Blame libvendor/osm_vendor_mtl_hca_guid.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
#if defined(OSM_VENDOR_INTF_MTL) | defined(OSM_VENDOR_INTF_TS)
Packit 13e616
#undef IN
Packit 13e616
#undef OUT
Packit 13e616
#include <stdlib.h>
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 <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
/**********************************************************************
Packit 13e616
 * Convert the given GID to GUID by copy of it's upper 8 bytes
Packit 13e616
 *
Packit 13e616
 *
Packit 13e616
 **********************************************************************/
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
/****f* OpenSM: CA Info/osm_ca_info_get_pi_ptr
Packit 13e616
 * NAME
Packit 13e616
 * osm_ca_info_get_pi_ptr
Packit 13e616
 *
Packit 13e616
 * DESCRIPTION
Packit 13e616
 * Returns a pointer to the port attribute of the specified port
Packit 13e616
 * owned by this CA.
Packit 13e616
 *
Packit 13e616
 * SYNOPSIS
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
 * PARAMETERS
Packit 13e616
 * p_ca_info
Packit 13e616
 *    [in] Pointer to a CA Info object.
Packit 13e616
 *
Packit 13e616
 * index
Packit 13e616
 *    [in] Port "index" for which to retrieve the port attribute.
Packit 13e616
 *    The index is the offset into the ca's internal array
Packit 13e616
 *    of port attributes.
Packit 13e616
 *
Packit 13e616
 * RETURN VALUE
Packit 13e616
 * Returns a pointer to the port attribute of the specified port
Packit 13e616
 * owned by this CA.
Packit 13e616
 *
Packit 13e616
 * NOTES
Packit 13e616
 *
Packit 13e616
 * SEE ALSO
Packit 13e616
 *********/
Packit 13e616
Packit 13e616
/********************************************************************************
Packit 13e616
 * get the CA names ava`ilable 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 7101: "
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 7102: "
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 7103: "
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 7104: "
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 7105: "
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 7106: "
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 7107: "
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 7108: "
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)
Packit 13e616
{
Packit 13e616
	OSM_LOG_ENTER(p_vend->p_log);
Packit 13e616
Packit 13e616
	if (p_ca_info->p_attr) {
Packit 13e616
		if (p_ca_info->p_attr->num_ports) {
Packit 13e616
			free(p_ca_info->p_attr->p_port_attr);
Packit 13e616
		}
Packit 13e616
		free(p_ca_info->p_attr);
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;
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_info;
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_all_port_attr: ERR 7109: "
Packit 13e616
			"Fail to get CA Ids.\n");
Packit 13e616
		goto Exit;
Packit 13e616
	}
Packit 13e616
Packit 13e616
	/* we keep track of all the CAs in this info array */
Packit 13e616
	p_vend->p_ca_info = malloc(ca_count * sizeof(*p_vend->p_ca_info));
Packit 13e616
	if (p_vend->p_ca_info == NULL) {
Packit 13e616
		osm_log(p_vend->p_log, OSM_LOG_ERROR,
Packit 13e616
			"osm_vendor_get_all_port_attr: ERR 7110: "
Packit 13e616
			"Unable to allocate CA information array.\n");
Packit 13e616
		goto Exit;
Packit 13e616
	}
Packit 13e616
Packit 13e616
	memset(p_vend->p_ca_info, 0, ca_count * sizeof(*p_vend->p_ca_info));
Packit 13e616
	p_vend->ca_count = ca_count;
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
		p_ca_info = &p_vend->p_ca_info[ca];
Packit 13e616
Packit 13e616
		status = __osm_ca_info_init(p_vend, p_ca_ids[ca], p_ca_info);
Packit 13e616
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 7111: "
Packit 13e616
				"Unable to initialize CA Info object (%s).\n",
Packit 13e616
				ib_get_err_str(status));
Packit 13e616
		}
Packit 13e616
Packit 13e616
		total_ports += osm_ca_info_get_num_ports(p_ca_info);
Packit 13e616
Packit 13e616
		osm_log(p_vend->p_log, OSM_LOG_DEBUG,
Packit 13e616
			"osm_vendor_get_all_port_attr: "
Packit 13e616
			"osm_vendor_get_all_port_attr: %u got %u ports total:%u\n",
Packit 13e616
			ca, osm_ca_info_get_num_ports(p_ca_info), total_ports);
