Blame libvendor/osm_vendor_mlx_hca.c

Packit 13e616
/*
Packit 13e616
 * Copyright (c) 2004-2008 Voltaire, Inc. All rights reserved.
Packit 13e616
 * Copyright (c) 2002-2005 Mellanox Technologies LTD. All rights reserved.
Packit 13e616
 * Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
Packit 13e616
 *
Packit 13e616
 * This software is available to you under a choice of one of two
Packit 13e616
 * licenses.  You may choose to be licensed under the terms of the GNU
Packit 13e616
 * General Public License (GPL) Version 2, available from the file
Packit 13e616
 * COPYING in the main directory of this source tree, or the
Packit 13e616
 * OpenIB.org BSD license below:
Packit 13e616
 *
Packit 13e616
 *     Redistribution and use in source and binary forms, with or
Packit 13e616
 *     without modification, are permitted provided that the following
Packit 13e616
 *     conditions are met:
Packit 13e616
 *
Packit 13e616
 *      - Redistributions of source code must retain the above
Packit 13e616
 *        copyright notice, this list of conditions and the following
Packit 13e616
 *        disclaimer.
Packit 13e616
 *
Packit 13e616
 *      - Redistributions in binary form must reproduce the above
Packit 13e616
 *        copyright notice, this list of conditions and the following
Packit 13e616
 *        disclaimer in the documentation and/or other materials
Packit 13e616
 *        provided with the distribution.
Packit 13e616
 *
Packit 13e616
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Packit 13e616
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
Packit 13e616
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Packit 13e616
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
Packit 13e616
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
Packit 13e616
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
Packit 13e616
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
Packit 13e616
 * SOFTWARE.
Packit 13e616
 *
Packit 13e616
 */
Packit 13e616
Packit 13e616
#if HAVE_CONFIG_H
Packit 13e616
#  include <config.h>
Packit 13e616
#endif				/* HAVE_CONFIG_H */
Packit 13e616
Packit 13e616
#include <stdlib.h>
Packit 13e616
#include <string.h>
Packit 13e616
#if defined(OSM_VENDOR_INTF_MTL) | defined(OSM_VENDOR_INTF_TS)
Packit 13e616
#undef IN
Packit 13e616
#undef OUT
Packit 13e616
#include <vapi_types.h>
Packit 13e616
#include <evapi.h>
Packit 13e616
#include <vendor/osm_vendor_api.h>
Packit 13e616
#include <opensm/osm_log.h>
Packit 13e616
#include <stdlib.h>
Packit 13e616
#include <stdio.h>
Packit 13e616
Packit 13e616
/********************************************************************************
Packit 13e616
 *
Packit 13e616
 * Provide the functionality for selecting an HCA Port and Obtaining it's guid.
Packit 13e616
 *
Packit 13e616
 ********************************************************************************/
Packit 13e616
Packit 13e616
typedef struct _osm_ca_info {
Packit 13e616
	ib_net64_t guid;
Packit 13e616
	size_t attr_size;
Packit 13e616
	ib_ca_attr_t *p_attr;
Packit 13e616
} osm_ca_info_t;
Packit 13e616
Packit 13e616
/**********************************************************************
Packit 13e616
 * Convert the given GID to GUID by copy of it's upper 8 bytes
Packit 13e616
 **********************************************************************/
Packit 13e616
ib_api_status_t
Packit 13e616
__osm_vendor_gid_to_guid(IN u_int8_t * gid, OUT VAPI_gid_t * guid)
Packit 13e616
{
Packit 13e616
	memcpy(guid, gid + 8, 8);
Packit 13e616
	return (IB_SUCCESS);
Packit 13e616
}
Packit 13e616
Packit 13e616
/**********************************************************************
Packit 13e616
 * Returns a pointer to the port attribute of the specified port
Packit 13e616
 * owned by this CA.
Packit 13e616
 ************************************************************************/
Packit 13e616
static ib_port_attr_t *__osm_ca_info_get_port_attr_ptr(IN const osm_ca_info_t *
Packit 13e616
						       const p_ca_info,
Packit 13e616
						       IN const uint8_t index)
