xref: /illumos-gate/usr/src/uts/common/io/ib/ibtl/ibtl_hca.c (revision f7327bbd)
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
5a1e3386eShiremath  * Common Development and Distribution License (the "License").
6a1e3386eShiremath  * 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 /*
22*f7327bbdSBill Taylor  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
237c478bd9Sstevel@tonic-gate  */
247c478bd9Sstevel@tonic-gate 
257c478bd9Sstevel@tonic-gate /*
267c478bd9Sstevel@tonic-gate  * ibtl_hca.c
277c478bd9Sstevel@tonic-gate  *
287c478bd9Sstevel@tonic-gate  * This file contains Transport API functions related to
297c478bd9Sstevel@tonic-gate  * Host Channel Adapter (HCA) Verbs.
307c478bd9Sstevel@tonic-gate  */
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #include <sys/ib/ibtl/impl/ibtl.h>
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate static char ibtf_hca[] = "ibtl_hca";
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate /* Prototype declarations. */
377c478bd9Sstevel@tonic-gate static ibt_status_t ibtl_query_hca_ports(ibtl_hca_devinfo_t *hca_devp,
387c478bd9Sstevel@tonic-gate     uint8_t port, ibt_hca_portinfo_t **port_info_p, uint_t *ports_p,
397c478bd9Sstevel@tonic-gate     uint_t *size_p, int use_cache);
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate /*
427c478bd9Sstevel@tonic-gate  * Function:
437c478bd9Sstevel@tonic-gate  *      ibt_open_hca
447c478bd9Sstevel@tonic-gate  * Input:
457c478bd9Sstevel@tonic-gate  *      ibt_hdl    - IBT Client Handle
467c478bd9Sstevel@tonic-gate  *      hca_guid   - HCA's node GUID.
477c478bd9Sstevel@tonic-gate  * Output:
487c478bd9Sstevel@tonic-gate  *      hca_hdl_p  - IBT HCA Handle.
497c478bd9Sstevel@tonic-gate  * Returns:
507c478bd9Sstevel@tonic-gate  *      IBT_SUCCESS
517c478bd9Sstevel@tonic-gate  *      IBT_HCA_IN_USE
527c478bd9Sstevel@tonic-gate  *      IBT_HCA_INVALID
537c478bd9Sstevel@tonic-gate  * Description:
547c478bd9Sstevel@tonic-gate  *      Open a HCA. HCA can only be opened/closed once. This routine allocates
557c478bd9Sstevel@tonic-gate  *      and returns a unique IBT Client HCA handle. Clients passes this
567c478bd9Sstevel@tonic-gate  *      handle on its subsequent references to this device. Once opened by a
577c478bd9Sstevel@tonic-gate  *      client, a specific HCA cannot be opened again until after it is closed.
587c478bd9Sstevel@tonic-gate  *      The IBT_HCA_IN_USE error is returned if client tries to open multiple
597c478bd9Sstevel@tonic-gate  *      times. In this case, previously allocated IBT HCA handle is returned to
607c478bd9Sstevel@tonic-gate  *      the client. Opening the HCA prepares the HCA for use by the client.
617c478bd9Sstevel@tonic-gate  */
627c478bd9Sstevel@tonic-gate ibt_status_t
ibt_open_hca(ibt_clnt_hdl_t ibt_hdl,ib_guid_t hca_guid,ibt_hca_hdl_t * hca_hdl_p)637c478bd9Sstevel@tonic-gate ibt_open_hca(ibt_clnt_hdl_t ibt_hdl, ib_guid_t hca_guid,
647c478bd9Sstevel@tonic-gate     ibt_hca_hdl_t *hca_hdl_p)
657c478bd9Sstevel@tonic-gate {
667c478bd9Sstevel@tonic-gate 	ibtl_hca_t  		*hca_infop;
677c478bd9Sstevel@tonic-gate 	ibtl_hca_devinfo_t	*hca_devp;		/* HCA Dev Info */
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L3(ibtf_hca, "ibt_open_hca(%p, %llX)", ibt_hdl, hca_guid);
707c478bd9Sstevel@tonic-gate 
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate 	/*
737c478bd9Sstevel@tonic-gate 	 * Get HCA Device Info Structure, referenced by HCA GUID.
747c478bd9Sstevel@tonic-gate 	 */
757c478bd9Sstevel@tonic-gate 	mutex_enter(&ibtl_clnt_list_mutex);
767c478bd9Sstevel@tonic-gate 	hca_devp = ibtl_get_hcadevinfo(hca_guid);
777c478bd9Sstevel@tonic-gate 	if (hca_devp == NULL) {
787c478bd9Sstevel@tonic-gate 		/*
797c478bd9Sstevel@tonic-gate 		 * If we are here, then the requested HCA device is not present.
807c478bd9Sstevel@tonic-gate 		 * Return the status as Invalid HCA GUID.
817c478bd9Sstevel@tonic-gate 		 */
827c478bd9Sstevel@tonic-gate 		mutex_exit(&ibtl_clnt_list_mutex);
837c478bd9Sstevel@tonic-gate 
847c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L2(ibtf_hca, "ibt_open_hca: "
857c478bd9Sstevel@tonic-gate 		    "HCA Device Not Found: Invalid HCA GUID");
867c478bd9Sstevel@tonic-gate 
877c478bd9Sstevel@tonic-gate 		*hca_hdl_p = NULL;
887c478bd9Sstevel@tonic-gate 		return (IBT_HCA_INVALID);
897c478bd9Sstevel@tonic-gate 	}
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate 	/*
927c478bd9Sstevel@tonic-gate 	 * Check whether open is allowed for this dip
937c478bd9Sstevel@tonic-gate 	 */
947c478bd9Sstevel@tonic-gate 	if (ibt_hdl->clnt_dip) {
957c478bd9Sstevel@tonic-gate 		if (ddi_get_parent(ibt_hdl->clnt_dip) == hca_devp->hd_hca_dip) {
967c478bd9Sstevel@tonic-gate 			if (hca_guid != hca_devp->hd_hca_attr->hca_node_guid) {
977c478bd9Sstevel@tonic-gate 				mutex_exit(&ibtl_clnt_list_mutex);
987c478bd9Sstevel@tonic-gate 				return (IBT_FAILURE);
997c478bd9Sstevel@tonic-gate 			}
1007c478bd9Sstevel@tonic-gate 		}
1017c478bd9Sstevel@tonic-gate 	}
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate 	if (hca_devp->hd_state != IBTL_HCA_DEV_ATTACHED) {
1047c478bd9Sstevel@tonic-gate 		/*
1057c478bd9Sstevel@tonic-gate 		 * If we are here, then the requested HCA device has detached,
1067c478bd9Sstevel@tonic-gate 		 * or is in the process of detaching.
1077c478bd9Sstevel@tonic-gate 		 */
1087c478bd9Sstevel@tonic-gate 		mutex_exit(&ibtl_clnt_list_mutex);
1097c478bd9Sstevel@tonic-gate 
1107c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L2(ibtf_hca, "ibt_open_hca: "
1117c478bd9Sstevel@tonic-gate 		    "HCA is busy trying to detach");
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate 		*hca_hdl_p = NULL;
1147c478bd9Sstevel@tonic-gate 		return (IBT_HCA_BUSY_DETACHING);
1157c478bd9Sstevel@tonic-gate 	}
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate 	/*
1187c478bd9Sstevel@tonic-gate 	 * Yes, we found a HCA Device registered with IBTF, which matches with
1197c478bd9Sstevel@tonic-gate 	 * the requested HCA_GUID.
1207c478bd9Sstevel@tonic-gate 	 *
1217c478bd9Sstevel@tonic-gate 	 * Check out whether this client has already opened this HCA device,
1227c478bd9Sstevel@tonic-gate 	 * if yes return the status as IBT_HCA_IN_USE.
1237c478bd9Sstevel@tonic-gate 	 */
1247c478bd9Sstevel@tonic-gate 	hca_infop = hca_devp->hd_clnt_list;
1257c478bd9Sstevel@tonic-gate 
1267c478bd9Sstevel@tonic-gate 	while (hca_infop != NULL) {
1277c478bd9Sstevel@tonic-gate 		if (ibt_hdl == hca_infop->ha_clnt_devp) {
1287c478bd9Sstevel@tonic-gate 			IBTF_DPRINTF_L3(ibtf_hca,
1297c478bd9Sstevel@tonic-gate 			    "ibt_open_hca: Already Open");
1307c478bd9Sstevel@tonic-gate 
1317c478bd9Sstevel@tonic-gate 			if (hca_infop->ha_flags & IBTL_HA_CLOSING) {
1327c478bd9Sstevel@tonic-gate 				mutex_exit(&ibtl_clnt_list_mutex);
1337c478bd9Sstevel@tonic-gate 				*hca_hdl_p = NULL;
1347c478bd9Sstevel@tonic-gate 				return (IBT_HCA_BUSY_CLOSING);
1357c478bd9Sstevel@tonic-gate 			}
1367c478bd9Sstevel@tonic-gate 			mutex_exit(&ibtl_clnt_list_mutex);
1377c478bd9Sstevel@tonic-gate 
1387c478bd9Sstevel@tonic-gate 			/* Already Opened. Return back old HCA Handle. */
1397c478bd9Sstevel@tonic-gate 			*hca_hdl_p = hca_infop;
1407c478bd9Sstevel@tonic-gate 
1417c478bd9Sstevel@tonic-gate 			return (IBT_HCA_IN_USE);
1427c478bd9Sstevel@tonic-gate 		}
1437c478bd9Sstevel@tonic-gate 		hca_infop = hca_infop->ha_clnt_link;
1447c478bd9Sstevel@tonic-gate 	}
1457c478bd9Sstevel@tonic-gate 
1467c478bd9Sstevel@tonic-gate 	/* Create a new HCA Info entity. */
1477c478bd9Sstevel@tonic-gate 	hca_infop = kmem_zalloc(sizeof (ibtl_hca_t), KM_SLEEP);
1487c478bd9Sstevel@tonic-gate 
1497c478bd9Sstevel@tonic-gate 	/* Update the HCA Info entity */
1507c478bd9Sstevel@tonic-gate 	hca_infop->ha_hca_devp  = hca_devp;	/* HCA Device Info */
1517c478bd9Sstevel@tonic-gate 	hca_infop->ha_clnt_devp = ibt_hdl;	/* Client Info */
1527c478bd9Sstevel@tonic-gate 
1537c478bd9Sstevel@tonic-gate 	/* Update the HCA List, to keep track about the clients using it. */
1547c478bd9Sstevel@tonic-gate 	hca_infop->ha_clnt_link = hca_devp->hd_clnt_list;
1557c478bd9Sstevel@tonic-gate 	hca_devp->hd_clnt_list = hca_infop;
1567c478bd9Sstevel@tonic-gate 
1577c478bd9Sstevel@tonic-gate 
1587c478bd9Sstevel@tonic-gate 	/* Update the client's list to depict that it uses this HCA device. */
1597c478bd9Sstevel@tonic-gate 	hca_infop->ha_hca_link = ibt_hdl->clnt_hca_list;
1607c478bd9Sstevel@tonic-gate 	ibt_hdl->clnt_hca_list = hca_infop;
1617c478bd9Sstevel@tonic-gate 
1627c478bd9Sstevel@tonic-gate 	mutex_exit(&ibtl_clnt_list_mutex);
1637c478bd9Sstevel@tonic-gate 
1647c478bd9Sstevel@tonic-gate 	/*
1657c478bd9Sstevel@tonic-gate 	 * Return back the address of ibtl_hca_t structure as an opaque
1667c478bd9Sstevel@tonic-gate 	 * IBT HCA handle for the clients, to be used in future calls.
1677c478bd9Sstevel@tonic-gate 	 */
1687c478bd9Sstevel@tonic-gate 	*hca_hdl_p = hca_infop;
1697c478bd9Sstevel@tonic-gate 
1707c478bd9Sstevel@tonic-gate 	return (IBT_SUCCESS);
1717c478bd9Sstevel@tonic-gate }
1727c478bd9Sstevel@tonic-gate 
173*f7327bbdSBill Taylor static char *ibtl_close_error_fmt = "IBT CLOSE HCA failed: %d '%s' "
174*f7327bbdSBill Taylor 	"resources not yet freed by client '%s'\n";
175*f7327bbdSBill Taylor 
176*f7327bbdSBill Taylor #define	IBTL_CLOSE_RESOURCE_CHECK(counter, resource_type) \
177*f7327bbdSBill Taylor 	if ((cntr = atomic_add_32_nv(&(counter), 0)) != 0) {		\
178*f7327bbdSBill Taylor 		cmn_err(CE_CONT, ibtl_close_error_fmt,			\
179*f7327bbdSBill Taylor 		    cntr, resource_type,				\
180*f7327bbdSBill Taylor 		    hca_hdl->ha_clnt_devp->clnt_modinfop->mi_clnt_name); \
181*f7327bbdSBill Taylor 	}								\
182*f7327bbdSBill Taylor 	error |= cntr
1837c478bd9Sstevel@tonic-gate 
1847c478bd9Sstevel@tonic-gate /*
1857c478bd9Sstevel@tonic-gate  * Function:
1867c478bd9Sstevel@tonic-gate  *      ibt_close_hca
1877c478bd9Sstevel@tonic-gate  * Input:
1887c478bd9Sstevel@tonic-gate  *      hca_hdl  - The HCA handle as returned during its open.
1897c478bd9Sstevel@tonic-gate  * Output:
1907c478bd9Sstevel@tonic-gate  *      none
1917c478bd9Sstevel@tonic-gate  * Returns:
1927c478bd9Sstevel@tonic-gate  *      IBT_SUCCESS
1937c478bd9Sstevel@tonic-gate  *      IBT_HCA_HDL_INVALID
1947c478bd9Sstevel@tonic-gate  *      IBT_HCA_RESOURCES_NOT_FREED
1957c478bd9Sstevel@tonic-gate  * Description:
1967c478bd9Sstevel@tonic-gate  *      Close a HCA.
1977c478bd9Sstevel@tonic-gate  */
1987c478bd9Sstevel@tonic-gate ibt_status_t
ibt_close_hca(ibt_hca_hdl_t hca_hdl)1997c478bd9Sstevel@tonic-gate ibt_close_hca(ibt_hca_hdl_t hca_hdl)
2007c478bd9Sstevel@tonic-gate {
2017c478bd9Sstevel@tonic-gate 	ibtl_hca_devinfo_t	*hca_devp, *tmp_devp;
2027c478bd9Sstevel@tonic-gate 	ibtl_hca_t		**hcapp;
2037c478bd9Sstevel@tonic-gate 	ibtl_clnt_t		*clntp = hca_hdl->ha_clnt_devp;
204*f7327bbdSBill Taylor 	uint32_t		cntr, error;
2057c478bd9Sstevel@tonic-gate 
2067c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L3(ibtf_hca, "ibt_close_hca(%p)", hca_hdl);
2077c478bd9Sstevel@tonic-gate 
2087c478bd9Sstevel@tonic-gate 	/*
2097c478bd9Sstevel@tonic-gate 	 * Verify the Input HCA Handle, if fake return error as
2107c478bd9Sstevel@tonic-gate 	 * invalid HCA Handle.
2117c478bd9Sstevel@tonic-gate 	 */
2127c478bd9Sstevel@tonic-gate 	mutex_enter(&ibtl_clnt_list_mutex);
2137c478bd9Sstevel@tonic-gate 	hca_devp = hca_hdl->ha_hca_devp;
2147c478bd9Sstevel@tonic-gate 	tmp_devp = ibtl_hca_list;
2157c478bd9Sstevel@tonic-gate 
2167c478bd9Sstevel@tonic-gate 	for (; tmp_devp != NULL; tmp_devp = tmp_devp->hd_hca_dev_link)
2177c478bd9Sstevel@tonic-gate 		if (tmp_devp == hca_devp)
2187c478bd9Sstevel@tonic-gate 			break;
2197c478bd9Sstevel@tonic-gate 
2207c478bd9Sstevel@tonic-gate 	if (tmp_devp == NULL) {
2217c478bd9Sstevel@tonic-gate 		mutex_exit(&ibtl_clnt_list_mutex);
2227c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L2(ibtf_hca, "ibt_close_hca: "
2237c478bd9Sstevel@tonic-gate 		    "Unable to find this on global HCA list");
2247c478bd9Sstevel@tonic-gate 		return (IBT_HCA_HDL_INVALID);
2257c478bd9Sstevel@tonic-gate 	}
2267c478bd9Sstevel@tonic-gate 
2277c478bd9Sstevel@tonic-gate 	/* Make sure resources have been freed. */
228*f7327bbdSBill Taylor 	error = 0;
229*f7327bbdSBill Taylor 	IBTL_CLOSE_RESOURCE_CHECK(hca_hdl->ha_qp_cnt, "QP/Channel");
230*f7327bbdSBill Taylor 	IBTL_CLOSE_RESOURCE_CHECK(hca_hdl->ha_eec_cnt, "EEC");
231*f7327bbdSBill Taylor 	IBTL_CLOSE_RESOURCE_CHECK(hca_hdl->ha_cq_cnt, "CQ");
232*f7327bbdSBill Taylor 	IBTL_CLOSE_RESOURCE_CHECK(hca_hdl->ha_pd_cnt, "Protection Domain");
233*f7327bbdSBill Taylor 	IBTL_CLOSE_RESOURCE_CHECK(hca_hdl->ha_ah_cnt, "AH");
234*f7327bbdSBill Taylor 	IBTL_CLOSE_RESOURCE_CHECK(hca_hdl->ha_mr_cnt, "Memory Region");
235*f7327bbdSBill Taylor 	IBTL_CLOSE_RESOURCE_CHECK(hca_hdl->ha_mw_cnt, "Memory Window");
236*f7327bbdSBill Taylor 	IBTL_CLOSE_RESOURCE_CHECK(hca_hdl->ha_qpn_cnt, "QPN");
237*f7327bbdSBill Taylor 	IBTL_CLOSE_RESOURCE_CHECK(hca_hdl->ha_srq_cnt, "SRQ");
238*f7327bbdSBill Taylor 	IBTL_CLOSE_RESOURCE_CHECK(hca_hdl->ha_fmr_pool_cnt, "FMR Pool");
239*f7327bbdSBill Taylor 	if (error) {
2407c478bd9Sstevel@tonic-gate 		mutex_exit(&ibtl_clnt_list_mutex);
2417c478bd9Sstevel@tonic-gate 		return (IBT_HCA_RESOURCES_NOT_FREED);
2427c478bd9Sstevel@tonic-gate 	}
2437c478bd9Sstevel@tonic-gate 
2447c478bd9Sstevel@tonic-gate 	/* we are now committed to closing the HCA */
2457c478bd9Sstevel@tonic-gate 	hca_hdl->ha_flags |= IBTL_HA_CLOSING;
2467c478bd9Sstevel@tonic-gate 	while (hca_hdl->ha_qpn_cnt > 0)
2477c478bd9Sstevel@tonic-gate 		cv_wait(&ibtl_close_hca_cv, &ibtl_clnt_list_mutex);
2487c478bd9Sstevel@tonic-gate 
2497c478bd9Sstevel@tonic-gate 	/*
2507c478bd9Sstevel@tonic-gate 	 * Remove this HCA Device entry form Client's current list of HCA
2517c478bd9Sstevel@tonic-gate 	 * Device Instances being used by it.
2527c478bd9Sstevel@tonic-gate 	 */
2537c478bd9Sstevel@tonic-gate 	hcapp = &clntp->clnt_hca_list;
2547c478bd9Sstevel@tonic-gate 
2557c478bd9Sstevel@tonic-gate 	for (; *hcapp != NULL; hcapp = &(*hcapp)->ha_hca_link)
2567c478bd9Sstevel@tonic-gate 		if (*hcapp == hca_hdl)
2577c478bd9Sstevel@tonic-gate 			break;
2587c478bd9Sstevel@tonic-gate 
2597c478bd9Sstevel@tonic-gate 	if (*hcapp == NULL) {
2607c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L2(ibtf_hca, "ibt_close_hca: "
2617c478bd9Sstevel@tonic-gate 		    "Unable to find this HCA on client list");
2627c478bd9Sstevel@tonic-gate 		mutex_exit(&ibtl_clnt_list_mutex);
2637c478bd9Sstevel@tonic-gate 		return (IBT_HCA_HDL_INVALID);
2647c478bd9Sstevel@tonic-gate 	}
2657c478bd9Sstevel@tonic-gate 
2667c478bd9Sstevel@tonic-gate 	/* hcapp now points to a link that points to us */
2677c478bd9Sstevel@tonic-gate 	*hcapp = hca_hdl->ha_hca_link;		/* remove us */
2687c478bd9Sstevel@tonic-gate 
2697c478bd9Sstevel@tonic-gate 	/*
2707c478bd9Sstevel@tonic-gate 	 * Remove this Client's entry from this HCA Device's Clients list.
2717c478bd9Sstevel@tonic-gate 	 */
2727c478bd9Sstevel@tonic-gate 	hcapp = &hca_devp->hd_clnt_list;
2737c478bd9Sstevel@tonic-gate 
2747c478bd9Sstevel@tonic-gate 	for (; *hcapp != NULL; hcapp = &(*hcapp)->ha_clnt_link)
2757c478bd9Sstevel@tonic-gate 		if (*hcapp == hca_hdl)
2767c478bd9Sstevel@tonic-gate 			break;
2777c478bd9Sstevel@tonic-gate 
2787c478bd9Sstevel@tonic-gate 	if (*hcapp == NULL) {
2797c478bd9Sstevel@tonic-gate 		mutex_exit(&ibtl_clnt_list_mutex);
2807c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L2(ibtf_hca, "ibt_close_hca: "
2817c478bd9Sstevel@tonic-gate 		    "Unable to find this HCA on the client's HCA list");
2827c478bd9Sstevel@tonic-gate 		return (IBT_HCA_HDL_INVALID);
2837c478bd9Sstevel@tonic-gate 	}
2847c478bd9Sstevel@tonic-gate 
2857c478bd9Sstevel@tonic-gate 	/* hcapp now points to a link that points to us */
2867c478bd9Sstevel@tonic-gate 	*hcapp = hca_hdl->ha_clnt_link;		/* remove us */
2877c478bd9Sstevel@tonic-gate 	mutex_exit(&ibtl_clnt_list_mutex);
2887c478bd9Sstevel@tonic-gate 
2897c478bd9Sstevel@tonic-gate 	/* Free memory for this HCA Handle */
2907c478bd9Sstevel@tonic-gate 	ibtl_free_hca_async_check(hca_hdl);
2917c478bd9Sstevel@tonic-gate 
2927c478bd9Sstevel@tonic-gate 	return (IBT_SUCCESS);
2937c478bd9Sstevel@tonic-gate }
2947c478bd9Sstevel@tonic-gate 
2957c478bd9Sstevel@tonic-gate void
ibtl_close_hca_check(ibt_hca_hdl_t hca_hdl)2967c478bd9Sstevel@tonic-gate ibtl_close_hca_check(ibt_hca_hdl_t hca_hdl)
2977c478bd9Sstevel@tonic-gate {
2987c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L3(ibtf_hca, "ibtl_close_hca_check(%p)", hca_hdl);
2997c478bd9Sstevel@tonic-gate 
3007c478bd9Sstevel@tonic-gate 	mutex_enter(&ibtl_clnt_list_mutex);
3017c478bd9Sstevel@tonic-gate 	if ((--hca_hdl->ha_qpn_cnt == 0) &&
3027c478bd9Sstevel@tonic-gate 	    (hca_hdl->ha_flags & IBTL_HA_CLOSING)) {
3037c478bd9Sstevel@tonic-gate 		cv_signal(&ibtl_close_hca_cv);
3047c478bd9Sstevel@tonic-gate 	}
3057c478bd9Sstevel@tonic-gate 	mutex_exit(&ibtl_clnt_list_mutex);
3067c478bd9Sstevel@tonic-gate }
3077c478bd9Sstevel@tonic-gate 
3087c478bd9Sstevel@tonic-gate /*
3097c478bd9Sstevel@tonic-gate  * Function:
3107c478bd9Sstevel@tonic-gate  *      ibt_get_hca_list
3117c478bd9Sstevel@tonic-gate  * Input:
3127c478bd9Sstevel@tonic-gate  *      hca_list_p -  Address of pointer updated here.
3137c478bd9Sstevel@tonic-gate  * Output:
3147c478bd9Sstevel@tonic-gate  *      hca_list_p -  Points to an array of ib_guid_t's allocated here.
3157c478bd9Sstevel@tonic-gate  * Returns:
3167c478bd9Sstevel@tonic-gate  *      The actual number of valid ib_guid_t's returned.
3177c478bd9Sstevel@tonic-gate  * Description:
3187c478bd9Sstevel@tonic-gate  *	If hca_list_p is not NULL then the memory for the array of GUIDs is
3197c478bd9Sstevel@tonic-gate  *	allocated here and should be freed by the caller using
3207c478bd9Sstevel@tonic-gate  *	ibt_free_hca_list(). If hca_list_p is NULL then no memory is allocated
3217c478bd9Sstevel@tonic-gate  *	by ibt_get_hca_list and only the number of HCAs in a system is returned.
3227c478bd9Sstevel@tonic-gate  */
3237c478bd9Sstevel@tonic-gate uint_t
ibt_get_hca_list(ib_guid_t ** hca_list_p)3247c478bd9Sstevel@tonic-gate ibt_get_hca_list(ib_guid_t **hca_list_p)
3257c478bd9Sstevel@tonic-gate {
3267c478bd9Sstevel@tonic-gate 	uint_t			hca_count = 0;
3277c478bd9Sstevel@tonic-gate 	ibtl_hca_devinfo_t	*hca_devp;
3287c478bd9Sstevel@tonic-gate 	ib_guid_t		*hca_listp;
3297c478bd9Sstevel@tonic-gate 
3307c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L3(ibtf_hca, "ibt_get_hca_list(%p)", hca_list_p);
3317c478bd9Sstevel@tonic-gate 
3327c478bd9Sstevel@tonic-gate 	mutex_enter(&ibtl_clnt_list_mutex);
3337c478bd9Sstevel@tonic-gate 
3347c478bd9Sstevel@tonic-gate 	hca_devp = ibtl_hca_list;
3357c478bd9Sstevel@tonic-gate 	while (hca_devp != NULL) {
3367c478bd9Sstevel@tonic-gate 		hca_count++;
3377c478bd9Sstevel@tonic-gate 		hca_devp = hca_devp->hd_hca_dev_link;
3387c478bd9Sstevel@tonic-gate 	}
3397c478bd9Sstevel@tonic-gate 
3407c478bd9Sstevel@tonic-gate 	if (hca_count == 0)
3417c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L2(ibtf_hca, "ibt_get_hca_list: "
3427c478bd9Sstevel@tonic-gate 		    "HCA device not found");
3437c478bd9Sstevel@tonic-gate 
3447c478bd9Sstevel@tonic-gate 	if ((hca_count == 0) || (hca_list_p == NULL)) {
3457c478bd9Sstevel@tonic-gate 		mutex_exit(&ibtl_clnt_list_mutex);
3467c478bd9Sstevel@tonic-gate 		return (hca_count);
3477c478bd9Sstevel@tonic-gate 	}
3487c478bd9Sstevel@tonic-gate 
3497c478bd9Sstevel@tonic-gate 	hca_listp = kmem_alloc(hca_count * sizeof (ib_guid_t), KM_SLEEP);
3507c478bd9Sstevel@tonic-gate 	*hca_list_p = hca_listp;
3517c478bd9Sstevel@tonic-gate 
3527c478bd9Sstevel@tonic-gate 	hca_devp = ibtl_hca_list;
3537c478bd9Sstevel@tonic-gate 	while (hca_devp != NULL) {
3547c478bd9Sstevel@tonic-gate 		/* Traverse Global HCA List & retrieve HCA Node GUIDs. */
3557c478bd9Sstevel@tonic-gate 		*hca_listp++ = hca_devp->hd_hca_attr->hca_node_guid;
3567c478bd9Sstevel@tonic-gate 		hca_devp = hca_devp->hd_hca_dev_link;
3577c478bd9Sstevel@tonic-gate 	}
3587c478bd9Sstevel@tonic-gate 	mutex_exit(&ibtl_clnt_list_mutex);
3597c478bd9Sstevel@tonic-gate 
3607c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L3(ibtf_hca, "ibt_get_hca_list: "
3617c478bd9Sstevel@tonic-gate 	    "Returned <%d> entries @0x%p", hca_count, *hca_list_p);
3627c478bd9Sstevel@tonic-gate 
3637c478bd9Sstevel@tonic-gate 	return (hca_count);
3647c478bd9Sstevel@tonic-gate }
3657c478bd9Sstevel@tonic-gate 
3667c478bd9Sstevel@tonic-gate /*
3677c478bd9Sstevel@tonic-gate  * Function:
3687c478bd9Sstevel@tonic-gate  *      ibt_free_hca_list
3697c478bd9Sstevel@tonic-gate  * Input:
3707c478bd9Sstevel@tonic-gate  *      hca_list  - The address of an ib_guid_t pointer.
3717c478bd9Sstevel@tonic-gate  *      entries   - The number of ib_guid_t entries to be freed.
3727c478bd9Sstevel@tonic-gate  * Output:
3737c478bd9Sstevel@tonic-gate  *      none.
3747c478bd9Sstevel@tonic-gate  * Returns:
3757c478bd9Sstevel@tonic-gate  *      none.
3767c478bd9Sstevel@tonic-gate  * Description:
3777c478bd9Sstevel@tonic-gate  *      The memory allocated in ibt_get_hca_list() is freed in this function.
3787c478bd9Sstevel@tonic-gate  */
3797c478bd9Sstevel@tonic-gate void
ibt_free_hca_list(ib_guid_t * hca_list,uint_t entries)3807c478bd9Sstevel@tonic-gate ibt_free_hca_list(ib_guid_t *hca_list, uint_t entries)
3817c478bd9Sstevel@tonic-gate {
3827c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L3(ibtf_hca, "ibt_free_hca_list: "
3837c478bd9Sstevel@tonic-gate 	    "Free <%d> entries from 0x%p", entries, hca_list);
3847c478bd9Sstevel@tonic-gate 
3857c478bd9Sstevel@tonic-gate 	if ((hca_list != NULL) && (entries > 0))
3867c478bd9Sstevel@tonic-gate 		kmem_free(hca_list, entries * sizeof (ib_guid_t));
3877c478bd9Sstevel@tonic-gate }
3887c478bd9Sstevel@tonic-gate 
3897c478bd9Sstevel@tonic-gate /*
3907c478bd9Sstevel@tonic-gate  * ibtl_portinfo_locked() is called when the portinfo cache is being
3917c478bd9Sstevel@tonic-gate  * updated.  If this port's info update is in progress, we return 0
3927c478bd9Sstevel@tonic-gate  * immediately and have the c
3937c478bd9Sstevel@tonic-gate  * unless it's already in progress (distinguished by return value).
3947c478bd9Sstevel@tonic-gate  * When done updating the portinfo, they call ibtl_portinfo_unlock().
3957c478bd9Sstevel@tonic-gate  */
3967c478bd9Sstevel@tonic-gate 
3977c478bd9Sstevel@tonic-gate static int
ibtl_portinfo_locked(ibtl_hca_devinfo_t * hca_devp,uint8_t port)3987c478bd9Sstevel@tonic-gate ibtl_portinfo_locked(ibtl_hca_devinfo_t *hca_devp, uint8_t port)
3997c478bd9Sstevel@tonic-gate {
4007c478bd9Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&ibtl_clnt_list_mutex));
4017c478bd9Sstevel@tonic-gate 
4027c478bd9Sstevel@tonic-gate 	for (;;) {
4037c478bd9Sstevel@tonic-gate 		if (hca_devp->hd_portinfo_locked_port == 0) {
4047c478bd9Sstevel@tonic-gate 			hca_devp->hd_portinfo_locked_port = port;
4057c478bd9Sstevel@tonic-gate 			return (1); /* not busy, so OK to initiate update */
4067c478bd9Sstevel@tonic-gate 		} else if (hca_devp->hd_portinfo_locked_port == port) {
4077c478bd9Sstevel@tonic-gate 			IBTF_DPRINTF_L3(ibtf_hca, "ibtl_portinfo_locked: "
4087c478bd9Sstevel@tonic-gate 			    "HCA %p port %d is already locked",
4097c478bd9Sstevel@tonic-gate 			    hca_devp, port);
4107c478bd9Sstevel@tonic-gate 			hca_devp->hd_portinfo_waiters = 1;
4117c478bd9Sstevel@tonic-gate 			cv_wait(&hca_devp->hd_portinfo_cv,
4127c478bd9Sstevel@tonic-gate 			    &ibtl_clnt_list_mutex);
4137c478bd9Sstevel@tonic-gate 			return (0); /* it's now done, so no need to initiate */
4147c478bd9Sstevel@tonic-gate 		} else {
4157c478bd9Sstevel@tonic-gate 			/* need to wait for other port before we try again */
4167c478bd9Sstevel@tonic-gate 			hca_devp->hd_portinfo_waiters = 1;
4177c478bd9Sstevel@tonic-gate 			cv_wait(&hca_devp->hd_portinfo_cv,
4187c478bd9Sstevel@tonic-gate 			    &ibtl_clnt_list_mutex);
4197c478bd9Sstevel@tonic-gate 		}
4207c478bd9Sstevel@tonic-gate 	}
4217c478bd9Sstevel@tonic-gate }
4227c478bd9Sstevel@tonic-gate 
4237c478bd9Sstevel@tonic-gate static void
ibtl_portinfo_unlock(ibtl_hca_devinfo_t * hca_devp,uint8_t port)4247c478bd9Sstevel@tonic-gate ibtl_portinfo_unlock(ibtl_hca_devinfo_t *hca_devp, uint8_t port)
4257c478bd9Sstevel@tonic-gate {
4267c478bd9Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&ibtl_clnt_list_mutex));
4277c478bd9Sstevel@tonic-gate 	ASSERT(hca_devp->hd_portinfo_locked_port == port);
4287c478bd9Sstevel@tonic-gate 	hca_devp->hd_portinfo_locked_port = 0;
4297c478bd9Sstevel@tonic-gate 	if (hca_devp->hd_portinfo_waiters) {
4307c478bd9Sstevel@tonic-gate 		hca_devp->hd_portinfo_waiters = 0;
4317c478bd9Sstevel@tonic-gate 		cv_broadcast(&hca_devp->hd_portinfo_cv);
4327c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L3(ibtf_hca, "ibtl_portinfo_unlock: "
4337c478bd9Sstevel@tonic-gate 		    "waking up waiters for port %d info on HCA %p",
4347c478bd9Sstevel@tonic-gate 		    port, hca_devp);
4357c478bd9Sstevel@tonic-gate 	}
4367c478bd9Sstevel@tonic-gate }
4377c478bd9Sstevel@tonic-gate 
4387c478bd9Sstevel@tonic-gate /*
4397c478bd9Sstevel@tonic-gate  * Function:
4407c478bd9Sstevel@tonic-gate  *      ibt_get_port_state
4417c478bd9Sstevel@tonic-gate  * Input:
4427c478bd9Sstevel@tonic-gate  *      hca_devp    - The HCA Dev Info pointer.
4437c478bd9Sstevel@tonic-gate  *	port        - Port number to query.
4447c478bd9Sstevel@tonic-gate  * Output:
4457c478bd9Sstevel@tonic-gate  *      sgid_p	    - Returned sgid[0], NULL implies no return value.
4467c478bd9Sstevel@tonic-gate  *      base_lid_p  - Returned base_lid, NULL implies no return value.
4477c478bd9Sstevel@tonic-gate  * Returns:
4487c478bd9Sstevel@tonic-gate  *      IBT_SUCCESS
4497c478bd9Sstevel@tonic-gate  *	IBT_HCA_PORT_INVALID
4507c478bd9Sstevel@tonic-gate  * Description:
4517c478bd9Sstevel@tonic-gate  *      Returns HCA port attributes for one of the HCA ports.
4527c478bd9Sstevel@tonic-gate  */
4537c478bd9Sstevel@tonic-gate static ibt_status_t
ibtl_get_port_state(ibtl_hca_devinfo_t * hca_devp,uint8_t port,ib_gid_t * sgid_p,ib_lid_t * base_lid_p)4547c478bd9Sstevel@tonic-gate ibtl_get_port_state(ibtl_hca_devinfo_t *hca_devp, uint8_t port,
4557c478bd9Sstevel@tonic-gate     ib_gid_t *sgid_p, ib_lid_t *base_lid_p)
4567c478bd9Sstevel@tonic-gate {
4577c478bd9Sstevel@tonic-gate 	ibt_hca_portinfo_t *portinfop;
4587c478bd9Sstevel@tonic-gate 
4597c478bd9Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&ibtl_clnt_list_mutex));
4607c478bd9Sstevel@tonic-gate 
4617c478bd9Sstevel@tonic-gate 	if ((port < 1) || (port > hca_devp->hd_hca_attr->hca_nports)) {
4627c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L2(ibtf_hca, "ibtl_get_port_state: "
4637c478bd9Sstevel@tonic-gate 		    "invalid port %d, nports = %d", port,
4647c478bd9Sstevel@tonic-gate 		    hca_devp->hd_hca_attr->hca_nports);
4657c478bd9Sstevel@tonic-gate 		return (IBT_HCA_PORT_INVALID);
4667c478bd9Sstevel@tonic-gate 	}
4677c478bd9Sstevel@tonic-gate 	portinfop = hca_devp->hd_portinfop + port - 1;
468a1e3386eShiremath 	if (portinfop->p_linkstate != IBT_PORT_ACTIVE)
469a1e3386eShiremath 		ibtl_reinit_hca_portinfo(hca_devp, port);
4707c478bd9Sstevel@tonic-gate 
4717c478bd9Sstevel@tonic-gate 	if (sgid_p)
4727c478bd9Sstevel@tonic-gate 		*sgid_p = portinfop->p_sgid_tbl[0];
4737c478bd9Sstevel@tonic-gate 	if (base_lid_p)
4747c478bd9Sstevel@tonic-gate 		*base_lid_p = portinfop->p_base_lid;
4757c478bd9Sstevel@tonic-gate 	if (portinfop->p_linkstate != IBT_PORT_ACTIVE) {
4767c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L2(ibtf_hca, "ibtl_get_port_state: "
4777c478bd9Sstevel@tonic-gate 		    "port %d, port_state %d, base_lid %d",
4787c478bd9Sstevel@tonic-gate 		    port, portinfop->p_linkstate, portinfop->p_base_lid);
4797c478bd9Sstevel@tonic-gate 		return (IBT_HCA_PORT_NOT_ACTIVE);
4807c478bd9Sstevel@tonic-gate 	}
4817c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L3(ibtf_hca, "ibtl_get_port_state: "
4827c478bd9Sstevel@tonic-gate 	    "port %d, port_state %d, base_lid %d",
4837c478bd9Sstevel@tonic-gate 	    port, portinfop->p_linkstate, portinfop->p_base_lid);
4847c478bd9Sstevel@tonic-gate 	return (IBT_SUCCESS);
4857c478bd9Sstevel@tonic-gate }
4867c478bd9Sstevel@tonic-gate 
4877c478bd9Sstevel@tonic-gate /*
4887c478bd9Sstevel@tonic-gate  * Function:
4897c478bd9Sstevel@tonic-gate  *      ibt_get_port_state
4907c478bd9Sstevel@tonic-gate  * Input:
4917c478bd9Sstevel@tonic-gate  *      hca_hdl	    - The HCA handle.
4927c478bd9Sstevel@tonic-gate  *	port        - Port number to query.
4937c478bd9Sstevel@tonic-gate  * Output:
4947c478bd9Sstevel@tonic-gate  *      sgid_p	    - Returned sgid[0], NULL implies no return value.
4957c478bd9Sstevel@tonic-gate  *      base_lid_p  - Returned base_lid, NULL implies no return value.
4967c478bd9Sstevel@tonic-gate  * Returns:
4977c478bd9Sstevel@tonic-gate  *      IBT_SUCCESS
4987c478bd9Sstevel@tonic-gate  *	IBT_HCA_PORT_INVALID
4997c478bd9Sstevel@tonic-gate  * Description:
5007c478bd9Sstevel@tonic-gate  *      Returns HCA port attributes for one of the HCA ports.
5017c478bd9Sstevel@tonic-gate  */
5027c478bd9Sstevel@tonic-gate ibt_status_t
ibt_get_port_state(ibt_hca_hdl_t hca_hdl,uint8_t port,ib_gid_t * sgid_p,ib_lid_t * base_lid_p)5037c478bd9Sstevel@tonic-gate ibt_get_port_state(ibt_hca_hdl_t hca_hdl, uint8_t port,
5047c478bd9Sstevel@tonic-gate     ib_gid_t *sgid_p, ib_lid_t *base_lid_p)
5057c478bd9Sstevel@tonic-gate {
5067c478bd9Sstevel@tonic-gate 	ibt_status_t		retval;
5077c478bd9Sstevel@tonic-gate 
5087c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L3(ibtf_hca, "ibt_get_port_state(%p, %d, %p, %p)",
5097c478bd9Sstevel@tonic-gate 	    hca_hdl, port, sgid_p, base_lid_p);
5107c478bd9Sstevel@tonic-gate 	mutex_enter(&ibtl_clnt_list_mutex);
5117c478bd9Sstevel@tonic-gate 	retval = ibtl_get_port_state(hca_hdl->ha_hca_devp, port, sgid_p,
5127c478bd9Sstevel@tonic-gate 	    base_lid_p);
5137c478bd9Sstevel@tonic-gate 	mutex_exit(&ibtl_clnt_list_mutex);
5147c478bd9Sstevel@tonic-gate 	return (retval);
5157c478bd9Sstevel@tonic-gate }
5167c478bd9Sstevel@tonic-gate 
5177c478bd9Sstevel@tonic-gate 
5187c478bd9Sstevel@tonic-gate /*
5197c478bd9Sstevel@tonic-gate  * Function:
5207c478bd9Sstevel@tonic-gate  *      ibt_get_port_state_byguid
5217c478bd9Sstevel@tonic-gate  * Input:
5227c478bd9Sstevel@tonic-gate  *      hca_guid    - The HCA node GUID.
5237c478bd9Sstevel@tonic-gate  *	port        - Port number to query.
5247c478bd9Sstevel@tonic-gate  * Output:
5257c478bd9Sstevel@tonic-gate  *      sgid_p	    - Returned sgid[0], NULL implies no return value.
5267c478bd9Sstevel@tonic-gate  *      base_lid_p  - Returned base_lid, NULL implies no return value.
5277c478bd9Sstevel@tonic-gate  * Returns:
5287c478bd9Sstevel@tonic-gate  *      IBT_SUCCESS
5297c478bd9Sstevel@tonic-gate  *	IBT_HCA_PORT_INVALID
5307c478bd9Sstevel@tonic-gate  *      IBT_HCA_INVALID
5317c478bd9Sstevel@tonic-gate  * Description:
5327c478bd9Sstevel@tonic-gate  *      Returns HCA port attributes for one of the HCA ports.
5337c478bd9Sstevel@tonic-gate  */
5347c478bd9Sstevel@tonic-gate ibt_status_t
ibt_get_port_state_byguid(ib_guid_t hca_guid,uint8_t port,ib_gid_t * sgid_p,ib_lid_t * base_lid_p)5357c478bd9Sstevel@tonic-gate ibt_get_port_state_byguid(ib_guid_t hca_guid, uint8_t port,
5367c478bd9Sstevel@tonic-gate     ib_gid_t *sgid_p, ib_lid_t *base_lid_p)
5377c478bd9Sstevel@tonic-gate {
5387c478bd9Sstevel@tonic-gate 	ibtl_hca_devinfo_t	*hca_devp;		/* HCA Dev Info */
5397c478bd9Sstevel@tonic-gate 	ibt_status_t		retval;
5407c478bd9Sstevel@tonic-gate 
5417c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L3(ibtf_hca, "ibt_get_port_state_byguid(%llx, %d, %p, "
5427c478bd9Sstevel@tonic-gate 	    "%p)", (longlong_t)hca_guid, port, sgid_p, base_lid_p);
5437c478bd9Sstevel@tonic-gate 	mutex_enter(&ibtl_clnt_list_mutex);
5447c478bd9Sstevel@tonic-gate 	hca_devp = ibtl_get_hcadevinfo(hca_guid);
5457c478bd9Sstevel@tonic-gate 	if (hca_devp == NULL)
5467c478bd9Sstevel@tonic-gate 		retval = IBT_HCA_INVALID;
5477c478bd9Sstevel@tonic-gate 	else
5487c478bd9Sstevel@tonic-gate 		retval = ibtl_get_port_state(hca_devp, port, sgid_p,
5497c478bd9Sstevel@tonic-gate 		    base_lid_p);
5507c478bd9Sstevel@tonic-gate 	mutex_exit(&ibtl_clnt_list_mutex);
5517c478bd9Sstevel@tonic-gate 	return (retval);
5527c478bd9Sstevel@tonic-gate }
5537c478bd9Sstevel@tonic-gate 
5547c478bd9Sstevel@tonic-gate 
5557c478bd9Sstevel@tonic-gate /*
5567c478bd9Sstevel@tonic-gate  * Function:
5577c478bd9Sstevel@tonic-gate  *      ibt_query_hca_byguid
5587c478bd9Sstevel@tonic-gate  * Input:
5597c478bd9Sstevel@tonic-gate  *      hca_guid  - The HCA node GUID.
5607c478bd9Sstevel@tonic-gate  * Output:
5617c478bd9Sstevel@tonic-gate  *      hca_attrs - A pointer to a ibt_hca_attr_t allocated by the caller,
5627c478bd9Sstevel@tonic-gate  *                  into which the HCA Attributes are copied.
5637c478bd9Sstevel@tonic-gate  * Returns:
5647c478bd9Sstevel@tonic-gate  *      IBT_SUCCESS
5657c478bd9Sstevel@tonic-gate  *      IBT_INVALID_PARAM
5667c478bd9Sstevel@tonic-gate  *      IBT_HCA_INVALID
5677c478bd9Sstevel@tonic-gate  * Description:
5687c478bd9Sstevel@tonic-gate  *      Returns the static attributes of the specified HCA.
5697c478bd9Sstevel@tonic-gate  */
5707c478bd9Sstevel@tonic-gate ibt_status_t
ibt_query_hca_byguid(ib_guid_t hca_guid,ibt_hca_attr_t * hca_attrs)5717c478bd9Sstevel@tonic-gate ibt_query_hca_byguid(ib_guid_t hca_guid, ibt_hca_attr_t *hca_attrs)
5727c478bd9Sstevel@tonic-gate {
5737c478bd9Sstevel@tonic-gate 	ibtl_hca_devinfo_t	*hca_devp;	/* HCA Dev Info. */
5747c478bd9Sstevel@tonic-gate 
5757c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L3(ibtf_hca, "ibt_query_hca_byguid(%llX)", hca_guid);
5767c478bd9Sstevel@tonic-gate 
5777c478bd9Sstevel@tonic-gate 	mutex_enter(&ibtl_clnt_list_mutex);
5787c478bd9Sstevel@tonic-gate 	/* Get HCA Dev Info Structure, referenced by HCA GUID. */
5797c478bd9Sstevel@tonic-gate 	hca_devp = ibtl_get_hcadevinfo(hca_guid);
5807c478bd9Sstevel@tonic-gate 	if (hca_devp == NULL) {
5817c478bd9Sstevel@tonic-gate 		/*
5827c478bd9Sstevel@tonic-gate 		 * If we are here, then the requested HCA device is not present.
5837c478bd9Sstevel@tonic-gate 		 */
5847c478bd9Sstevel@tonic-gate 		mutex_exit(&ibtl_clnt_list_mutex);
5857c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L2(ibtf_hca, "ibt_query_hca_byguid: "
5867c478bd9Sstevel@tonic-gate 		    "Device Not Found");
5877c478bd9Sstevel@tonic-gate 		return (IBT_HCA_INVALID);
5887c478bd9Sstevel@tonic-gate 	}
5897c478bd9Sstevel@tonic-gate 
5907c478bd9Sstevel@tonic-gate 	/* Return back the static HCA attributes */
5917c478bd9Sstevel@tonic-gate 	bcopy(hca_devp->hd_hca_attr, hca_attrs, sizeof (ibt_hca_attr_t));
5927c478bd9Sstevel@tonic-gate 
5937c478bd9Sstevel@tonic-gate 	mutex_exit(&ibtl_clnt_list_mutex);
5947c478bd9Sstevel@tonic-gate 
5957c478bd9Sstevel@tonic-gate 	return (IBT_SUCCESS);
5967c478bd9Sstevel@tonic-gate }
5977c478bd9Sstevel@tonic-gate 
5987c478bd9Sstevel@tonic-gate 
5997c478bd9Sstevel@tonic-gate /*
6007c478bd9Sstevel@tonic-gate  * Function:
6017c478bd9Sstevel@tonic-gate  *      ibt_query_hca
6027c478bd9Sstevel@tonic-gate  * Input:
6037c478bd9Sstevel@tonic-gate  *      hca_hdl   - The HCA handle.
6047c478bd9Sstevel@tonic-gate  * Output:
6057c478bd9Sstevel@tonic-gate  *      hca_attrs - A pointer to a ibt_hca_attr_t allocated by the caller,
6067c478bd9Sstevel@tonic-gate  *                  into which the HCA Attributes are copied.
6077c478bd9Sstevel@tonic-gate  * Returns:
6087c478bd9Sstevel@tonic-gate  *      IBT_SUCCESS
6097c478bd9Sstevel@tonic-gate  *
6107c478bd9Sstevel@tonic-gate  * Description:
6117c478bd9Sstevel@tonic-gate  *      Returns the static attributes of the specified HCA.
6127c478bd9Sstevel@tonic-gate  */
6137c478bd9Sstevel@tonic-gate ibt_status_t
ibt_query_hca(ibt_hca_hdl_t hca_hdl,ibt_hca_attr_t * hca_attrs)6147c478bd9Sstevel@tonic-gate ibt_query_hca(ibt_hca_hdl_t hca_hdl, ibt_hca_attr_t *hca_attrs)
6157c478bd9Sstevel@tonic-gate {
6167c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L3(ibtf_hca, "ibt_query_hca(%p)", hca_hdl);
6177c478bd9Sstevel@tonic-gate 
6187c478bd9Sstevel@tonic-gate 	/* Return back the static HCA attributes */
6197c478bd9Sstevel@tonic-gate 	bcopy(hca_hdl->ha_hca_devp->hd_hca_attr, hca_attrs,
6207c478bd9Sstevel@tonic-gate 	    sizeof (ibt_hca_attr_t));
6217c478bd9Sstevel@tonic-gate 
6227c478bd9Sstevel@tonic-gate 	return (IBT_SUCCESS);
6237c478bd9Sstevel@tonic-gate }
6247c478bd9Sstevel@tonic-gate 
6257c478bd9Sstevel@tonic-gate #define	ROUNDUP(x, y)	((((x)+((y)-1))/(y))*(y))
6267c478bd9Sstevel@tonic-gate 
6277c478bd9Sstevel@tonic-gate /*
6287c478bd9Sstevel@tonic-gate  * Function:
6297c478bd9Sstevel@tonic-gate  *      ibt_query_hca_ports
6307c478bd9Sstevel@tonic-gate  * Input:
6317c478bd9Sstevel@tonic-gate  *      hca_hdl	    - The HCA handle.
6327c478bd9Sstevel@tonic-gate  *	port        - Port number.  If "0", then query ALL Ports.
6337c478bd9Sstevel@tonic-gate  * Output:
6347c478bd9Sstevel@tonic-gate  *      port_info_p - The address of a pointer to a ibt_hca_portinfo_t struct.
6357c478bd9Sstevel@tonic-gate  *      ports_p     - The number of hca ports on the specified HCA.
6367c478bd9Sstevel@tonic-gate  *      size_p      - Size of the memory allocated by IBTL to get portinfo,
6377c478bd9Sstevel@tonic-gate  *                   to be freed by calling ibt_free_portinfo().
6387c478bd9Sstevel@tonic-gate  * Returns:
6397c478bd9Sstevel@tonic-gate  *      IBT_SUCCESS
6407c478bd9Sstevel@tonic-gate  *      IBT_HCA_HDL_INVALID
6417c478bd9Sstevel@tonic-gate  *      IBT_HCA_INVALID
6427c478bd9Sstevel@tonic-gate  * Description:
6437c478bd9Sstevel@tonic-gate  *      Returns HCA port attributes for either "one", or "all" of the HCA ports.
6447c478bd9Sstevel@tonic-gate  */
6457c478bd9Sstevel@tonic-gate ibt_status_t
ibt_query_hca_ports(ibt_hca_hdl_t hca_hdl,uint8_t port,ibt_hca_portinfo_t ** port_info_p,uint_t * ports_p,uint_t * size_p)6467c478bd9Sstevel@tonic-gate ibt_query_hca_ports(ibt_hca_hdl_t hca_hdl, uint8_t port,
6477c478bd9Sstevel@tonic-gate     ibt_hca_portinfo_t **port_info_p, uint_t *ports_p, uint_t *size_p)
6487c478bd9Sstevel@tonic-gate {
6497c478bd9Sstevel@tonic-gate 	ibt_status_t	retval;
6507c478bd9Sstevel@tonic-gate 
6517c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L3(ibtf_hca, "ibt_query_hca_ports(%p, %d)",
6527c478bd9Sstevel@tonic-gate 	    hca_hdl, port);
6537c478bd9Sstevel@tonic-gate 
6547c478bd9Sstevel@tonic-gate 	mutex_enter(&ibtl_clnt_list_mutex);
6557c478bd9Sstevel@tonic-gate 
6567c478bd9Sstevel@tonic-gate 	retval = ibtl_query_hca_ports(hca_hdl->ha_hca_devp, port, port_info_p,
6577c478bd9Sstevel@tonic-gate 	    ports_p, size_p, 0);
6587c478bd9Sstevel@tonic-gate 
6597c478bd9Sstevel@tonic-gate 	mutex_exit(&ibtl_clnt_list_mutex);
6607c478bd9Sstevel@tonic-gate 
6617c478bd9Sstevel@tonic-gate 	return (retval);
6627c478bd9Sstevel@tonic-gate }
6637c478bd9Sstevel@tonic-gate 
6647c478bd9Sstevel@tonic-gate /*
6657c478bd9Sstevel@tonic-gate  * Function:
6667c478bd9Sstevel@tonic-gate  *      ibt_query_hca_ports_byguid
6677c478bd9Sstevel@tonic-gate  * Input:
6687c478bd9Sstevel@tonic-gate  *      hca_guid    - The HCA node GUID.
6697c478bd9Sstevel@tonic-gate  *	port        - Port number.  If "0", then query ALL Ports.
6707c478bd9Sstevel@tonic-gate  * Output:
6717c478bd9Sstevel@tonic-gate  *      port_info_p - The address of a pointer to a ibt_hca_portinfo_t struct.
6727c478bd9Sstevel@tonic-gate  *      ports_p     - The number of hca ports on the specified HCA.
6737c478bd9Sstevel@tonic-gate  *      size_p      - Size of the memory allocated by IBTL to get portinfo,
6747c478bd9Sstevel@tonic-gate  *                   to be freed by calling ibt_free_portinfo().
6757c478bd9Sstevel@tonic-gate  * Returns:
6767c478bd9Sstevel@tonic-gate  *      IBT_SUCCESS
6777c478bd9Sstevel@tonic-gate  *      IBT_HCA_HDL_INVALID
6787c478bd9Sstevel@tonic-gate  *      IBT_HCA_INVALID
6797c478bd9Sstevel@tonic-gate  * Description:
6807c478bd9Sstevel@tonic-gate  *      Returns HCA port attributes for either "one", or "all" of the HCA ports.
6817c478bd9Sstevel@tonic-gate  */
6827c478bd9Sstevel@tonic-gate ibt_status_t
ibt_query_hca_ports_byguid(ib_guid_t hca_guid,uint8_t port,ibt_hca_portinfo_t ** port_info_p,uint_t * ports_p,uint_t * size_p)6837c478bd9Sstevel@tonic-gate ibt_query_hca_ports_byguid(ib_guid_t hca_guid, uint8_t port,
6847c478bd9Sstevel@tonic-gate     ibt_hca_portinfo_t **port_info_p, uint_t *ports_p, uint_t *size_p)
6857c478bd9Sstevel@tonic-gate {
6867c478bd9Sstevel@tonic-gate 	ibtl_hca_devinfo_t	*hca_devp;	/* HCA Dev Info */
6877c478bd9Sstevel@tonic-gate 	ibt_status_t		retval;
6887c478bd9Sstevel@tonic-gate 
6897c478bd9Sstevel@tonic-gate 	mutex_enter(&ibtl_clnt_list_mutex);
6907c478bd9Sstevel@tonic-gate 	hca_devp = ibtl_get_hcadevinfo(hca_guid);
6917c478bd9Sstevel@tonic-gate 	if (hca_devp == NULL) {
6927c478bd9Sstevel@tonic-gate 		/*
6937c478bd9Sstevel@tonic-gate 		 * If we are here, then the requested HCA device is not present.
6947c478bd9Sstevel@tonic-gate 		 * Return the status as Invalid HCA GUID.
6957c478bd9Sstevel@tonic-gate 		 */
6967c478bd9Sstevel@tonic-gate 		*ports_p = *size_p = 0;
6977c478bd9Sstevel@tonic-gate 		*port_info_p = NULL;
6987c478bd9Sstevel@tonic-gate 		mutex_exit(&ibtl_clnt_list_mutex);
6997c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L2(ibtf_hca, "ibt_query_hca_ports_byguid: "
7007c478bd9Sstevel@tonic-gate 		    "HCA Device Not Found. ");
7017c478bd9Sstevel@tonic-gate 		return (IBT_HCA_INVALID);
7027c478bd9Sstevel@tonic-gate 	}
7037c478bd9Sstevel@tonic-gate 
7047c478bd9Sstevel@tonic-gate 	retval = ibtl_query_hca_ports(hca_devp, port, port_info_p, ports_p,
7057c478bd9Sstevel@tonic-gate 	    size_p, 0);
7067c478bd9Sstevel@tonic-gate 
7077c478bd9Sstevel@tonic-gate 	mutex_exit(&ibtl_clnt_list_mutex);
7087c478bd9Sstevel@tonic-gate 
7097c478bd9Sstevel@tonic-gate 	return (retval);
7107c478bd9Sstevel@tonic-gate }
7117c478bd9Sstevel@tonic-gate 
7127c478bd9Sstevel@tonic-gate /*
7137c478bd9Sstevel@tonic-gate  * Define the above function for CM's use that uses the cached copy.
7147c478bd9Sstevel@tonic-gate  */
7157c478bd9Sstevel@tonic-gate ibt_status_t
ibtl_cm_query_hca_ports_byguid(ib_guid_t hca_guid,uint8_t port,ibt_hca_portinfo_t ** port_info_p,uint_t * ports_p,uint_t * size_p)7167c478bd9Sstevel@tonic-gate ibtl_cm_query_hca_ports_byguid(ib_guid_t hca_guid, uint8_t port,
7177c478bd9Sstevel@tonic-gate     ibt_hca_portinfo_t **port_info_p, uint_t *ports_p, uint_t *size_p)
7187c478bd9Sstevel@tonic-gate {
7197c478bd9Sstevel@tonic-gate 	ibtl_hca_devinfo_t	*hca_devp;	/* HCA Dev Info */
7207c478bd9Sstevel@tonic-gate 	ibt_status_t		retval;
7217c478bd9Sstevel@tonic-gate 
7227c478bd9Sstevel@tonic-gate 	mutex_enter(&ibtl_clnt_list_mutex);
7237c478bd9Sstevel@tonic-gate 	hca_devp = ibtl_get_hcadevinfo(hca_guid);
7247c478bd9Sstevel@tonic-gate 	if (hca_devp == NULL) {
7257c478bd9Sstevel@tonic-gate 		/*
7267c478bd9Sstevel@tonic-gate 		 * If we are here, then the requested HCA device is not present.
7277c478bd9Sstevel@tonic-gate 		 * Return the status as Invalid HCA GUID.
7287c478bd9Sstevel@tonic-gate 		 */
7297c478bd9Sstevel@tonic-gate 		*ports_p = *size_p = 0;
7307c478bd9Sstevel@tonic-gate 		*port_info_p = NULL;
7317c478bd9Sstevel@tonic-gate 		mutex_exit(&ibtl_clnt_list_mutex);
7327c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L2(ibtf_hca, "ibt_query_hca_ports_byguid: "
7337c478bd9Sstevel@tonic-gate 		    "HCA Device Not Found. ");
7347c478bd9Sstevel@tonic-gate 		return (IBT_HCA_INVALID);
7357c478bd9Sstevel@tonic-gate 	}
7367c478bd9Sstevel@tonic-gate 
7377c478bd9Sstevel@tonic-gate 	retval = ibtl_query_hca_ports(hca_devp, port, port_info_p, ports_p,
7387c478bd9Sstevel@tonic-gate 	    size_p, 1);
7397c478bd9Sstevel@tonic-gate 
7407c478bd9Sstevel@tonic-gate 	mutex_exit(&ibtl_clnt_list_mutex);
7417c478bd9Sstevel@tonic-gate 
7427c478bd9Sstevel@tonic-gate 	return (retval);
7437c478bd9Sstevel@tonic-gate }
7447c478bd9Sstevel@tonic-gate 
7457c478bd9Sstevel@tonic-gate 
7467c478bd9Sstevel@tonic-gate /*
7477c478bd9Sstevel@tonic-gate  * ibtl_query_one_port - fill in portinfo for one port.
7487c478bd9Sstevel@tonic-gate  */
7497c478bd9Sstevel@tonic-gate static ibt_status_t
ibtl_query_one_port(ibtl_hca_devinfo_t * hca_devp,uint8_t port,ibt_hca_portinfo_t ** port_info_p,uint_t * ports_p,uint_t * size_p,int use_cache)7507c478bd9Sstevel@tonic-gate ibtl_query_one_port(ibtl_hca_devinfo_t *hca_devp, uint8_t port,
7517c478bd9Sstevel@tonic-gate     ibt_hca_portinfo_t **port_info_p, uint_t *ports_p, uint_t *size_p,
7527c478bd9Sstevel@tonic-gate     int use_cache)
7537c478bd9Sstevel@tonic-gate {
7547c478bd9Sstevel@tonic-gate 	ibt_hca_portinfo_t	*sp1;	/* src */
7557c478bd9Sstevel@tonic-gate 	ibt_hca_portinfo_t	*p1;	/* dst */
7567c478bd9Sstevel@tonic-gate 	caddr_t			p2;
7577c478bd9Sstevel@tonic-gate 	uint_t			len;
7587c478bd9Sstevel@tonic-gate 	uint_t			sgid_tbl_len, pkey_tbl_len;
7597c478bd9Sstevel@tonic-gate 
7607c478bd9Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&ibtl_clnt_list_mutex));
7617c478bd9Sstevel@tonic-gate 
7627c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L3(ibtf_hca, "ibtl_query_one_port(%p, %d)",
7637c478bd9Sstevel@tonic-gate 	    hca_devp, port);
7647c478bd9Sstevel@tonic-gate 
7657c478bd9Sstevel@tonic-gate 	if (port > hca_devp->hd_hca_attr->hca_nports) {
7667c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L2(ibtf_hca, "ibtl_query_one_port: "
7677c478bd9Sstevel@tonic-gate 		    "invalid port %d", port);
7687c478bd9Sstevel@tonic-gate 		return (IBT_HCA_PORT_INVALID);
7697c478bd9Sstevel@tonic-gate 	}
7707c478bd9Sstevel@tonic-gate 
7717c478bd9Sstevel@tonic-gate 	/* If the PORT_UP event is not supported, we need to query */
7727c478bd9Sstevel@tonic-gate 	sp1 = hca_devp->hd_portinfop + port - 1;
7737c478bd9Sstevel@tonic-gate 	if (use_cache == 0)
7747c478bd9Sstevel@tonic-gate 		ibtl_reinit_hca_portinfo(hca_devp, port);
7757c478bd9Sstevel@tonic-gate 
7767c478bd9Sstevel@tonic-gate 	*ports_p = 1;
7777c478bd9Sstevel@tonic-gate 
7787c478bd9Sstevel@tonic-gate 	/*
7797c478bd9Sstevel@tonic-gate 	 * Calculate how much memory we need for one port, and allocate it.
7807c478bd9Sstevel@tonic-gate 	 */
7817c478bd9Sstevel@tonic-gate 	sgid_tbl_len = ROUNDUP(sp1->p_sgid_tbl_sz * sizeof (ib_gid_t),
7827c478bd9Sstevel@tonic-gate 	    _LONG_LONG_ALIGNMENT);
7837c478bd9Sstevel@tonic-gate 	pkey_tbl_len = ROUNDUP(sp1->p_pkey_tbl_sz * sizeof (ib_pkey_t),
7847c478bd9Sstevel@tonic-gate 	    _LONG_LONG_ALIGNMENT);
7857c478bd9Sstevel@tonic-gate 
7867c478bd9Sstevel@tonic-gate 	len = sizeof (ibt_hca_portinfo_t) + sgid_tbl_len + pkey_tbl_len;
7877c478bd9Sstevel@tonic-gate 	*size_p = len;
7887c478bd9Sstevel@tonic-gate 
7897c478bd9Sstevel@tonic-gate 	p1 = kmem_zalloc(len, KM_SLEEP);
7907c478bd9Sstevel@tonic-gate 	*port_info_p = p1;
7917c478bd9Sstevel@tonic-gate 	bcopy(sp1, p1, sizeof (ibt_hca_portinfo_t));
7927c478bd9Sstevel@tonic-gate 
7937c478bd9Sstevel@tonic-gate 	/* initialize the p_pkey_tbl & p_sgid_tbl pointers. */
7947c478bd9Sstevel@tonic-gate 	p2 = (caddr_t)(p1 + 1);	/* pkeys follow the struct ibt_hca_portinfo_s */
7957c478bd9Sstevel@tonic-gate 	bcopy(sp1->p_pkey_tbl, p2, pkey_tbl_len);
7967c478bd9Sstevel@tonic-gate 	p1->p_pkey_tbl = (ib_pkey_t *)p2;
7977c478bd9Sstevel@tonic-gate 
7987c478bd9Sstevel@tonic-gate 	p2 += pkey_tbl_len;	/* sgids follow the pkeys */
7997c478bd9Sstevel@tonic-gate 	bcopy(sp1->p_sgid_tbl, p2, sgid_tbl_len);
8007c478bd9Sstevel@tonic-gate 	p1->p_sgid_tbl = (ib_gid_t *)p2;
8017c478bd9Sstevel@tonic-gate 
8027c478bd9Sstevel@tonic-gate 	return (IBT_SUCCESS);
8037c478bd9Sstevel@tonic-gate }
8047c478bd9Sstevel@tonic-gate 
8057c478bd9Sstevel@tonic-gate /*
8067c478bd9Sstevel@tonic-gate  * ibtl_query_hca_ports - worker routine to get port_info for clients.
8077c478bd9Sstevel@tonic-gate  */
8087c478bd9Sstevel@tonic-gate static ibt_status_t
ibtl_query_hca_ports(ibtl_hca_devinfo_t * hca_devp,uint8_t port,ibt_hca_portinfo_t ** port_info_p,uint_t * ports_p,uint_t * size_p,int use_cache)8097c478bd9Sstevel@tonic-gate ibtl_query_hca_ports(ibtl_hca_devinfo_t *hca_devp, uint8_t port,
8107c478bd9Sstevel@tonic-gate     ibt_hca_portinfo_t **port_info_p, uint_t *ports_p, uint_t *size_p,
8117c478bd9Sstevel@tonic-gate     int use_cache)
8127c478bd9Sstevel@tonic-gate {
8137c478bd9Sstevel@tonic-gate 	ibt_hca_portinfo_t	*sp1;	/* src */
8147c478bd9Sstevel@tonic-gate 	ibt_hca_portinfo_t	*p1;	/* dst */
8157c478bd9Sstevel@tonic-gate 	uint_t			i, nports;
8167c478bd9Sstevel@tonic-gate 	caddr_t			p2;
8177c478bd9Sstevel@tonic-gate 	uint_t			len;
8187c478bd9Sstevel@tonic-gate 	uint_t			sgid_tbl_len, pkey_tbl_len;
8197c478bd9Sstevel@tonic-gate 
8207c478bd9Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&ibtl_clnt_list_mutex));
8217c478bd9Sstevel@tonic-gate 
8227c478bd9Sstevel@tonic-gate 	/*
8237c478bd9Sstevel@tonic-gate 	 * If user has specified the port num, then query only that port,
8247c478bd9Sstevel@tonic-gate 	 * else query all ports.
8257c478bd9Sstevel@tonic-gate 	 */
8267c478bd9Sstevel@tonic-gate 	if (port)
8277c478bd9Sstevel@tonic-gate 		return (ibtl_query_one_port(hca_devp, port, port_info_p,
8287c478bd9Sstevel@tonic-gate 		    ports_p, size_p, use_cache));
8297c478bd9Sstevel@tonic-gate 
8307c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L3(ibtf_hca, "ibtl_query_hca_ports(%p, ALL)", hca_devp);
8317c478bd9Sstevel@tonic-gate 
8327c478bd9Sstevel@tonic-gate 	nports = hca_devp->hd_hca_attr->hca_nports;
8337c478bd9Sstevel@tonic-gate 	*ports_p = nports;
8347c478bd9Sstevel@tonic-gate 
8357c478bd9Sstevel@tonic-gate 	/* If the PORT_UP event is not supported, we need to query */
8367c478bd9Sstevel@tonic-gate 	if (use_cache == 0)
8377c478bd9Sstevel@tonic-gate 		for (i = 0; i < nports; i++)
8387c478bd9Sstevel@tonic-gate 			ibtl_reinit_hca_portinfo(hca_devp, i + 1);
8397c478bd9Sstevel@tonic-gate 
8407c478bd9Sstevel@tonic-gate 	sp1 = hca_devp->hd_portinfop;
8417c478bd9Sstevel@tonic-gate 
8427c478bd9Sstevel@tonic-gate 	/*
8437c478bd9Sstevel@tonic-gate 	 * Calculate how much memory we need for all ports, and allocate it.
8447c478bd9Sstevel@tonic-gate 	 */
8457c478bd9Sstevel@tonic-gate 	sgid_tbl_len = ROUNDUP(sp1->p_sgid_tbl_sz * sizeof (ib_gid_t),
8467c478bd9Sstevel@tonic-gate 	    _LONG_LONG_ALIGNMENT);
8477c478bd9Sstevel@tonic-gate 	pkey_tbl_len = ROUNDUP(sp1->p_pkey_tbl_sz * sizeof (ib_pkey_t),
8487c478bd9Sstevel@tonic-gate 	    _LONG_LONG_ALIGNMENT);
8497c478bd9Sstevel@tonic-gate 
8507c478bd9Sstevel@tonic-gate 	len = (sizeof (ibt_hca_portinfo_t) + sgid_tbl_len + pkey_tbl_len) *
8517c478bd9Sstevel@tonic-gate 	    nports;
8527c478bd9Sstevel@tonic-gate 	*size_p = len;
8537c478bd9Sstevel@tonic-gate 
8547c478bd9Sstevel@tonic-gate 	ASSERT(len == hca_devp->hd_portinfo_len);
8557c478bd9Sstevel@tonic-gate 
8567c478bd9Sstevel@tonic-gate 	p1 = kmem_zalloc(len, KM_SLEEP);
8577c478bd9Sstevel@tonic-gate 	*port_info_p = p1;
8587c478bd9Sstevel@tonic-gate 	bcopy(sp1, p1, len);	/* start with an exact copy of our cache */
8597c478bd9Sstevel@tonic-gate 
8607c478bd9Sstevel@tonic-gate 	p2 = (caddr_t)(p1 + nports);
8617c478bd9Sstevel@tonic-gate 
8627c478bd9Sstevel@tonic-gate 	/* For each port, update the p_pkey_tbl & p_sgid_tbl ptrs. */
8637c478bd9Sstevel@tonic-gate 	for (i = 0; i < nports; i++) {
8647c478bd9Sstevel@tonic-gate 		p1->p_pkey_tbl = (ib_pkey_t *)p2;
8657c478bd9Sstevel@tonic-gate 		p2 += pkey_tbl_len;
8667c478bd9Sstevel@tonic-gate 		p1->p_sgid_tbl = (ib_gid_t *)p2;
8677c478bd9Sstevel@tonic-gate 		p2 += sgid_tbl_len;
8687c478bd9Sstevel@tonic-gate 		p1++;
8697c478bd9Sstevel@tonic-gate 	}
8707c478bd9Sstevel@tonic-gate 	return (IBT_SUCCESS);
8717c478bd9Sstevel@tonic-gate }
8727c478bd9Sstevel@tonic-gate 
8737c478bd9Sstevel@tonic-gate /*
8747c478bd9Sstevel@tonic-gate  *	Search for a Full pkey.  Use the pkey at index 0 if not found.
8757c478bd9Sstevel@tonic-gate  */
8767c478bd9Sstevel@tonic-gate static void
ibtl_set_default_pkey_ix(ibt_hca_portinfo_t * p1)8777c478bd9Sstevel@tonic-gate ibtl_set_default_pkey_ix(ibt_hca_portinfo_t *p1)
8787c478bd9Sstevel@tonic-gate {
8797c478bd9Sstevel@tonic-gate 	uint16_t	pkey_ix;
8807c478bd9Sstevel@tonic-gate 
8817c478bd9Sstevel@tonic-gate 	for (pkey_ix = 0; pkey_ix < p1->p_pkey_tbl_sz; pkey_ix++) {
8827c478bd9Sstevel@tonic-gate 		if ((p1->p_pkey_tbl[pkey_ix] & 0x8000) &&
8837c478bd9Sstevel@tonic-gate 		    (p1->p_pkey_tbl[pkey_ix] != IB_PKEY_INVALID_FULL)) {
8847c478bd9Sstevel@tonic-gate 			p1->p_def_pkey_ix = pkey_ix;
8857c478bd9Sstevel@tonic-gate 			IBTF_DPRINTF_L3(ibtf_hca,
8867c478bd9Sstevel@tonic-gate 			    "ibtl_set_default_pkey_ix: portinfop %p, "
8877c478bd9Sstevel@tonic-gate 			    "FULL PKEY 0x%x found, pkey_ix is %d",
8887c478bd9Sstevel@tonic-gate 			    p1, p1->p_pkey_tbl[pkey_ix], pkey_ix);
8897c478bd9Sstevel@tonic-gate 			return;
8907c478bd9Sstevel@tonic-gate 		}
8917c478bd9Sstevel@tonic-gate 	}
8927c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L2(ibtf_hca,
8937c478bd9Sstevel@tonic-gate 	    "ibtl_set_default_pkey_ix: portinfop %p: failed "
8947c478bd9Sstevel@tonic-gate 	    "to find a default PKEY in the table, using PKey 0x%x",
8957c478bd9Sstevel@tonic-gate 	    p1, p1->p_pkey_tbl[0]);
8967c478bd9Sstevel@tonic-gate 	p1->p_def_pkey_ix = 0;
8977c478bd9Sstevel@tonic-gate }
8987c478bd9Sstevel@tonic-gate 
8997c478bd9Sstevel@tonic-gate /*
9007c478bd9Sstevel@tonic-gate  * ibtl_reinit_hca_portinfo - update the portinfo cache for use by IBTL.
9017c478bd9Sstevel@tonic-gate  *
9027c478bd9Sstevel@tonic-gate  * We have the HCA driver fill in a temporary portinfo, then we bcopy
9037c478bd9Sstevel@tonic-gate  * it into our cache while holding the appropriate lock.
9047c478bd9Sstevel@tonic-gate  */
9057c478bd9Sstevel@tonic-gate void
ibtl_reinit_hca_portinfo(ibtl_hca_devinfo_t * hca_devp,uint8_t port)9067c478bd9Sstevel@tonic-gate ibtl_reinit_hca_portinfo(ibtl_hca_devinfo_t *hca_devp, uint8_t port)
9077c478bd9Sstevel@tonic-gate {
9087c478bd9Sstevel@tonic-gate 	ibt_status_t		status;
9097c478bd9Sstevel@tonic-gate 	ibt_hca_portinfo_t	*p1, *sp1;
9107c478bd9Sstevel@tonic-gate 	ibt_port_state_t	old_linkstate;
9117c478bd9Sstevel@tonic-gate 	uint_t			len, sgid_tbl_len, pkey_tbl_len;
9127c478bd9Sstevel@tonic-gate 	ib_pkey_t		*saved_pkey_tbl;
9137c478bd9Sstevel@tonic-gate 	ib_gid_t		*saved_sgid_tbl;
9147c478bd9Sstevel@tonic-gate 	ib_sn_prefix_t		sn_pfx = 0;
9157c478bd9Sstevel@tonic-gate 	uint_t			multiSM;
9167c478bd9Sstevel@tonic-gate 	int			i;
9177c478bd9Sstevel@tonic-gate 
9187c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L3(ibtf_hca, "ibtl_reinit_hca_portinfo(%p, %d)",
9197c478bd9Sstevel@tonic-gate 	    hca_devp, port);
9207c478bd9Sstevel@tonic-gate 
9217c478bd9Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&ibtl_clnt_list_mutex));
9227c478bd9Sstevel@tonic-gate 	ASSERT(port != 0);
9237c478bd9Sstevel@tonic-gate 
9247c478bd9Sstevel@tonic-gate 	if (ibtl_portinfo_locked(hca_devp, port)) {
9257c478bd9Sstevel@tonic-gate 		/* we got the lock, so we need to do the portinfo update */
9267c478bd9Sstevel@tonic-gate 
9277c478bd9Sstevel@tonic-gate 		/* invalidate fast_gid_cache */
9287c478bd9Sstevel@tonic-gate 		ibtl_fast_gid_cache_valid = B_FALSE;
9297c478bd9Sstevel@tonic-gate 
9307c478bd9Sstevel@tonic-gate 		p1 = hca_devp->hd_portinfop + port - 1;
9317c478bd9Sstevel@tonic-gate 		sgid_tbl_len = ROUNDUP(p1->p_sgid_tbl_sz * sizeof (ib_gid_t),
9327c478bd9Sstevel@tonic-gate 		    _LONG_LONG_ALIGNMENT);
9337c478bd9Sstevel@tonic-gate 		pkey_tbl_len = ROUNDUP(p1->p_pkey_tbl_sz * sizeof (ib_pkey_t),
9347c478bd9Sstevel@tonic-gate 		    _LONG_LONG_ALIGNMENT);
9357c478bd9Sstevel@tonic-gate 		len = sizeof (ibt_hca_portinfo_t) + sgid_tbl_len + pkey_tbl_len;
9367c478bd9Sstevel@tonic-gate 
9377c478bd9Sstevel@tonic-gate 		/* update was NOT in progress, so we do it here */
9387c478bd9Sstevel@tonic-gate 		mutex_exit(&ibtl_clnt_list_mutex);
9397c478bd9Sstevel@tonic-gate 
9407c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L3(ibtf_hca, "ibtl_reinit_hca_portinfo(%p, %d): "
9417c478bd9Sstevel@tonic-gate 		    "calling ibc_query_hca_ports", hca_devp, port);
9427c478bd9Sstevel@tonic-gate 
9437c478bd9Sstevel@tonic-gate 		sp1 = kmem_zalloc(len, KM_SLEEP);
9447c478bd9Sstevel@tonic-gate 		sp1->p_pkey_tbl = (ib_pkey_t *)(sp1 + 1);
9457c478bd9Sstevel@tonic-gate 		sp1->p_sgid_tbl =
9467c478bd9Sstevel@tonic-gate 		    (ib_gid_t *)((caddr_t)sp1->p_pkey_tbl + pkey_tbl_len);
9477c478bd9Sstevel@tonic-gate 		status = IBTL_HDIP2CIHCAOPS_P(hca_devp)->ibc_query_hca_ports(
9487c478bd9Sstevel@tonic-gate 		    IBTL_HDIP2CIHCA(hca_devp), port, sp1);
9497c478bd9Sstevel@tonic-gate 
9507c478bd9Sstevel@tonic-gate 		mutex_enter(&ibtl_clnt_list_mutex);
9517c478bd9Sstevel@tonic-gate 		if (status != IBT_SUCCESS) {
9527c478bd9Sstevel@tonic-gate 			IBTF_DPRINTF_L2(ibtf_hca,
9537c478bd9Sstevel@tonic-gate 			    "ibtl_reinit_hca_portinfo(%p, %d): "
9547c478bd9Sstevel@tonic-gate 			    "ibc_query_hca_ports() failed: status = %d",
9557c478bd9Sstevel@tonic-gate 			    hca_devp, port, status);
9567c478bd9Sstevel@tonic-gate 		} else {
9577c478bd9Sstevel@tonic-gate 			old_linkstate = p1->p_linkstate;
9587c478bd9Sstevel@tonic-gate 			bcopy(sp1->p_pkey_tbl, p1->p_pkey_tbl, pkey_tbl_len);
9597c478bd9Sstevel@tonic-gate 			bcopy(sp1->p_sgid_tbl, p1->p_sgid_tbl, sgid_tbl_len);
9607c478bd9Sstevel@tonic-gate 			saved_pkey_tbl = p1->p_pkey_tbl;
9617c478bd9Sstevel@tonic-gate 			saved_sgid_tbl = p1->p_sgid_tbl;
9627c478bd9Sstevel@tonic-gate 			bcopy(sp1, p1, sizeof (ibt_hca_portinfo_t));
9637c478bd9Sstevel@tonic-gate 			p1->p_pkey_tbl = saved_pkey_tbl;
9647c478bd9Sstevel@tonic-gate 			p1->p_sgid_tbl = saved_sgid_tbl;
9657c478bd9Sstevel@tonic-gate 			if (p1->p_linkstate == IBT_PORT_ACTIVE) {
9667c478bd9Sstevel@tonic-gate 				ibtl_set_default_pkey_ix(p1);
9677c478bd9Sstevel@tonic-gate 				if (p1->p_linkstate != old_linkstate)
9687c478bd9Sstevel@tonic-gate 					IBTF_DPRINTF_L2(ibtf_hca,
9697c478bd9Sstevel@tonic-gate 					    "ibtl_reinit_hca_portinfo(%p, %d): "
9707c478bd9Sstevel@tonic-gate 					    "PORT UP", hca_devp, port);
9717c478bd9Sstevel@tonic-gate 			} else {
972a1e3386eShiremath 				if (p1->p_linkstate != IBT_PORT_ARM)
973a1e3386eShiremath 					p1->p_base_lid = 0;
9747c478bd9Sstevel@tonic-gate 				if (p1->p_linkstate != old_linkstate)
9757c478bd9Sstevel@tonic-gate 					IBTF_DPRINTF_L2(ibtf_hca,
9767c478bd9Sstevel@tonic-gate 					    "ibtl_reinit_hca_portinfo(%p, %d): "
9777c478bd9Sstevel@tonic-gate 					    "PORT DOWN", hca_devp, port);
9787c478bd9Sstevel@tonic-gate 			}
9797c478bd9Sstevel@tonic-gate 		}
9807c478bd9Sstevel@tonic-gate 		kmem_free(sp1, len);
9817c478bd9Sstevel@tonic-gate 
9827c478bd9Sstevel@tonic-gate 		/* Set multism bit accordingly. */
9837c478bd9Sstevel@tonic-gate 		multiSM = 0;
9847c478bd9Sstevel@tonic-gate 		p1 = hca_devp->hd_portinfop;
9857c478bd9Sstevel@tonic-gate 		for (i = 0; i < hca_devp->hd_hca_attr->hca_nports; i++) {
9867c478bd9Sstevel@tonic-gate 			if (p1->p_linkstate == IBT_PORT_ACTIVE) {
9877c478bd9Sstevel@tonic-gate 				if (sn_pfx == 0) {
9887c478bd9Sstevel@tonic-gate 					sn_pfx = p1->p_sgid_tbl[0].gid_prefix;
9897c478bd9Sstevel@tonic-gate 				} else if (sn_pfx !=
9907c478bd9Sstevel@tonic-gate 				    p1->p_sgid_tbl[0].gid_prefix) {
9917c478bd9Sstevel@tonic-gate 					multiSM = 1;
9927c478bd9Sstevel@tonic-gate 					IBTF_DPRINTF_L3(ibtf_hca,
9937c478bd9Sstevel@tonic-gate 					    "ibtl_reinit_hca_portinfo: "
9947c478bd9Sstevel@tonic-gate 					    "MULTI SM, Port1 SnPfx=0x%llX, "
9957c478bd9Sstevel@tonic-gate 					    "Port2 SnPfx=0x%llX", sn_pfx,
9967c478bd9Sstevel@tonic-gate 					    p1->p_sgid_tbl[0].gid_prefix);
9977c478bd9Sstevel@tonic-gate 				}
9987c478bd9Sstevel@tonic-gate 			}
9997c478bd9Sstevel@tonic-gate 			p1++;
10007c478bd9Sstevel@tonic-gate 		}
10017c478bd9Sstevel@tonic-gate 		hca_devp->hd_multism = multiSM;
10027c478bd9Sstevel@tonic-gate 
10037c478bd9Sstevel@tonic-gate 		ibtl_portinfo_unlock(hca_devp, port);
10047c478bd9Sstevel@tonic-gate 	}
10057c478bd9Sstevel@tonic-gate }
10067c478bd9Sstevel@tonic-gate 
10077c478bd9Sstevel@tonic-gate /*
10087c478bd9Sstevel@tonic-gate  * ibtl_init_hca_portinfo - fill in the portinfo cache for use by IBTL.
10097c478bd9Sstevel@tonic-gate  */
10107c478bd9Sstevel@tonic-gate ibt_status_t
ibtl_init_hca_portinfo(ibtl_hca_devinfo_t * hca_devp)10117c478bd9Sstevel@tonic-gate ibtl_init_hca_portinfo(ibtl_hca_devinfo_t *hca_devp)
10127c478bd9Sstevel@tonic-gate {
10137c478bd9Sstevel@tonic-gate 	ibt_hca_portinfo_t	*p1;
10147c478bd9Sstevel@tonic-gate 	ibt_status_t		retval;
10157c478bd9Sstevel@tonic-gate 	uint_t			i, nports;
10167c478bd9Sstevel@tonic-gate 	caddr_t			p2;
10177c478bd9Sstevel@tonic-gate 	uint_t			len;
10187c478bd9Sstevel@tonic-gate 	uint_t			sgid_tbl_len, pkey_tbl_len;
10197c478bd9Sstevel@tonic-gate 	uint_t			sgid_tbl_sz, pkey_tbl_sz;
10207c478bd9Sstevel@tonic-gate 	ib_sn_prefix_t		sn_pfx = 0;
10217c478bd9Sstevel@tonic-gate 	uint_t			multiSM;
10227c478bd9Sstevel@tonic-gate 
10237c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L2(ibtf_hca, "ibtl_init_hca_portinfo(%p)", hca_devp);
10247c478bd9Sstevel@tonic-gate 
10257c478bd9Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&ibtl_clnt_list_mutex));
10267c478bd9Sstevel@tonic-gate 
10277c478bd9Sstevel@tonic-gate 	nports = hca_devp->hd_hca_attr->hca_nports;
10287c478bd9Sstevel@tonic-gate 
10297c478bd9Sstevel@tonic-gate 	/*
10307c478bd9Sstevel@tonic-gate 	 * Calculate how much memory we need for all ports, and allocate it.
10317c478bd9Sstevel@tonic-gate 	 */
10327c478bd9Sstevel@tonic-gate 	pkey_tbl_sz = IBTL_HDIP2PKEYTBLSZ(hca_devp);
10337c478bd9Sstevel@tonic-gate 	sgid_tbl_sz = IBTL_HDIP2SGIDTBLSZ(hca_devp);
10347c478bd9Sstevel@tonic-gate 	pkey_tbl_len = ROUNDUP(pkey_tbl_sz * sizeof (ib_pkey_t),
10357c478bd9Sstevel@tonic-gate 	    _LONG_LONG_ALIGNMENT);
10367c478bd9Sstevel@tonic-gate 	sgid_tbl_len = ROUNDUP(sgid_tbl_sz * sizeof (ib_gid_t),
10377c478bd9Sstevel@tonic-gate 	    _LONG_LONG_ALIGNMENT);
10387c478bd9Sstevel@tonic-gate 
10397c478bd9Sstevel@tonic-gate 	len = (sizeof (ibt_hca_portinfo_t) + sgid_tbl_len + pkey_tbl_len) *
10407c478bd9Sstevel@tonic-gate 	    nports;
10417c478bd9Sstevel@tonic-gate 
10427c478bd9Sstevel@tonic-gate 	p1 = kmem_zalloc(len, KM_SLEEP);
10437c478bd9Sstevel@tonic-gate 	p2 = (caddr_t)(p1 + nports);
10447c478bd9Sstevel@tonic-gate 
10457c478bd9Sstevel@tonic-gate 	hca_devp->hd_portinfop = p1;
10467c478bd9Sstevel@tonic-gate 	hca_devp->hd_portinfo_len = len;
10477c478bd9Sstevel@tonic-gate 
10487c478bd9Sstevel@tonic-gate 	/* For each port initialize the p_pkey_tbl & p_sgid_tbl ptrs. */
10497c478bd9Sstevel@tonic-gate 	for (i = 0; i < nports; i++) {
10507c478bd9Sstevel@tonic-gate 		p1->p_pkey_tbl_sz = pkey_tbl_sz;
10517c478bd9Sstevel@tonic-gate 		p1->p_sgid_tbl_sz = sgid_tbl_sz;
10527c478bd9Sstevel@tonic-gate 		p1->p_pkey_tbl = (ib_pkey_t *)p2;
10537c478bd9Sstevel@tonic-gate 		p2 += pkey_tbl_len;
10547c478bd9Sstevel@tonic-gate 		p1->p_sgid_tbl = (ib_gid_t *)p2;
10557c478bd9Sstevel@tonic-gate 		p2 += sgid_tbl_len;
10567c478bd9Sstevel@tonic-gate 		p1++;
10577c478bd9Sstevel@tonic-gate 	}
10587c478bd9Sstevel@tonic-gate 	p1 = hca_devp->hd_portinfop;
10597c478bd9Sstevel@tonic-gate 	mutex_exit(&ibtl_clnt_list_mutex);
10607c478bd9Sstevel@tonic-gate 
10617c478bd9Sstevel@tonic-gate 	/* re-direct the call to CI's call */
10627c478bd9Sstevel@tonic-gate 	retval = IBTL_HDIP2CIHCAOPS_P(hca_devp)->ibc_query_hca_ports(
10637c478bd9Sstevel@tonic-gate 	    IBTL_HDIP2CIHCA(hca_devp), 0, p1);
10647c478bd9Sstevel@tonic-gate 
10657c478bd9Sstevel@tonic-gate 	mutex_enter(&ibtl_clnt_list_mutex);
10667c478bd9Sstevel@tonic-gate 	if (retval != IBT_SUCCESS) {
10677c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L2(ibtf_hca, "ibtl_init_hca_portinfo(%p): "
10687c478bd9Sstevel@tonic-gate 		    "ibc_query_hca_ports() failed: status = %d",
10697c478bd9Sstevel@tonic-gate 		    hca_devp, retval);
10707c478bd9Sstevel@tonic-gate 		kmem_free(hca_devp->hd_portinfop, len);
10717c478bd9Sstevel@tonic-gate 		hca_devp->hd_portinfop = NULL;
10727c478bd9Sstevel@tonic-gate 		hca_devp->hd_portinfo_len = 0;
10737c478bd9Sstevel@tonic-gate 		return (retval);
10747c478bd9Sstevel@tonic-gate 	}
10757c478bd9Sstevel@tonic-gate 
10767c478bd9Sstevel@tonic-gate 	p1 = hca_devp->hd_portinfop;
10777c478bd9Sstevel@tonic-gate 	multiSM = 0;
10787c478bd9Sstevel@tonic-gate 	for (i = 0; i < nports; i++) {
10797c478bd9Sstevel@tonic-gate 		if (p1->p_linkstate == IBT_PORT_ACTIVE) {
10807c478bd9Sstevel@tonic-gate 			ibtl_set_default_pkey_ix(p1);
10817c478bd9Sstevel@tonic-gate 			if (sn_pfx == 0) {
10827c478bd9Sstevel@tonic-gate 				sn_pfx = p1->p_sgid_tbl[0].gid_prefix;
10837c478bd9Sstevel@tonic-gate 			} else if (p1->p_sgid_tbl[0].gid_prefix != sn_pfx) {
10847c478bd9Sstevel@tonic-gate 				multiSM = 1;
10857c478bd9Sstevel@tonic-gate 				IBTF_DPRINTF_L3(ibtf_hca,
10867c478bd9Sstevel@tonic-gate 				    "ibtl_init_hca_portinfo: MULTI SM, "
10877c478bd9Sstevel@tonic-gate 				    "Port1 SnPfx=0x%llX, Port2 SnPfx=0x%llX",
10887c478bd9Sstevel@tonic-gate 				    sn_pfx, p1->p_sgid_tbl[0].gid_prefix);
10897c478bd9Sstevel@tonic-gate 			}
10907c478bd9Sstevel@tonic-gate 		} else {
1091a1e3386eShiremath 			if (p1->p_linkstate != IBT_PORT_ARM)
1092a1e3386eShiremath 				p1->p_base_lid = 0;
10937c478bd9Sstevel@tonic-gate 		}
10947c478bd9Sstevel@tonic-gate 		p1++;
10957c478bd9Sstevel@tonic-gate 	}
10967c478bd9Sstevel@tonic-gate 	hca_devp->hd_multism = multiSM;
10977c478bd9Sstevel@tonic-gate 
10987c478bd9Sstevel@tonic-gate 	return (IBT_SUCCESS);
10997c478bd9Sstevel@tonic-gate }
11007c478bd9Sstevel@tonic-gate 
11017c478bd9Sstevel@tonic-gate /*
11027c478bd9Sstevel@tonic-gate  * Function:
11037c478bd9Sstevel@tonic-gate  *	ibt_modify_system_image
11047c478bd9Sstevel@tonic-gate  * Input:
11057c478bd9Sstevel@tonic-gate  *	hca_hdl	 - The HCA handle.
11067c478bd9Sstevel@tonic-gate  *	sys_guid - The New system image GUID.
11077c478bd9Sstevel@tonic-gate  * Description:
11087c478bd9Sstevel@tonic-gate  *	Modify specified HCA's system image GUID.
11097c478bd9Sstevel@tonic-gate  */
11107c478bd9Sstevel@tonic-gate ibt_status_t
ibt_modify_system_image(ibt_hca_hdl_t hca_hdl,ib_guid_t sys_guid)11117c478bd9Sstevel@tonic-gate ibt_modify_system_image(ibt_hca_hdl_t hca_hdl, ib_guid_t sys_guid)
11127c478bd9Sstevel@tonic-gate {
11137c478bd9Sstevel@tonic-gate 	ibt_status_t		retval;
11147c478bd9Sstevel@tonic-gate 
11157c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L3(ibtf_hca, "ibt_modify_system_image(%p, %llX)",
11167c478bd9Sstevel@tonic-gate 	    hca_hdl, sys_guid);
11177c478bd9Sstevel@tonic-gate 
11187c478bd9Sstevel@tonic-gate 	mutex_enter(&ibtl_clnt_list_mutex);
11197c478bd9Sstevel@tonic-gate 	/* Get HCA Dev Info Structure, referenced by HCA GUID. */
11207c478bd9Sstevel@tonic-gate 
11217c478bd9Sstevel@tonic-gate 	/* re-direct the call to CI's call */
11227c478bd9Sstevel@tonic-gate 	retval = IBTL_HCA2CIHCAOPS_P(hca_hdl)->ibc_modify_system_image(
11237c478bd9Sstevel@tonic-gate 	    IBTL_HCA2CIHCA(hca_hdl), sys_guid);
11247c478bd9Sstevel@tonic-gate 
11257c478bd9Sstevel@tonic-gate 	mutex_exit(&ibtl_clnt_list_mutex);
11267c478bd9Sstevel@tonic-gate 	return (retval);
11277c478bd9Sstevel@tonic-gate }
11287c478bd9Sstevel@tonic-gate 
11297c478bd9Sstevel@tonic-gate /*
11307c478bd9Sstevel@tonic-gate  * Function:
11317c478bd9Sstevel@tonic-gate  *	ibt_modify_system_image_byguid
11327c478bd9Sstevel@tonic-gate  *
11337c478bd9Sstevel@tonic-gate  * Input:
11347c478bd9Sstevel@tonic-gate  *	hca_guid - The HCA Node GUID.
11357c478bd9Sstevel@tonic-gate  *	sys_guid - The New system image GUID.
11367c478bd9Sstevel@tonic-gate  * Description:
11377c478bd9Sstevel@tonic-gate  *	Modify specified HCA's system image GUID.
11387c478bd9Sstevel@tonic-gate  */
11397c478bd9Sstevel@tonic-gate ibt_status_t
ibt_modify_system_image_byguid(ib_guid_t hca_guid,ib_guid_t sys_guid)11407c478bd9Sstevel@tonic-gate ibt_modify_system_image_byguid(ib_guid_t hca_guid, ib_guid_t sys_guid)
11417c478bd9Sstevel@tonic-gate {
11427c478bd9Sstevel@tonic-gate 	ibtl_hca_devinfo_t	*hca_devp;	/* HCA Dev Info. */
11437c478bd9Sstevel@tonic-gate 	ibt_status_t		retval;
11447c478bd9Sstevel@tonic-gate 
11457c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L3(ibtf_hca, "ibt_modify_system_image_byguid(%llX, %llX)",
11467c478bd9Sstevel@tonic-gate 	    hca_guid, sys_guid);
11477c478bd9Sstevel@tonic-gate 
11487c478bd9Sstevel@tonic-gate 	mutex_enter(&ibtl_clnt_list_mutex);
11497c478bd9Sstevel@tonic-gate 	/* Get HCA Dev Info Structure, referenced by HCA GUID. */
11507c478bd9Sstevel@tonic-gate 	hca_devp = ibtl_get_hcadevinfo(hca_guid);
11517c478bd9Sstevel@tonic-gate 	if (hca_devp == NULL) {
11527c478bd9Sstevel@tonic-gate 		/*
11537c478bd9Sstevel@tonic-gate 		 * If we are here, then the requested HCA device is not present.
11547c478bd9Sstevel@tonic-gate 		 */
11557c478bd9Sstevel@tonic-gate 		mutex_exit(&ibtl_clnt_list_mutex);
11567c478bd9Sstevel@tonic-gate 		return (IBT_HCA_INVALID);
11577c478bd9Sstevel@tonic-gate 	}
11587c478bd9Sstevel@tonic-gate 
11597c478bd9Sstevel@tonic-gate 	/* re-direct the call to CI's call */
11607c478bd9Sstevel@tonic-gate 	retval = IBTL_HDIP2CIHCAOPS_P(hca_devp)->ibc_modify_system_image(
11617c478bd9Sstevel@tonic-gate 	    IBTL_HDIP2CIHCA(hca_devp), sys_guid);
11627c478bd9Sstevel@tonic-gate 
11637c478bd9Sstevel@tonic-gate 	mutex_exit(&ibtl_clnt_list_mutex);
11647c478bd9Sstevel@tonic-gate 	return (retval);
11657c478bd9Sstevel@tonic-gate }
11667c478bd9Sstevel@tonic-gate 
11677c478bd9Sstevel@tonic-gate /*
11687c478bd9Sstevel@tonic-gate  * Function:
11697c478bd9Sstevel@tonic-gate  *      ibt_modify_port_byguid
11707c478bd9Sstevel@tonic-gate  * Input:
11717c478bd9Sstevel@tonic-gate  *      hca_guid - The HCA Guid.
11727c478bd9Sstevel@tonic-gate  *      cmds     - A pointer to an array of ibt_port_modify_t cmds. The
11737c478bd9Sstevel@tonic-gate  *                 pmod_port field specifies the port to modify (all ports if 0)
11747c478bd9Sstevel@tonic-gate  *                 and the pmod_flags field specifies which attribute to reset.
11757c478bd9Sstevel@tonic-gate  *      num_cmds - The number of commands in the cmds array.
11767c478bd9Sstevel@tonic-gate  * Output:
11777c478bd9Sstevel@tonic-gate  *      none.
11787c478bd9Sstevel@tonic-gate  * Returns:
11797c478bd9Sstevel@tonic-gate  *      IBT_SUCCESS
11807c478bd9Sstevel@tonic-gate  *      IBT_HCA_HDL_INVALID
11817c478bd9Sstevel@tonic-gate  *      IBT_HCA_CNTR_INVALID
11827c478bd9Sstevel@tonic-gate  *      IBT_HCA_CNTR_VAL_INVALID
11837c478bd9Sstevel@tonic-gate  * Description:
11847c478bd9Sstevel@tonic-gate  *      Reset the specified port, or all ports attribute(s).
11857c478bd9Sstevel@tonic-gate  */
11867c478bd9Sstevel@tonic-gate ibt_status_t
ibt_modify_port_byguid(ib_guid_t hca_guid,uint8_t port,ibt_port_modify_flags_t flags,uint8_t init_type)11877c478bd9Sstevel@tonic-gate ibt_modify_port_byguid(ib_guid_t hca_guid,  uint8_t port,
11887c478bd9Sstevel@tonic-gate     ibt_port_modify_flags_t flags, uint8_t init_type)
11897c478bd9Sstevel@tonic-gate {
11907c478bd9Sstevel@tonic-gate 	ibtl_hca_devinfo_t	*hca_devp;	/* HCA Dev Info. */
11917c478bd9Sstevel@tonic-gate 	ibt_status_t		retval;
11927c478bd9Sstevel@tonic-gate 
11937c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L3(ibtf_hca, "ibt_modify_port_byguid(%llX, %d, %X, %X)",
11947c478bd9Sstevel@tonic-gate 	    hca_guid, port, flags, init_type);
11957c478bd9Sstevel@tonic-gate 
11967c478bd9Sstevel@tonic-gate 	mutex_enter(&ibtl_clnt_list_mutex);
11977c478bd9Sstevel@tonic-gate 	/* Get HCA Dev Info Structure, referenced by HCA GUID. */
11987c478bd9Sstevel@tonic-gate 	hca_devp = ibtl_get_hcadevinfo(hca_guid);
11997c478bd9Sstevel@tonic-gate 	if (hca_devp == NULL) {
12007c478bd9Sstevel@tonic-gate 		/*
12017c478bd9Sstevel@tonic-gate 		 * If we are here, then the requested HCA device is not present.
12027c478bd9Sstevel@tonic-gate 		 */
12037c478bd9Sstevel@tonic-gate 		mutex_exit(&ibtl_clnt_list_mutex);
12047c478bd9Sstevel@tonic-gate 		return (IBT_HCA_INVALID);
12057c478bd9Sstevel@tonic-gate 	}
12067c478bd9Sstevel@tonic-gate 
12077c478bd9Sstevel@tonic-gate 	/* re-direct the call to CI's call */
12087c478bd9Sstevel@tonic-gate 	retval = IBTL_HDIP2CIHCAOPS_P(hca_devp)->ibc_modify_ports(
12097c478bd9Sstevel@tonic-gate 	    IBTL_HDIP2CIHCA(hca_devp), port, flags, init_type);
12107c478bd9Sstevel@tonic-gate 
12117c478bd9Sstevel@tonic-gate 	mutex_exit(&ibtl_clnt_list_mutex);
12127c478bd9Sstevel@tonic-gate 	return (retval);
12137c478bd9Sstevel@tonic-gate }
12147c478bd9Sstevel@tonic-gate 
12157c478bd9Sstevel@tonic-gate /*
12167c478bd9Sstevel@tonic-gate  * Function:
12177c478bd9Sstevel@tonic-gate  *      ibt_modify_port
12187c478bd9Sstevel@tonic-gate  * Input:
12197c478bd9Sstevel@tonic-gate  *      hca_hdl  - The HCA handle.
12207c478bd9Sstevel@tonic-gate  *      cmds     - A pointer to an array of ibt_port_modify_t cmds. The
12217c478bd9Sstevel@tonic-gate  *                 pmod_port field specifies the port to modify (all ports if 0)
12227c478bd9Sstevel@tonic-gate  *                 and the pmod_flags field specifies which attribute to reset.
12237c478bd9Sstevel@tonic-gate  *      num_cmds - The number of commands in the cmds array.
12247c478bd9Sstevel@tonic-gate  * Output:
12257c478bd9Sstevel@tonic-gate  *      none.
12267c478bd9Sstevel@tonic-gate  * Returns:
12277c478bd9Sstevel@tonic-gate  *      IBT_SUCCESS
12287c478bd9Sstevel@tonic-gate  *      IBT_HCA_HDL_INVALID
12297c478bd9Sstevel@tonic-gate  *      IBT_HCA_CNTR_INVALID
12307c478bd9Sstevel@tonic-gate  *      IBT_HCA_CNTR_VAL_INVALID
12317c478bd9Sstevel@tonic-gate  * Description:
12327c478bd9Sstevel@tonic-gate  *      Reset the specified port, or all ports attribute(s).
12337c478bd9Sstevel@tonic-gate  */
12347c478bd9Sstevel@tonic-gate ibt_status_t
ibt_modify_port(ibt_hca_hdl_t hca_hdl,uint8_t port,ibt_port_modify_flags_t flags,uint8_t init_type)12357c478bd9Sstevel@tonic-gate ibt_modify_port(ibt_hca_hdl_t hca_hdl, uint8_t port,
12367c478bd9Sstevel@tonic-gate     ibt_port_modify_flags_t flags, uint8_t init_type)
12377c478bd9Sstevel@tonic-gate 
12387c478bd9Sstevel@tonic-gate {
12397c478bd9Sstevel@tonic-gate 	ibt_status_t		retval;
12407c478bd9Sstevel@tonic-gate 
12417c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L3(ibtf_hca, "ibt_modify_port(%p, %d, %X, %X)",
12427c478bd9Sstevel@tonic-gate 	    hca_hdl, port, flags, init_type);
12437c478bd9Sstevel@tonic-gate 
12447c478bd9Sstevel@tonic-gate 	mutex_enter(&ibtl_clnt_list_mutex);
12457c478bd9Sstevel@tonic-gate 
12467c478bd9Sstevel@tonic-gate 	/* re-direct the call to CI's call */
12477c478bd9Sstevel@tonic-gate 	retval = IBTL_HCA2CIHCAOPS_P(hca_hdl)->ibc_modify_ports(
12487c478bd9Sstevel@tonic-gate 	    IBTL_HCA2CIHCA(hca_hdl), port, flags, init_type);
12497c478bd9Sstevel@tonic-gate 
12507c478bd9Sstevel@tonic-gate 	mutex_exit(&ibtl_clnt_list_mutex);
12517c478bd9Sstevel@tonic-gate 	return (retval);
12527c478bd9Sstevel@tonic-gate }
12537c478bd9Sstevel@tonic-gate 
12547c478bd9Sstevel@tonic-gate /*
12557c478bd9Sstevel@tonic-gate  * Function:
12567c478bd9Sstevel@tonic-gate  *      ibt_free_portinfo
12577c478bd9Sstevel@tonic-gate  * Input:
12587c478bd9Sstevel@tonic-gate  *      port_info  - The address of an array to a ibt_hca_portinfo_t struct.
12597c478bd9Sstevel@tonic-gate  *	size	   - Memory Size as returned from ibt_query_hca_ports().
12607c478bd9Sstevel@tonic-gate  * Output:
12617c478bd9Sstevel@tonic-gate  *      none
12627c478bd9Sstevel@tonic-gate  * Returns:
12637c478bd9Sstevel@tonic-gate  *      none
12647c478bd9Sstevel@tonic-gate  * Description:
12657c478bd9Sstevel@tonic-gate  *      Frees the memory allocated for a specified ibt_hca_portinfo_t struct.
12667c478bd9Sstevel@tonic-gate  */
12677c478bd9Sstevel@tonic-gate void
ibt_free_portinfo(ibt_hca_portinfo_t * port_info,uint_t size)12687c478bd9Sstevel@tonic-gate ibt_free_portinfo(ibt_hca_portinfo_t *port_info, uint_t size)
12697c478bd9Sstevel@tonic-gate {
12707c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L3(ibtf_hca, "ibt_free_portinfo(%p, %d)",
12717c478bd9Sstevel@tonic-gate 	    port_info, size);
12727c478bd9Sstevel@tonic-gate 
12737c478bd9Sstevel@tonic-gate 	if ((port_info == NULL) || (size == 0)) {
12747c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L2(ibtf_hca, "ibt_free_portinfo: NULL Pointer");
12757c478bd9Sstevel@tonic-gate 	} else {
12767c478bd9Sstevel@tonic-gate 		kmem_free(port_info, size);
12777c478bd9Sstevel@tonic-gate 	}
12787c478bd9Sstevel@tonic-gate }
12797c478bd9Sstevel@tonic-gate 
12807c478bd9Sstevel@tonic-gate 
12817c478bd9Sstevel@tonic-gate /*
12827c478bd9Sstevel@tonic-gate  * Function:
12837c478bd9Sstevel@tonic-gate  *      ibt_get_hcadevinfo
12847c478bd9Sstevel@tonic-gate  * Input:
12857c478bd9Sstevel@tonic-gate  *      hca_guid - The HCA's node GUID.
12867c478bd9Sstevel@tonic-gate  * Output:
12877c478bd9Sstevel@tonic-gate  *      none.
12887c478bd9Sstevel@tonic-gate  * Returns:
12897c478bd9Sstevel@tonic-gate  *      Pointer to HCA Device Info structure whose HCA GUID is requested or NULL
12907c478bd9Sstevel@tonic-gate  * Description:
12917c478bd9Sstevel@tonic-gate  *      Get a pointer to HCA Device Info Structure for the requested HCA GUID.
12927c478bd9Sstevel@tonic-gate  *      If no matching HCA GUID Device info is found, NULL is returned.
12937c478bd9Sstevel@tonic-gate  */
12947c478bd9Sstevel@tonic-gate ibtl_hca_devinfo_t *
ibtl_get_hcadevinfo(ib_guid_t hca_guid)12957c478bd9Sstevel@tonic-gate ibtl_get_hcadevinfo(ib_guid_t hca_guid)
12967c478bd9Sstevel@tonic-gate {
12977c478bd9Sstevel@tonic-gate 	ibtl_hca_devinfo_t	*hca_devp;	/* HCA Dev Info */
12987c478bd9Sstevel@tonic-gate 
12997c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L3(ibtf_hca, "ibtl_get_hcadevinfo(%llX)", hca_guid);
13007c478bd9Sstevel@tonic-gate 
13017c478bd9Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&ibtl_clnt_list_mutex));
13027c478bd9Sstevel@tonic-gate 
13037c478bd9Sstevel@tonic-gate 	hca_devp = ibtl_hca_list;
13047c478bd9Sstevel@tonic-gate 
13057c478bd9Sstevel@tonic-gate 	/*
13067c478bd9Sstevel@tonic-gate 	 * Check whether a HCA device with requested Node GUID is available.
13077c478bd9Sstevel@tonic-gate 	 * This is done, by searching the global HCA devinfo list and
13087c478bd9Sstevel@tonic-gate 	 * comparing the Node GUID from the device attribute info.
13097c478bd9Sstevel@tonic-gate 	 */
13107c478bd9Sstevel@tonic-gate 	while (hca_devp != NULL) {
13117c478bd9Sstevel@tonic-gate 		if (hca_devp->hd_hca_attr->hca_node_guid == hca_guid) {
13127c478bd9Sstevel@tonic-gate 			/* Match Found. */
13137c478bd9Sstevel@tonic-gate 			break;
13147c478bd9Sstevel@tonic-gate 		}
13157c478bd9Sstevel@tonic-gate 		hca_devp = hca_devp->hd_hca_dev_link;
13167c478bd9Sstevel@tonic-gate 	}
13177c478bd9Sstevel@tonic-gate 	return (hca_devp);
13187c478bd9Sstevel@tonic-gate }
13197c478bd9Sstevel@tonic-gate 
13207c478bd9Sstevel@tonic-gate 
13217c478bd9Sstevel@tonic-gate /*
13227c478bd9Sstevel@tonic-gate  * Function:
13237c478bd9Sstevel@tonic-gate  *      ibtl_pkey2index
13247c478bd9Sstevel@tonic-gate  * Input:
13257c478bd9Sstevel@tonic-gate  *      hca_devp     - The IBTL HCA Device Info.
13267c478bd9Sstevel@tonic-gate  *      port_num     - The HCA port number.
13277c478bd9Sstevel@tonic-gate  *      pkey         - The input PKey value, whose index we are interested in.
13287c478bd9Sstevel@tonic-gate  * Output:
13297c478bd9Sstevel@tonic-gate  *      pkey_ix      - The PKey index returned for the specified PKey.
13307c478bd9Sstevel@tonic-gate  * Returns:
13317c478bd9Sstevel@tonic-gate  *      IBT_SUCCESS/IBT_HCA_PORT_INVALID/IBT_INVALID_PARAM
13327c478bd9Sstevel@tonic-gate  * Description:
13337c478bd9Sstevel@tonic-gate  *      Returns the PKey Index for the specified PKey, the device as specified
13347c478bd9Sstevel@tonic-gate  *      by IBT HCA Handle.
13357c478bd9Sstevel@tonic-gate  */
13367c478bd9Sstevel@tonic-gate static ibt_status_t
ibtl_pkey2index(ibtl_hca_devinfo_t * hca_devp,uint8_t port_num,ib_pkey_t pkey,uint16_t * pkey_ix)13377c478bd9Sstevel@tonic-gate ibtl_pkey2index(ibtl_hca_devinfo_t *hca_devp, uint8_t port_num,
13387c478bd9Sstevel@tonic-gate     ib_pkey_t pkey, uint16_t *pkey_ix)
13397c478bd9Sstevel@tonic-gate {
13407c478bd9Sstevel@tonic-gate 	ibt_hca_portinfo_t 	*port_infop;
13417c478bd9Sstevel@tonic-gate 	uint_t			ports;
13427c478bd9Sstevel@tonic-gate 	uint_t			i;
13437c478bd9Sstevel@tonic-gate 
13447c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L3(ibtf_hca, "ibtl_pkey2index(%p, %d, %d)",
13457c478bd9Sstevel@tonic-gate 	    hca_devp, port_num, pkey);
13467c478bd9Sstevel@tonic-gate 
13477c478bd9Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&ibtl_clnt_list_mutex));
13487c478bd9Sstevel@tonic-gate 
13497c478bd9Sstevel@tonic-gate 	if ((pkey == IB_PKEY_INVALID_FULL) ||
13507c478bd9Sstevel@tonic-gate 	    (pkey == IB_PKEY_INVALID_LIMITED))
13517c478bd9Sstevel@tonic-gate 		return (IBT_INVALID_PARAM);
13527c478bd9Sstevel@tonic-gate 
13537c478bd9Sstevel@tonic-gate 	ports = hca_devp->hd_hca_attr->hca_nports;
13547c478bd9Sstevel@tonic-gate 	if ((port_num == 0) || (port_num > ports)) {
13557c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L2(ibtf_hca, "ibtl_pkey2index: "
13567c478bd9Sstevel@tonic-gate 		    "Invalid port_num %d, range is (1 to %d)", port_num, ports);
13577c478bd9Sstevel@tonic-gate 		return (IBT_HCA_PORT_INVALID);
13587c478bd9Sstevel@tonic-gate 	}
13597c478bd9Sstevel@tonic-gate 
13607c478bd9Sstevel@tonic-gate 	port_infop = hca_devp->hd_portinfop + port_num - 1;
13617c478bd9Sstevel@tonic-gate 	for (i = 0; i < port_infop->p_pkey_tbl_sz; i++) {
13627c478bd9Sstevel@tonic-gate 		if (pkey == port_infop->p_pkey_tbl[i]) {
13637c478bd9Sstevel@tonic-gate 			*pkey_ix = i;
13647c478bd9Sstevel@tonic-gate 			return (IBT_SUCCESS);
13657c478bd9Sstevel@tonic-gate 		}
13667c478bd9Sstevel@tonic-gate 	}
13677c478bd9Sstevel@tonic-gate 	return (IBT_INVALID_PARAM);
13687c478bd9Sstevel@tonic-gate }
13697c478bd9Sstevel@tonic-gate 
13707c478bd9Sstevel@tonic-gate /*
13717c478bd9Sstevel@tonic-gate  * Function:
13727c478bd9Sstevel@tonic-gate  *      ibtl_index2pkey
13737c478bd9Sstevel@tonic-gate  * Input:
13747c478bd9Sstevel@tonic-gate  *      hca_devp     - The IBTL HCA Device Info.
13757c478bd9Sstevel@tonic-gate  *      port_num     - The HCA port
13767c478bd9Sstevel@tonic-gate  *      pkey_ix      - The input PKey index, whose PKey we are interested in.
13777c478bd9Sstevel@tonic-gate  * Output:
13787c478bd9Sstevel@tonic-gate  *      pkey         - The returned PKey value.
13797c478bd9Sstevel@tonic-gate  * Returns:
13807c478bd9Sstevel@tonic-gate  *      IBT_SUCCESS/IBT_PKEY_IX_ILLEGAL/IBT_PKEY_IX_INVALID/IBT_HCA_PORT_INVALID
13817c478bd9Sstevel@tonic-gate  * Description:
13827c478bd9Sstevel@tonic-gate  *      Returns the PKey value for the specified PKey index, the device as
13837c478bd9Sstevel@tonic-gate  *      specified by IBT HCA Handle.
13847c478bd9Sstevel@tonic-gate  */
13857c478bd9Sstevel@tonic-gate static ibt_status_t
ibtl_index2pkey(ibtl_hca_devinfo_t * hca_devp,uint8_t port_num,uint16_t pkey_ix,ib_pkey_t * pkey)13867c478bd9Sstevel@tonic-gate ibtl_index2pkey(ibtl_hca_devinfo_t *hca_devp, uint8_t port_num,
13877c478bd9Sstevel@tonic-gate     uint16_t pkey_ix, ib_pkey_t *pkey)
13887c478bd9Sstevel@tonic-gate {
13897c478bd9Sstevel@tonic-gate 	ibt_hca_portinfo_t 	*port_infop;
13907c478bd9Sstevel@tonic-gate 	uint_t			ports;
13917c478bd9Sstevel@tonic-gate 
13927c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L3(ibtf_hca, "ibtl_index2pkey(%p, %d, %d)",
13937c478bd9Sstevel@tonic-gate 	    hca_devp, port_num, pkey_ix);
13947c478bd9Sstevel@tonic-gate 
13957c478bd9Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&ibtl_clnt_list_mutex));
13967c478bd9Sstevel@tonic-gate 
13977c478bd9Sstevel@tonic-gate 	ports = hca_devp->hd_hca_attr->hca_nports;
13987c478bd9Sstevel@tonic-gate 	if ((port_num == 0) || (port_num > ports)) {
13997c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L2(ibtf_hca, "ibtl_index2pkey: "
14007c478bd9Sstevel@tonic-gate 		    "Invalid port_num %d, range is (1 to %d)", port_num, ports);
14017c478bd9Sstevel@tonic-gate 		return (IBT_HCA_PORT_INVALID);
14027c478bd9Sstevel@tonic-gate 	}
14037c478bd9Sstevel@tonic-gate 
14047c478bd9Sstevel@tonic-gate 	port_infop = hca_devp->hd_portinfop + port_num - 1;
14057c478bd9Sstevel@tonic-gate 	if (pkey_ix >= port_infop->p_pkey_tbl_sz) {
14067c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L2(ibtf_hca, "ibtl_index2pkey: "
14077c478bd9Sstevel@tonic-gate 		    "pkey index %d out of range (0, %d)",
14087c478bd9Sstevel@tonic-gate 		    pkey_ix, port_infop->p_pkey_tbl_sz - 1);
14097c478bd9Sstevel@tonic-gate 		return (IBT_PKEY_IX_ILLEGAL);
14107c478bd9Sstevel@tonic-gate 	}
14117c478bd9Sstevel@tonic-gate 
14127c478bd9Sstevel@tonic-gate 	*pkey = port_infop->p_pkey_tbl[pkey_ix];
14137c478bd9Sstevel@tonic-gate 	if ((*pkey == IB_PKEY_INVALID_FULL) ||
14147c478bd9Sstevel@tonic-gate 	    (*pkey == IB_PKEY_INVALID_LIMITED))
14157c478bd9Sstevel@tonic-gate 		return (IBT_PKEY_IX_INVALID);
14167c478bd9Sstevel@tonic-gate 	return (IBT_SUCCESS);
14177c478bd9Sstevel@tonic-gate }
14187c478bd9Sstevel@tonic-gate 
14197c478bd9Sstevel@tonic-gate /*
14207c478bd9Sstevel@tonic-gate  * Function:
14217c478bd9Sstevel@tonic-gate  *      ibt_pkey2index
14227c478bd9Sstevel@tonic-gate  * Input:
14237c478bd9Sstevel@tonic-gate  *      hca_hdl      - The IBT HCA handle.
14247c478bd9Sstevel@tonic-gate  *      port_num     - The HCA port number.
14257c478bd9Sstevel@tonic-gate  *      pkey         - The input PKey value, whose index we are interested in.
14267c478bd9Sstevel@tonic-gate  * Output:
14277c478bd9Sstevel@tonic-gate  *      pkey_ix      - The PKey index returned for the specified PKey.
14287c478bd9Sstevel@tonic-gate  * Returns:
14297c478bd9Sstevel@tonic-gate  *      IBT_SUCCESS/IBT_HCA_PORT_INVALID/IBT_INVALID_PARAM
14307c478bd9Sstevel@tonic-gate  * Description:
14317c478bd9Sstevel@tonic-gate  *      Returns the PKey Index for the specified PKey, the device as specified
14327c478bd9Sstevel@tonic-gate  *      by IBT HCA Handle.
14337c478bd9Sstevel@tonic-gate  */
14347c478bd9Sstevel@tonic-gate ibt_status_t
ibt_pkey2index(ibt_hca_hdl_t hca_hdl,uint8_t port_num,ib_pkey_t pkey,uint16_t * pkey_ix)14357c478bd9Sstevel@tonic-gate ibt_pkey2index(ibt_hca_hdl_t hca_hdl, uint8_t port_num, ib_pkey_t pkey,
14367c478bd9Sstevel@tonic-gate     uint16_t *pkey_ix)
14377c478bd9Sstevel@tonic-gate {
14387c478bd9Sstevel@tonic-gate 	ibt_status_t		retval;
14397c478bd9Sstevel@tonic-gate 
14407c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L3(ibtf_hca, "ibt_pkey2index(%p, %d, %d)",
14417c478bd9Sstevel@tonic-gate 	    hca_hdl, port_num, pkey);
14427c478bd9Sstevel@tonic-gate 
14437c478bd9Sstevel@tonic-gate 	mutex_enter(&ibtl_clnt_list_mutex);
14447c478bd9Sstevel@tonic-gate 	retval = ibtl_pkey2index(hca_hdl->ha_hca_devp, port_num, pkey, pkey_ix);
14457c478bd9Sstevel@tonic-gate 	mutex_exit(&ibtl_clnt_list_mutex);
14467c478bd9Sstevel@tonic-gate 
14477c478bd9Sstevel@tonic-gate 	return (retval);
14487c478bd9Sstevel@tonic-gate }
14497c478bd9Sstevel@tonic-gate 
14507c478bd9Sstevel@tonic-gate /*
14517c478bd9Sstevel@tonic-gate  * Function:
14527c478bd9Sstevel@tonic-gate  *      ibt_pkey2index_byguid
14537c478bd9Sstevel@tonic-gate  * Input:
14547c478bd9Sstevel@tonic-gate  *      hca_guid     - The HCA's node GUID.
14557c478bd9Sstevel@tonic-gate  *      port_num     - The HCA port number.
14567c478bd9Sstevel@tonic-gate  *      pkey         - The input PKey value, whose index we are interested in.
14577c478bd9Sstevel@tonic-gate  * Output:
14587c478bd9Sstevel@tonic-gate  *      pkey_ix      - The PKey Index returned for the specified PKey.
14597c478bd9Sstevel@tonic-gate  * Returns:
14607c478bd9Sstevel@tonic-gate  *      IBT_SUCCESS/IBT_HCA_PORT_INVALID/IBT_INVALID_PARAM/IBT_HCA_INVALID
14617c478bd9Sstevel@tonic-gate  * Description:
14627c478bd9Sstevel@tonic-gate  *      Returns the PKey Index for the specified PKey, the device as specified
14637c478bd9Sstevel@tonic-gate  *      by HCA GUID Info.
14647c478bd9Sstevel@tonic-gate  */
14657c478bd9Sstevel@tonic-gate ibt_status_t
ibt_pkey2index_byguid(ib_guid_t hca_guid,uint8_t port_num,ib_pkey_t pkey,uint16_t * pkey_ix)14667c478bd9Sstevel@tonic-gate ibt_pkey2index_byguid(ib_guid_t hca_guid, uint8_t port_num, ib_pkey_t pkey,
14677c478bd9Sstevel@tonic-gate     uint16_t *pkey_ix)
14687c478bd9Sstevel@tonic-gate {
14697c478bd9Sstevel@tonic-gate 	ibt_status_t		retval;
14707c478bd9Sstevel@tonic-gate 	ibtl_hca_devinfo_t	*hca_devp;	/* HCA Dev Info */
14717c478bd9Sstevel@tonic-gate 
14727c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L3(ibtf_hca, "ibt_pkey2index_byguid(%llX, %d, %d)",
14737c478bd9Sstevel@tonic-gate 	    hca_guid, port_num, pkey);
14747c478bd9Sstevel@tonic-gate 
14757c478bd9Sstevel@tonic-gate 	mutex_enter(&ibtl_clnt_list_mutex);
14767c478bd9Sstevel@tonic-gate 	hca_devp = ibtl_get_hcadevinfo(hca_guid);
14777c478bd9Sstevel@tonic-gate 	if (hca_devp == NULL) {
14787c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L2(ibtf_hca, "ibt_pkey2index_byguid: "
14797c478bd9Sstevel@tonic-gate 		    "Invalid HCA GUID 0x%llx", hca_guid);
14807c478bd9Sstevel@tonic-gate 		mutex_exit(&ibtl_clnt_list_mutex);
14817c478bd9Sstevel@tonic-gate 		return (IBT_HCA_INVALID);
14827c478bd9Sstevel@tonic-gate 	}
14837c478bd9Sstevel@tonic-gate 	retval = ibtl_pkey2index(hca_devp, port_num, pkey, pkey_ix);
14847c478bd9Sstevel@tonic-gate 	mutex_exit(&ibtl_clnt_list_mutex);
14857c478bd9Sstevel@tonic-gate 
14867c478bd9Sstevel@tonic-gate 	return (retval);
14877c478bd9Sstevel@tonic-gate }
14887c478bd9Sstevel@tonic-gate 
14897c478bd9Sstevel@tonic-gate 
14907c478bd9Sstevel@tonic-gate /*
14917c478bd9Sstevel@tonic-gate  * Function:
14927c478bd9Sstevel@tonic-gate  *      ibt_index2pkey
14937c478bd9Sstevel@tonic-gate  * Input:
14947c478bd9Sstevel@tonic-gate  *      hca_hdl      - The IBT HCA handle.
14957c478bd9Sstevel@tonic-gate  *      port_num     - The HCA port
14967c478bd9Sstevel@tonic-gate  *      pkey_ix      - The input PKey index, whose PKey we are interested in.
14977c478bd9Sstevel@tonic-gate  * Output:
14987c478bd9Sstevel@tonic-gate  *      pkey         - The returned PKey value.
14997c478bd9Sstevel@tonic-gate  * Returns:
15007c478bd9Sstevel@tonic-gate  *      IBT_SUCCESS/IBT_PKEY_IX_ILLEGAL/IBT_PKEY_IX_INVALID/IBT_HCA_PORT_INVALID
15017c478bd9Sstevel@tonic-gate  * Description:
15027c478bd9Sstevel@tonic-gate  *      Returns the PKey value for the specified PKey index, the device as
15037c478bd9Sstevel@tonic-gate  *      specified by IBT HCA Handle.
15047c478bd9Sstevel@tonic-gate  */
15057c478bd9Sstevel@tonic-gate ibt_status_t
ibt_index2pkey(ibt_hca_hdl_t hca_hdl,uint8_t port_num,uint16_t pkey_ix,ib_pkey_t * pkey)15067c478bd9Sstevel@tonic-gate ibt_index2pkey(ibt_hca_hdl_t hca_hdl, uint8_t port_num, uint16_t pkey_ix,
15077c478bd9Sstevel@tonic-gate     ib_pkey_t *pkey)
15087c478bd9Sstevel@tonic-gate {
15097c478bd9Sstevel@tonic-gate 	ibt_status_t		retval;
15107c478bd9Sstevel@tonic-gate 
15117c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L3(ibtf_hca, "ibt_index2pkey(%p, %d, %d)",
15127c478bd9Sstevel@tonic-gate 	    hca_hdl, port_num, pkey_ix);
15137c478bd9Sstevel@tonic-gate 
15147c478bd9Sstevel@tonic-gate 	mutex_enter(&ibtl_clnt_list_mutex);
15157c478bd9Sstevel@tonic-gate 	retval = ibtl_index2pkey(hca_hdl->ha_hca_devp, port_num, pkey_ix, pkey);
15167c478bd9Sstevel@tonic-gate 	mutex_exit(&ibtl_clnt_list_mutex);
15177c478bd9Sstevel@tonic-gate 
15187c478bd9Sstevel@tonic-gate 	return (retval);
15197c478bd9Sstevel@tonic-gate }
15207c478bd9Sstevel@tonic-gate 
15217c478bd9Sstevel@tonic-gate /*
15227c478bd9Sstevel@tonic-gate  * Function:
15237c478bd9Sstevel@tonic-gate  *      ibt_index2pkey_byguid
15247c478bd9Sstevel@tonic-gate  * Input:
15257c478bd9Sstevel@tonic-gate  *      hca_guid     - The HCA's node GUID.
15267c478bd9Sstevel@tonic-gate  *      port_num     - The HCA port
15277c478bd9Sstevel@tonic-gate  *      pkey_ix      - The input PKey index, whose PKey we are interested in.
15287c478bd9Sstevel@tonic-gate  * Output:
15297c478bd9Sstevel@tonic-gate  *      pkey         - The returned PKey value, for the specified index.
15307c478bd9Sstevel@tonic-gate  * Returns:
15317c478bd9Sstevel@tonic-gate  *      IBT_SUCCESS/IBT_PKEY_IX_ILLEGAL/IBT_PKEY_IX_INVALID/
15327c478bd9Sstevel@tonic-gate  *	IBT_HCA_PORT_INVALID/IBT_HCA_INVALID
15337c478bd9Sstevel@tonic-gate  * Description:
15347c478bd9Sstevel@tonic-gate  *      Returns the PKey Index for the specified PKey, the device as specified
15357c478bd9Sstevel@tonic-gate  *      by HCA GUID Info.
15367c478bd9Sstevel@tonic-gate  */
15377c478bd9Sstevel@tonic-gate ibt_status_t
ibt_index2pkey_byguid(ib_guid_t hca_guid,uint8_t port_num,uint16_t pkey_ix,ib_pkey_t * pkey)15387c478bd9Sstevel@tonic-gate ibt_index2pkey_byguid(ib_guid_t hca_guid, uint8_t port_num, uint16_t pkey_ix,
15397c478bd9Sstevel@tonic-gate     ib_pkey_t *pkey)
15407c478bd9Sstevel@tonic-gate {
15417c478bd9Sstevel@tonic-gate 	ibt_status_t		retval;
15427c478bd9Sstevel@tonic-gate 	ibtl_hca_devinfo_t	*hca_devp;	/* HCA Dev Info */
15437c478bd9Sstevel@tonic-gate 
15447c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L3(ibtf_hca, "ibt_index2pkey_byguid(%llX, %d, %d)",
15457c478bd9Sstevel@tonic-gate 	    hca_guid, port_num, pkey_ix);
15467c478bd9Sstevel@tonic-gate 
15477c478bd9Sstevel@tonic-gate 	mutex_enter(&ibtl_clnt_list_mutex);
15487c478bd9Sstevel@tonic-gate 	hca_devp = ibtl_get_hcadevinfo(hca_guid);
15497c478bd9Sstevel@tonic-gate 	if (hca_devp == NULL) {
15507c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L2(ibtf_hca, "ibt_index2pkey_byguid: "
15517c478bd9Sstevel@tonic-gate 		    "Invalid HCA GUID 0x%llx", hca_guid);
15527c478bd9Sstevel@tonic-gate 		mutex_exit(&ibtl_clnt_list_mutex);
15537c478bd9Sstevel@tonic-gate 		return (IBT_HCA_INVALID);
15547c478bd9Sstevel@tonic-gate 	}
15557c478bd9Sstevel@tonic-gate 	retval = ibtl_index2pkey(hca_devp, port_num, pkey_ix, pkey);
15567c478bd9Sstevel@tonic-gate 	mutex_exit(&ibtl_clnt_list_mutex);
15577c478bd9Sstevel@tonic-gate 
15587c478bd9Sstevel@tonic-gate 	return (retval);
15597c478bd9Sstevel@tonic-gate }
15607c478bd9Sstevel@tonic-gate 
15617c478bd9Sstevel@tonic-gate 
15627c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("client managed", ibtl_hca_s::ha_clnt_private))
15637c478bd9Sstevel@tonic-gate 
15647c478bd9Sstevel@tonic-gate /*
15657c478bd9Sstevel@tonic-gate  * Function:
15667c478bd9Sstevel@tonic-gate  *      ibt_set_hca_private
15677c478bd9Sstevel@tonic-gate  * Input:
15687c478bd9Sstevel@tonic-gate  *      hca_hdl		The ibt_hca_hdl_t of the opened HCA.
15697c478bd9Sstevel@tonic-gate  *      clnt_private	The client private data.
15707c478bd9Sstevel@tonic-gate  * Output:
15717c478bd9Sstevel@tonic-gate  *	none.
15727c478bd9Sstevel@tonic-gate  * Returns:
15737c478bd9Sstevel@tonic-gate  *      none
15747c478bd9Sstevel@tonic-gate  * Description:
15757c478bd9Sstevel@tonic-gate  *      Sets the client private data.
15767c478bd9Sstevel@tonic-gate  */
15777c478bd9Sstevel@tonic-gate void
ibt_set_hca_private(ibt_hca_hdl_t hca_hdl,void * clnt_private)15787c478bd9Sstevel@tonic-gate ibt_set_hca_private(ibt_hca_hdl_t hca_hdl, void *clnt_private)
15797c478bd9Sstevel@tonic-gate {
15807c478bd9Sstevel@tonic-gate 	hca_hdl->ha_clnt_private = clnt_private;
15817c478bd9Sstevel@tonic-gate }
15827c478bd9Sstevel@tonic-gate 
15837c478bd9Sstevel@tonic-gate 
15847c478bd9Sstevel@tonic-gate /*
15857c478bd9Sstevel@tonic-gate  * Function:
15867c478bd9Sstevel@tonic-gate  *      ibt_get_hca_private
15877c478bd9Sstevel@tonic-gate  * Input:
15887c478bd9Sstevel@tonic-gate  *      hca_hdl		The ibt_hca_hdl_t of the opened HCA.
15897c478bd9Sstevel@tonic-gate  * Output:
15907c478bd9Sstevel@tonic-gate  *      none
15917c478bd9Sstevel@tonic-gate  * Returns:
15927c478bd9Sstevel@tonic-gate  *      The client private data.
15937c478bd9Sstevel@tonic-gate  * Description:
15947c478bd9Sstevel@tonic-gate  *      Retrieves the private data from a specified HCA.
15957c478bd9Sstevel@tonic-gate  */
15967c478bd9Sstevel@tonic-gate void *
ibt_get_hca_private(ibt_hca_hdl_t hca_hdl)15977c478bd9Sstevel@tonic-gate ibt_get_hca_private(ibt_hca_hdl_t hca_hdl)
15987c478bd9Sstevel@tonic-gate {
15997c478bd9Sstevel@tonic-gate 	return (hca_hdl->ha_clnt_private);
16007c478bd9Sstevel@tonic-gate }
16017c478bd9Sstevel@tonic-gate 
16027c478bd9Sstevel@tonic-gate /*
16037c478bd9Sstevel@tonic-gate  * Function:
16047c478bd9Sstevel@tonic-gate  *	ibt_hca_handle_to_guid
16057c478bd9Sstevel@tonic-gate  * Input:
16067c478bd9Sstevel@tonic-gate  *	hca		HCA Handle.
16077c478bd9Sstevel@tonic-gate  * Output:
16087c478bd9Sstevel@tonic-gate  *	none.
16097c478bd9Sstevel@tonic-gate  * Returns:
16107c478bd9Sstevel@tonic-gate  *	hca_guid	Returned HCA GUID on which the specified Channel is
16117c478bd9Sstevel@tonic-gate  *			allocated. Valid if it is non-NULL on return.
16127c478bd9Sstevel@tonic-gate  * Description:
16137c478bd9Sstevel@tonic-gate  *	A helper function to retrieve HCA GUID for the specified handle.
16147c478bd9Sstevel@tonic-gate  */
16157c478bd9Sstevel@tonic-gate ib_guid_t
ibt_hca_handle_to_guid(ibt_hca_hdl_t hca)16167c478bd9Sstevel@tonic-gate ibt_hca_handle_to_guid(ibt_hca_hdl_t hca)
16177c478bd9Sstevel@tonic-gate {
16187c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L3(ibtf_hca, "ibt_hca_handle_to_guid(%p)", hca);
16197c478bd9Sstevel@tonic-gate 	return (IBTL_HCA2HCAGUID(hca));
16207c478bd9Sstevel@tonic-gate }
16217c478bd9Sstevel@tonic-gate 
16227c478bd9Sstevel@tonic-gate /*
16237c478bd9Sstevel@tonic-gate  * Function:
16247c478bd9Sstevel@tonic-gate  *	ibt_hca_guid_to_handle
16257c478bd9Sstevel@tonic-gate  * Input:
16267c478bd9Sstevel@tonic-gate  *	ibt_hdl		The handle returned to the client by the IBTF from
16277c478bd9Sstevel@tonic-gate  *                      an ibt_attach() call.
16287c478bd9Sstevel@tonic-gate  *	hca_guid	HCA GUID
16297c478bd9Sstevel@tonic-gate  * Output:
16307c478bd9Sstevel@tonic-gate  *	hca_hdl		Returned ibt_hca_hdl_t.
16317c478bd9Sstevel@tonic-gate  * Returns:
16327c478bd9Sstevel@tonic-gate  *      IBT_SUCCESS
16337c478bd9Sstevel@tonic-gate  *      IBT_HCA_INVALID
16347c478bd9Sstevel@tonic-gate  * Description:
16357c478bd9Sstevel@tonic-gate  *	A helper function to retrieve a hca handle from a HCA GUID.
16367c478bd9Sstevel@tonic-gate  */
16377c478bd9Sstevel@tonic-gate ibt_status_t
ibt_hca_guid_to_handle(ibt_clnt_hdl_t ibt_hdl,ib_guid_t hca_guid,ibt_hca_hdl_t * hca_hdl)16387c478bd9Sstevel@tonic-gate ibt_hca_guid_to_handle(ibt_clnt_hdl_t ibt_hdl, ib_guid_t hca_guid,
16397c478bd9Sstevel@tonic-gate     ibt_hca_hdl_t *hca_hdl)
16407c478bd9Sstevel@tonic-gate {
16417c478bd9Sstevel@tonic-gate 	ibtl_hca_t  		*hca_infop;
16427c478bd9Sstevel@tonic-gate 	ibtl_hca_devinfo_t	*hca_devp;		/* HCA Dev Info */
16437c478bd9Sstevel@tonic-gate 	ibt_status_t		rval = IBT_HCA_INVALID;
16447c478bd9Sstevel@tonic-gate 
16457c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L3(ibtf_hca, "ibt_hca_guid_to_handle(%p, %llX)",
16467c478bd9Sstevel@tonic-gate 	    ibt_hdl, hca_guid);
16477c478bd9Sstevel@tonic-gate 
16487c478bd9Sstevel@tonic-gate 	mutex_enter(&ibtl_clnt_list_mutex);
16497c478bd9Sstevel@tonic-gate 
16507c478bd9Sstevel@tonic-gate 	/*
16517c478bd9Sstevel@tonic-gate 	 * Get HCA Device Info Structure, referenced by HCA GUID.
16527c478bd9Sstevel@tonic-gate 	 */
16537c478bd9Sstevel@tonic-gate 	hca_devp = ibtl_get_hcadevinfo(hca_guid);
16547c478bd9Sstevel@tonic-gate 	if (hca_devp == NULL) {
16557c478bd9Sstevel@tonic-gate 		/*
16567c478bd9Sstevel@tonic-gate 		 * If we are here, then the requested HCA device is not present.
16577c478bd9Sstevel@tonic-gate 		 * Return the status as Invalid HCA GUID.
16587c478bd9Sstevel@tonic-gate 		 */
16597c478bd9Sstevel@tonic-gate 		mutex_exit(&ibtl_clnt_list_mutex);
16607c478bd9Sstevel@tonic-gate 
16617c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L2(ibtf_hca, "ibt_hca_guid_to_handle: "
16627c478bd9Sstevel@tonic-gate 		    "HCA Device Not Found: Invalid HCA GUID");
16637c478bd9Sstevel@tonic-gate 
16647c478bd9Sstevel@tonic-gate 		*hca_hdl = NULL;
16657c478bd9Sstevel@tonic-gate 		return (rval);
16667c478bd9Sstevel@tonic-gate 	}
16677c478bd9Sstevel@tonic-gate 
16687c478bd9Sstevel@tonic-gate 	/*
16697c478bd9Sstevel@tonic-gate 	 * Yes, we found a HCA Device registered with IBTF, which matches with
16707c478bd9Sstevel@tonic-gate 	 * the requested HCA_GUID.
16717c478bd9Sstevel@tonic-gate 	 */
16727c478bd9Sstevel@tonic-gate 	hca_infop = hca_devp->hd_clnt_list;
16737c478bd9Sstevel@tonic-gate 
16747c478bd9Sstevel@tonic-gate 	while (hca_infop != NULL) {
16757c478bd9Sstevel@tonic-gate 		if (ibt_hdl == hca_infop->ha_clnt_devp) {
16767c478bd9Sstevel@tonic-gate 			rval = IBT_SUCCESS;
16777c478bd9Sstevel@tonic-gate 			break;
16787c478bd9Sstevel@tonic-gate 		}
16797c478bd9Sstevel@tonic-gate 		hca_infop = hca_infop->ha_clnt_link;
16807c478bd9Sstevel@tonic-gate 	}
16817c478bd9Sstevel@tonic-gate 
16827c478bd9Sstevel@tonic-gate 	mutex_exit(&ibtl_clnt_list_mutex);
16837c478bd9Sstevel@tonic-gate 	*hca_hdl = hca_infop;
16847c478bd9Sstevel@tonic-gate 	return (rval);
16857c478bd9Sstevel@tonic-gate }
1686