Packit 13e616
Packit 13e616
	}
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 (*p_num_ports >= total_ports) {
Packit 13e616
		for (ca = 0; ca < ca_count; ca++) {
Packit 13e616
			uint32_t num_ports;
Packit 13e616
Packit 13e616
			p_ca_info = &p_vend->p_ca_info[ca];
Packit 13e616
Packit 13e616
			num_ports = osm_ca_info_get_num_ports(p_ca_info);
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_info,
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
	*p_num_ports = total_ports;
Packit 13e616
Packit 13e616
	if (p_ca_ids)
Packit 13e616
		free(p_ca_ids);
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 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 7112: "
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 7113: "
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 7114: "
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 7115: "
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_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 7116: "
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
#ifdef __TEST_HCA_GUID__
Packit 13e616
Packit 13e616
#define GUID_ARRAY_SIZE 64
Packit 13e616
Packit 13e616
#include <stdio.h>
Packit 13e616
Packit 13e616
ib_net64_t get_port_guid()
Packit 13e616
{
Packit 13e616
	uint32_t i;
Packit 13e616
	uint32_t choice = 0;
Packit 13e616
	boolean_t done_flag = FALSE;
Packit 13e616
	ib_api_status_t status;
Packit 13e616
	uint32_t num_ports = GUID_ARRAY_SIZE;
Packit 13e616
	ib_port_attr_t attr_array[GUID_ARRAY_SIZE];
Packit 13e616
	VAPI_hca_id_t ca_id;
Packit 13e616
	uint32_t portNum;
Packit 13e616
	osm_vendor_t vend;
Packit 13e616
	osm_vendor_t *p_vend;
Packit 13e616
	osm_log_t *p_osm_log, tlog;
Packit 13e616
Packit 13e616
	p_osm_log = &tlog;
Packit 13e616
Packit 13e616
	status = osm_log_init(p_osm_log, FALSE);
Packit 13e616
	if (status != IB_SUCCESS)
Packit 13e616
		return (status);
Packit 13e616
Packit 13e616
	osm_log(p_osm_log, OSM_LOG_FUNCS, "get_port_guid: [\n");
Packit 13e616
Packit 13e616
	p_vend = &ven;;
Packit 13e616
	p_vend->p_log = p_osm_log;
Packit 13e616
Packit 13e616
	/*
Packit 13e616
	 * Call the transport layer for a list of local port
Packit 13e616
	 * GUID values.
Packit 13e616
	 */
Packit 13e616
	status = osm_vendor_get_all_port_attr(p_vend, attr_array, &num_ports);
Packit 13e616
	if (status != IB_SUCCESS) {
Packit 13e616
		printf("\nError from osm_opensm_init (%x)\n", status);
Packit 13e616
		return (0);
Packit 13e616
	}
Packit 13e616
Packit 13e616
	if (num_ports == 0) {
Packit 13e616
		printf("\nNo local ports detected!\n");
Packit 13e616
		return (0);
Packit 13e616
	}
Packit 13e616
Packit 13e616
	while (done_flag == FALSE) {
Packit 13e616
		printf("\nChoose a local port number with which to bind:\n\n");
Packit 13e616
		for (i = 0; i < num_ports; i++) {
Packit 13e616
			/*
Packit 13e616
			 * Print the index + 1 since by convention, port numbers
Packit 13e616
			 * start with 1 on host channel adapters.
Packit 13e616
			 */
Packit 13e616
Packit 13e616
			printf("\t%u: GUID = 0x%8" PRIx64
Packit 13e616
			       ", lid = 0x%04X, state = %s\n", i + 1,
Packit 13e616
			       cl_ntoh64(attr_array[i].port_guid),
Packit 13e616
			       cl_ntoh16(attr_array[i].lid),
Packit 13e616
			       ib_get_port_state_str(attr_array[i].link_state));
Packit 13e616
		}
Packit 13e616
Packit 13e616
		printf("\nEnter choice (1-%u): ", i);
Packit 13e616
		fflush(stdout);
Packit 13e616
		scanf("%u", &choice);
Packit 13e616
		if (choice > num_ports)
Packit 13e616
			printf("\nError: Lame choice!\n");
Packit 13e616
		else
Packit 13e616
			done_flag = TRUE;
Packit 13e616
	}
Packit 13e616
Packit 13e616
	status =
Packit 13e616
	    osm_vendor_get_guid_ca_and_port(p_vend,
Packit 13e616
					    attr_array[choice - 1].port_guid,
Packit 13e616
					    &ca_id, &portNum);
Packit 13e616
	if (status != IB_SUCCESS) {
Packit 13e616
		printf("Error obtaining back the HCA and Port\n");
Packit 13e616
		return (0);
Packit 13e616
	}
Packit 13e616
Packit 13e616
	printf("Selected: CA:%s Port:%d\n", ca_id, portNum);
Packit 13e616
Packit 13e616
	return (attr_array[choice - 1].port_guid);
Packit 13e616
}
Packit 13e616
Packit 13e616
int main(int argc, char **argv)
Packit 13e616
{
Packit 13e616
	get_port_guid();
Packit 13e616
	return (0);
Packit 13e616
}
Packit 13e616
Packit 13e616
#endif
Packit 13e616
Packit 13e616
#endif