Packit 13e616
{
Packit 13e616
	return (&p_ca_info->p_attr->p_port_attr[index]);
Packit 13e616
}
Packit 13e616
Packit 13e616
/********************************************************************************
Packit 13e616
 * get the CA names available on the system
Packit 13e616
 * NOTE: user of this function needs to deallocate p_hca_ids after usage.
Packit 13e616
 ********************************************************************************/
Packit 13e616
static ib_api_status_t
Packit 13e616
__osm_vendor_get_ca_ids(IN osm_vendor_t * const p_vend,
Packit 13e616
			IN VAPI_hca_id_t ** const p_hca_ids,
Packit 13e616
			IN uint32_t * const p_num_guids)
Packit 13e616
{
Packit 13e616
	ib_api_status_t status;
Packit 13e616
	VAPI_ret_t vapi_res;
Packit 13e616
Packit 13e616
	OSM_LOG_ENTER(p_vend->p_log);
Packit 13e616
Packit 13e616
	CL_ASSERT(p_hca_ids);
Packit 13e616
	CL_ASSERT(p_num_guids);
Packit 13e616
Packit 13e616
	/* first call is just to get the number */
Packit 13e616
	vapi_res = EVAPI_list_hcas(0, p_num_guids, NULL);
Packit 13e616
Packit 13e616
	/* fail ? */
Packit 13e616
	if (vapi_res == VAPI_EINVAL_PARAM) {
Packit 13e616
		osm_log(p_vend->p_log, OSM_LOG_ERROR,
Packit 13e616
			"__osm_vendor_get_ca_ids: ERR 3D08: : "
Packit 13e616
			"Bad parameter in calling: EVAPI_list_hcas. (%d)\n",
Packit 13e616
			vapi_res);
Packit 13e616
		status = IB_ERROR;
Packit 13e616
		goto Exit;
Packit 13e616
	}
Packit 13e616
Packit 13e616
	/* NO HCA ? */
Packit 13e616
	if (*p_num_guids == 0) {
Packit 13e616
		osm_log(p_vend->p_log, OSM_LOG_ERROR,
Packit 13e616
			"__osm_vendor_get_ca_ids: ERR 3D09: "
Packit 13e616
			"No available channel adapters.\n");
Packit 13e616
		status = IB_INSUFFICIENT_RESOURCES;
Packit 13e616
		goto Exit;
Packit 13e616
	}
Packit 13e616
Packit 13e616
	/* allocate and really call - user of this function needs to deallocate it */
Packit 13e616
	*p_hca_ids =
Packit 13e616
	    (VAPI_hca_id_t *) malloc(*p_num_guids * sizeof(VAPI_hca_id_t));
Packit 13e616
Packit 13e616
	/* now call it really */
Packit 13e616
	vapi_res = EVAPI_list_hcas(*p_num_guids, p_num_guids, *p_hca_ids);
Packit 13e616
Packit 13e616
	/* too many ? */
Packit 13e616
	if (vapi_res == VAPI_EAGAIN) {
Packit 13e616
		osm_log(p_vend->p_log, OSM_LOG_ERROR,
Packit 13e616
			"__osm_vendor_get_ca_ids: ERR 3D10: "
Packit 13e616
			"More CA GUIDs than allocated array (%d).\n",
Packit 13e616
			*p_num_guids);
Packit 13e616
		status = IB_ERROR;
Packit 13e616
		goto Exit;
Packit 13e616
	}
Packit 13e616
Packit 13e616
	/* fail ? */
Packit 13e616
	if (vapi_res != VAPI_OK) {
Packit 13e616
		osm_log(p_vend->p_log, OSM_LOG_ERROR,
Packit 13e616
			"__osm_vendor_get_ca_ids: ERR 3D11: : "
Packit 13e616
			"Bad parameter in calling: EVAPI_list_hcas.\n");
Packit 13e616
		status = IB_ERROR;
Packit 13e616
		goto Exit;
Packit 13e616
	}
Packit 13e616
Packit 13e616
	if (osm_log_is_active(p_vend->p_log, OSM_LOG_DEBUG)) {
Packit 13e616
		osm_log(p_vend->p_log, OSM_LOG_DEBUG,
Packit 13e616
			"__osm_vendor_get_ca_ids: "
Packit 13e616
			"Detected %u local channel adapters.\n", *p_num_guids);
Packit 13e616
	}
Packit 13e616
Packit 13e616
	status = IB_SUCCESS;
Packit 13e616
Packit 13e616
Exit:
Packit 13e616
	OSM_LOG_EXIT(p_vend->p_log);
Packit 13e616
	return (status);
Packit 13e616
}
Packit 13e616
Packit 13e616
/**********************************************************************
Packit 13e616
 * Initialize an Info Struct for the Given HCA by its Id
Packit 13e616
 **********************************************************************/
Packit 13e616
static ib_api_status_t
Packit 13e616
__osm_ca_info_init(IN osm_vendor_t * const p_vend,
Packit 13e616
		   IN VAPI_hca_id_t ca_id, OUT osm_ca_info_t * const p_ca_info)
Packit 13e616
{
Packit 13e616
	ib_api_status_t status = IB_ERROR;
Packit 13e616
	VAPI_ret_t vapi_res;
Packit 13e616
	VAPI_hca_hndl_t hca_hndl;
Packit 13e616
	VAPI_hca_vendor_t hca_vendor;
Packit 13e616
	VAPI_hca_cap_t hca_cap;
Packit 13e616
	VAPI_hca_port_t hca_port;
Packit 13e616
	uint8_t port_num;
Packit 13e616
	IB_gid_t *p_port_gid;
Packit 13e616
	uint16_t maxNumGids;
Packit 13e616
Packit 13e616
	OSM_LOG_ENTER(p_vend->p_log);
Packit 13e616
Packit 13e616
	/* get the HCA handle */
Packit 13e616
	vapi_res = EVAPI_get_hca_hndl(ca_id, &hca_hndl);
Packit 13e616
	if (vapi_res != VAPI_OK) {
Packit 13e616
		osm_log(p_vend->p_log, OSM_LOG_ERROR,
Packit 13e616
			"__osm_ca_info_init: ERR 3D05: "
Packit 13e616
			"Fail to get HCA handle (%u).\n", vapi_res);
Packit 13e616
		goto Exit;
Packit 13e616
	}
Packit 13e616
Packit 13e616
	if (osm_log_is_active(p_vend->p_log, OSM_LOG_DEBUG)) {
Packit 13e616
		osm_log(p_vend->p_log, OSM_LOG_DEBUG,
Packit 13e616
			"__osm_ca_info_init: " "Querying CA %s.\n", ca_id);
Packit 13e616
	}
Packit 13e616
Packit 13e616
	/* query and get the HCA capability */
Packit 13e616
	vapi_res = VAPI_query_hca_cap(hca_hndl, &hca_vendor, &hca_cap);
Packit 13e616
	if (vapi_res != VAPI_OK) {
Packit 13e616
		osm_log(p_vend->p_log, OSM_LOG_ERROR,
Packit 13e616
			"__osm_ca_info_init: ERR 3D06: "
Packit 13e616
			"Fail to get HCA Capabilities (%u).\n", vapi_res);
Packit 13e616
		goto Exit;
Packit 13e616
	}
Packit 13e616
Packit 13e616
	/* get the guid of the HCA */
Packit 13e616
	memcpy(&(p_ca_info->guid), hca_cap.node_guid, 8 * sizeof(u_int8_t));
Packit 13e616
	p_ca_info->attr_size = 1;
Packit 13e616
	p_ca_info->p_attr = (ib_ca_attr_t *) malloc(sizeof(ib_ca_attr_t));
Packit 13e616
	memcpy(&(p_ca_info->p_attr->ca_guid), hca_cap.node_guid,
Packit 13e616
	       8 * sizeof(u_int8_t));
Packit 13e616
Packit 13e616
	/* now obtain the attributes of the ports */
Packit 13e616
	p_ca_info->p_attr->num_ports = hca_cap.phys_port_num;
Packit 13e616
	p_ca_info->p_attr->p_port_attr =
Packit 13e616
	    (ib_port_attr_t *) malloc(hca_cap.phys_port_num *
Packit 13e616
				      sizeof(ib_port_attr_t));
Packit 13e616
Packit 13e616
	for (port_num = 0; port_num < p_ca_info->p_attr->num_ports; port_num++) {
Packit 13e616
Packit 13e616
		/* query the port attributes */
Packit 13e616
		vapi_res =
Packit 13e616
		    VAPI_query_hca_port_prop(hca_hndl, port_num + 1, &hca_port);
Packit 13e616
		if (vapi_res != VAPI_OK) {
Packit 13e616
			osm_log(p_vend->p_log, OSM_LOG_ERROR,
Packit 13e616
				"__osm_ca_info_init: ERR 3D07: "
Packit 13e616
				"Fail to get HCA Port Attributes (%d).\n",
Packit 13e616
				vapi_res);
Packit 13e616
			goto Exit;
Packit 13e616
		}
Packit 13e616
Packit 13e616
		/* first call to know the size of the gid table */
Packit 13e616
		vapi_res =
Packit 13e616
		    VAPI_query_hca_gid_tbl(hca_hndl, port_num + 1, 0,
Packit 13e616
					   &maxNumGids, NULL);
Packit 13e616
		p_port_gid = (IB_gid_t *) malloc(maxNumGids * sizeof(IB_gid_t));
Packit 13e616
Packit 13e616
		vapi_res =
Packit 13e616
		    VAPI_query_hca_gid_tbl(hca_hndl, port_num + 1, maxNumGids,
Packit 13e616
					   &maxNumGids, p_port_gid);
Packit 13e616
		if (vapi_res != VAPI_OK) {
Packit 13e616
			osm_log(p_vend->p_log, OSM_LOG_ERROR,
Packit 13e616
				"__osm_ca_info_init: ERR 3D12: "
Packit 13e616
				"Fail to get HCA Port GID (%d).\n", vapi_res);
Packit 13e616
			goto Exit;
Packit 13e616
		}
Packit 13e616
Packit 13e616
		__osm_vendor_gid_to_guid(p_port_gid[0],
Packit 13e616
					 (IB_gid_t *) & p_ca_info->p_attr->
Packit 13e616
					 p_port_attr[port_num].port_guid);
Packit 13e616
		p_ca_info->p_attr->p_port_attr[port_num].lid = hca_port.lid;
Packit 13e616
		p_ca_info->p_attr->p_port_attr[port_num].link_state =
Packit 13e616
		    hca_port.state;
Packit 13e616
		p_ca_info->p_attr->p_port_attr[port_num].sm_lid =
Packit 13e616
		    hca_port.sm_lid;
Packit 13e616
Packit 13e616
		free(p_port_gid);
Packit 13e616
	}
Packit 13e616
Packit 13e616
	status = IB_SUCCESS;
Packit 13e616
Exit:
Packit 13e616
	OSM_LOG_EXIT(p_vend->p_log);
Packit 13e616
	return (status);
Packit 13e616
}
Packit 13e616
Packit 13e616
void
Packit 13e616
osm_ca_info_destroy(IN osm_vendor_t * const p_vend,
Packit 13e616
		    IN osm_ca_info_t * const p_ca_info, IN uint8_t num_ca)
Packit 13e616
{
Packit 13e616
	osm_ca_info_t *p_ca;
Packit 13e616
	uint8_t i;
Packit 13e616
Packit 13e616
	OSM_LOG_ENTER(p_vend->p_log);
Packit 13e616
Packit 13e616
	for (i = 0; i < num_ca; i++) {
Packit 13e616
		p_ca = &p_ca_info[i];
Packit 13e616
Packit 13e616
		if (NULL != p_ca->p_attr) {
Packit 13e616
			if (0 != p_ca->p_attr->num_ports) {
Packit 13e616
				free(p_ca->p_attr->p_port_attr);
Packit 13e616
			}
Packit 13e616
Packit 13e616
			free(p_ca->p_attr);
Packit 13e616
		}
Packit 13e616
	}
Packit 13e616
Packit 13e616
	free(p_ca_info);
Packit 13e616
Packit 13e616
	OSM_LOG_EXIT(p_vend->p_log);
Packit 13e616
}
Packit 13e616
Packit 13e616
/**********************************************************************
Packit 13e616
 * Fill in the array of port_attr with all available ports on ALL the
Packit 13e616
 * avilable CAs on this machine.
Packit 13e616
 * ALSO -
Packit 13e616
 * Update the vendor object list of ca_info structs
Packit 13e616
 **********************************************************************/
Packit 13e616
ib_api_status_t
Packit 13e616
osm_vendor_get_all_port_attr(IN osm_vendor_t * const p_vend,
Packit 13e616
			     IN ib_port_attr_t * const p_attr_array,
Packit 13e616
			     IN uint32_t * const p_num_ports)
Packit 13e616
{
Packit 13e616
	ib_api_status_t status;
Packit 13e616
Packit 13e616
	uint32_t ca;
Packit 13e616
	uint32_t ca_count = 0;
Packit 13e616
	uint32_t port_count = 0;
Packit 13e616
	uint8_t port_num;
Packit 13e616
	uint32_t total_ports = 0;
Packit 13e616
	VAPI_hca_id_t *p_ca_ids = NULL;
Packit 13e616
	osm_ca_info_t *p_ca_infos = NULL;
Packit 13e616
	uint32_t attr_array_sz = *p_num_ports;
Packit 13e616
Packit 13e616
	OSM_LOG_ENTER(p_vend->p_log);
Packit 13e616
Packit 13e616
	CL_ASSERT(p_vend);
Packit 13e616
Packit 13e616
	/* determine the number of CA's */
Packit 13e616
	status = __osm_vendor_get_ca_ids(p_vend, &p_ca_ids, &ca_count);
Packit 13e616
	if (status != IB_SUCCESS) {
Packit 13e616
		osm_log(p_vend->p_log, OSM_LOG_ERROR,
Packit 13e616
			"osm_vendor_get_all_port_attr: ERR 3D13: "
Packit 13e616
			"Fail to get CA Ids.\n");
Packit 13e616
		goto Exit;
Packit 13e616
	}
Packit 13e616
Packit 13e616
	/* Allocate an array big enough to hold the ca info objects */
Packit 13e616
	p_ca_infos = malloc(ca_count * sizeof(osm_ca_info_t));
Packit 13e616
	if (p_ca_infos == NULL) {
Packit 13e616
		osm_log(p_vend->p_log, OSM_LOG_ERROR,
Packit 13e616
			"osm_vendor_get_all_port_attr: ERR 3D14: "
Packit 13e616
			"Unable to allocate CA information array.\n");
Packit 13e616
		goto Exit;
Packit 13e616
	}
Packit 13e616
Packit 13e616
	memset(p_ca_infos, 0, ca_count * sizeof(osm_ca_info_t));
Packit 13e616
Packit 13e616
	/*
Packit 13e616
	 * For each CA, retrieve the CA info attributes
Packit 13e616
	 */
Packit 13e616
	for (ca = 0; ca < ca_count; ca++) {
Packit 13e616
		status =
Packit 13e616
		    __osm_ca_info_init(p_vend, p_ca_ids[ca], &p_ca_infos[ca]);
Packit 13e616
		if (status != IB_SUCCESS) {
Packit 13e616
			osm_log(p_vend->p_log, OSM_LOG_ERROR,
Packit 13e616
				"osm_vendor_get_all_port_attr: ERR 3D15: "
Packit 13e616
				"Unable to initialize CA Info object (%s).\n",
Packit 13e616
				ib_get_err_str(status));
Packit 13e616
			goto Exit;
Packit 13e616
		}
Packit 13e616
		total_ports += p_ca_infos[ca].p_attr->num_ports;
Packit 13e616
	}
Packit 13e616
Packit 13e616
	*p_num_ports = total_ports;
Packit 13e616
	osm_log(p_vend->p_log, OSM_LOG_DEBUG,
Packit 13e616
		"osm_vendor_get_all_port_attr: total ports:%u \n", total_ports);
Packit 13e616
Packit 13e616
	/*
Packit 13e616
	 * If the user supplied enough storage, return the port guids,
Packit 13e616
	 * otherwise, return the appropriate error.
Packit 13e616
	 */
Packit 13e616
	if (attr_array_sz >= total_ports) {
Packit 13e616
		for (ca = 0; ca < ca_count; ca++) {
Packit 13e616
			uint32_t num_ports;
Packit 13e616
Packit 13e616
			num_ports = p_ca_infos[ca].p_attr->num_ports;
Packit 13e616
Packit 13e616
			for (port_num = 0; port_num < num_ports; port_num++) {
Packit 13e616
				p_attr_array[port_count] =
Packit 13e616
				    *__osm_ca_info_get_port_attr_ptr(&p_ca_infos
Packit 13e616
								     [ca],
Packit 13e616
								     port_num);
Packit 13e616
				port_count++;
Packit 13e616
			}
Packit 13e616
		}
Packit 13e616
	} else {
Packit 13e616
		status = IB_INSUFFICIENT_MEMORY;
Packit 13e616
		goto Exit;
Packit 13e616
	}
Packit 13e616
Packit 13e616
	status = IB_SUCCESS;
Packit 13e616
Packit 13e616
Exit:
Packit 13e616
	if (p_ca_ids)
Packit 13e616
		free(p_ca_ids);
Packit 13e616
Packit 13e616
	if (p_ca_infos) {
Packit 13e616
		osm_ca_info_destroy(p_vend, p_ca_infos, ca_count);
Packit 13e616
	}
Packit 13e616
Packit 13e616
	OSM_LOG_EXIT(p_vend->p_log);
Packit 13e616
	return (status);
Packit 13e616
}
Packit 13e616
Packit 13e616
/**********************************************************************
Packit 13e616
 * Given the vendor obj and a guid
Packit 13e616
 * return the ca id and port number that have that guid
Packit 13e616
 **********************************************************************/
Packit 13e616
Packit 13e616
ib_api_status_t
Packit 13e616
osm_vendor_get_guid_ca_and_port(IN osm_vendor_t * const p_vend,
Packit 13e616
				IN ib_net64_t const guid,
Packit 13e616
				OUT VAPI_hca_hndl_t * p_hca_hndl,
Packit 13e616
				OUT VAPI_hca_id_t * p_hca_id,
Packit 13e616
				OUT uint8_t * p_hca_idx,
Packit 13e616
				OUT uint32_t * p_port_num)
Packit 13e616
{
Packit 13e616
Packit 13e616
	ib_api_status_t status;
Packit 13e616
	VAPI_hca_id_t *p_ca_ids = NULL;
Packit 13e616
	VAPI_ret_t vapi_res;
Packit 13e616
	VAPI_hca_hndl_t hca_hndl;
Packit 13e616
	VAPI_hca_vendor_t hca_vendor;
Packit 13e616
	VAPI_hca_cap_t hca_cap;
Packit 13e616
	IB_gid_t *p_port_gid = NULL;
Packit 13e616
	uint16_t maxNumGids;
Packit 13e616
	ib_net64_t port_guid;
Packit 13e616
	uint32_t ca, portIdx, ca_count;
Packit 13e616
Packit 13e616
	OSM_LOG_ENTER(p_vend->p_log);
Packit 13e616
Packit 13e616
	CL_ASSERT(p_vend);
Packit 13e616
Packit 13e616
	/*
Packit 13e616
	 * 1) Determine the number of CA's
Packit 13e616
	 * 2) Allocate an array big enough to hold the ca info objects.
Packit 13e616
	 * 3) Call again to retrieve the guids.
Packit 13e616
	 */
Packit 13e616
	status = __osm_vendor_get_ca_ids(p_vend, &p_ca_ids, &ca_count);
Packit 13e616
	if (status != IB_SUCCESS) {
Packit 13e616
		osm_log(p_vend->p_log, OSM_LOG_ERROR,
Packit 13e616
			"osm_vendor_get_guid_ca_and_port: ERR 3D16: "
Packit 13e616
			"Fail to get CA Ids.\n");
Packit 13e616
		goto Exit;
Packit 13e616
	}
Packit 13e616
Packit 13e616
	/*
Packit 13e616
	 * For each CA, retrieve the CA info attributes
Packit 13e616
	 */
Packit 13e616
	for (ca = 0; ca < ca_count; ca++) {
Packit 13e616
		/* get the HCA handle */
Packit 13e616
		vapi_res = EVAPI_get_hca_hndl(p_ca_ids[ca], &hca_hndl);
Packit 13e616
		if (vapi_res != VAPI_OK) {
Packit 13e616
			osm_log(p_vend->p_log, OSM_LOG_ERROR,
Packit 13e616
				"osm_vendor_get_guid_ca_and_port: ERR 3D17: "
Packit 13e616
				"Fail to get HCA handle (%u).\n", vapi_res);
Packit 13e616
			goto Exit;
Packit 13e616
		}
Packit 13e616
Packit 13e616
		/* get the CA attributes - to know how many ports it has: */
Packit 13e616
		if (osm_log_is_active(p_vend->p_log, OSM_LOG_DEBUG)) {
Packit 13e616
			osm_log(p_vend->p_log, OSM_LOG_DEBUG,
Packit 13e616
				"osm_vendor_get_guid_ca_and_port: "
Packit 13e616
				"Querying CA %s.\n", p_ca_ids[ca]);
Packit 13e616
		}
Packit 13e616
Packit 13e616
		/* query and get the HCA capability */
Packit 13e616
		vapi_res = VAPI_query_hca_cap(hca_hndl, &hca_vendor, &hca_cap);
Packit 13e616
		if (vapi_res != VAPI_OK) {
Packit 13e616
			osm_log(p_vend->p_log, OSM_LOG_ERROR,
Packit 13e616
				"osm_vendor_get_guid_ca_and_port: ERR 3D18: "
Packit 13e616
				"Fail to get HCA Capabilities (%u).\n",
Packit 13e616
				vapi_res);
Packit 13e616
			goto Exit;
Packit 13e616
		}
Packit 13e616
Packit 13e616
		/* go over all ports - to obtail their guids */
Packit 13e616
		for (portIdx = 0; portIdx < hca_cap.phys_port_num; portIdx++) {
Packit 13e616
			vapi_res =
Packit 13e616
			    VAPI_query_hca_gid_tbl(hca_hndl, portIdx + 1, 0,
Packit 13e616
						   &maxNumGids, NULL);
Packit 13e616
			p_port_gid =
Packit 13e616
			    (IB_gid_t *) malloc(maxNumGids * sizeof(IB_gid_t));
Packit 13e616
Packit 13e616
			/* get the port guid */
Packit 13e616
			vapi_res =
Packit 13e616
			    VAPI_query_hca_gid_tbl(hca_hndl, portIdx + 1,
Packit 13e616
						   maxNumGids, &maxNumGids,
Packit 13e616
						   p_port_gid);
Packit 13e616
			if (vapi_res != VAPI_OK) {
Packit 13e616
				osm_log(p_vend->p_log, OSM_LOG_ERROR,
Packit 13e616
					"osm_vendor_get_guid_ca_and_port: ERR 3D19: "
Packit 13e616
					"Fail to get HCA Port GID (%d).\n",
Packit 13e616
					vapi_res);
Packit 13e616
				goto Exit;
Packit 13e616
			}
Packit 13e616
Packit 13e616
			/* convert to SF style */
Packit 13e616
			__osm_vendor_gid_to_guid(p_port_gid[0],
Packit 13e616
						 (VAPI_gid_t *) & port_guid);
Packit 13e616
Packit 13e616
			/* finally did we find it ? */
Packit 13e616
			if (port_guid == guid) {
Packit 13e616
				*p_hca_hndl = hca_hndl;
Packit 13e616
				memcpy(p_hca_id, p_ca_ids[ca],
Packit 13e616
				       sizeof(VAPI_hca_id_t));
Packit 13e616
				*p_hca_idx = ca;
Packit 13e616
				*p_port_num = portIdx + 1;
Packit 13e616
				status = IB_SUCCESS;
Packit 13e616
				goto Exit;
Packit 13e616
			}
Packit 13e616
Packit 13e616
			free(p_port_gid);
Packit 13e616
			p_port_gid = NULL;
Packit 13e616
		}		/*  ALL PORTS  */
Packit 13e616
	}			/*  all HCAs */
Packit 13e616
Packit 13e616
	osm_log(p_vend->p_log, OSM_LOG_ERROR,
Packit 13e616
		"osm_vendor_get_guid_ca_and_port: ERR 3D20: "
Packit 13e616
		"Fail to find HCA and Port for Port Guid 0x%" PRIx64 "\n",
Packit 13e616
		cl_ntoh64(guid));
Packit 13e616
	status = IB_INVALID_GUID;
Packit 13e616
Packit 13e616
Exit:
Packit 13e616
	if (p_ca_ids != NULL)
Packit 13e616
		free(p_ca_ids);
Packit 13e616
	if (p_port_gid != NULL)
Packit 13e616
		free(p_port_gid);
Packit 13e616
	OSM_LOG_EXIT(p_vend->p_log);
Packit 13e616
	return (status);
Packit 13e616
}
Packit 13e616
Packit 13e616
#endif