Blame libvendor/osm_vendor_mlx_hca_anafa.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_ANAFA)
Packit 13e616
#undef IN
Packit 13e616
#undef OUT
Packit 13e616
Packit 13e616
#include <stdlib.h>
Packit 13e616
#include <stddef.h>
Packit 13e616
#include <string.h>
Packit 13e616
Packit 13e616
#include <vendor/osm_vendor_api.h>
Packit 13e616
#include <opensm/osm_log.h>
Packit 13e616
#include <sys/ioctl.h>
Packit 13e616
Packit 13e616
#include <vendor/osm_vendor_mlx_transport_anafa.h>
Packit 13e616
#include <vendor/osm_ts_useraccess.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 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 tTS_IB_GID gid, OUT ib_net64_t * p_guid)
Packit 13e616
{
Packit 13e616
	memcpy(p_guid, gid + 8, 8);
Packit 13e616
	return (IB_SUCCESS);
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
		   OUT osm_ca_info_t * const p_ca_info)
Packit 13e616
{
Packit 13e616
	ib_api_status_t status = IB_ERROR;
Packit 13e616
	int ioctl_ret = 0;
Packit 13e616
	osmv_TOPSPIN_ANAFA_transport_info_t *p_tpot_info =
Packit 13e616
	    p_vend->p_transport_info;
Packit 13e616
	osm_ts_gid_entry_ioctl gid_ioctl;
Packit 13e616
	osm_ts_get_port_info_ioctl port_info;
Packit 13e616
	struct ib_get_dev_info_ioctl dev_info;
Packit 13e616
Packit 13e616
	OSM_LOG_ENTER(p_vend->p_log);
Packit 13e616
Packit 13e616
	/* query HCA guid */
Packit 13e616
	ioctl_ret = ioctl(p_tpot_info->device_fd, TS_IB_IOCGDEVINFO, &dev_info);
Packit 13e616
	if (ioctl_ret != 0) {
Packit 13e616
		osm_log(p_vend->p_log, OSM_LOG_ERROR,
Packit 13e616
			"__osm_ca_info_init: ERR 7001: "
Packit 13e616
			"Fail to get HCA Capabilities (%d).\n", ioctl_ret);
Packit 13e616
		goto Exit;
Packit 13e616
	}
Packit 13e616
Packit 13e616
	memcpy(&(p_ca_info->attr.ca_guid), dev_info.dev_info.node_guid,
Packit 13e616
	       8 * sizeof(uint8_t));
Packit 13e616
Packit 13e616
/* now obtain the attributes of the ports - on our case port 1*/
Packit 13e616
Packit 13e616
	p_ca_info->attr.num_ports = 1;
Packit 13e616
	p_ca_info->attr.p_port_attr =
Packit 13e616
	    (ib_port_attr_t *) malloc(1 * sizeof(ib_port_attr_t));
Packit 13e616
Packit 13e616
	port_info.port = 1;
Packit 13e616
	ioctl_ret =
Packit 13e616
	    ioctl(p_tpot_info->device_fd, TS_IB_IOCGPORTINFO, &port_info);
Packit 13e616
	if (ioctl_ret) {
Packit 13e616
		osm_log(p_vend->p_log, OSM_LOG_ERROR,
Packit 13e616
			"__osm_ca_info_init: ERR 7002: "
Packit 13e616
			"Fail to get HCA Port Attributes (%d).\n", ioctl_ret);
Packit 13e616
		goto Exit;
Packit 13e616
	}
Packit 13e616
Packit 13e616
	gid_ioctl.port = 1;
Packit 13e616
	gid_ioctl.index = 0;
Packit 13e616
	ioctl_ret =
Packit 13e616
	    ioctl(p_tpot_info->device_fd, TS_IB_IOCGGIDENTRY, &gid_ioctl);
Packit 13e616
	if (ioctl_ret) {
Packit 13e616
		osm_log(p_vend->p_log, OSM_LOG_ERROR,
Packit 13e616
			"__osm_ca_info_init: ERR 7003: "
Packit 13e616
			"Fail to get HCA Port GID (%d).\n", ioctl_ret);
Packit 13e616
		goto Exit;
Packit 13e616
	}
Packit 13e616
Packit 13e616
	__osm_vendor_gid_to_guid(gid_ioctl.gid_entry,
Packit 13e616
				 &(p_ca_info->attr.p_port_attr[0].port_guid));
Packit 13e616
	p_ca_info->attr.p_port_attr[0].lid = port_info.port_info.lid;
Packit 13e616
	p_ca_info->attr.p_port_attr[0].link_state =
Packit 13e616
	    port_info.port_info.port_state;
Packit 13e616
	p_ca_info->attr.p_port_attr[0].sm_lid = port_info.port_info.sm_lid;
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
/**********************************************************************
Packit 13e616
 * Fill in port_attr
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
	osm_ca_info_t ca_info;
Packit 13e616
	uint32_t attr_array_sz = *p_num_ports;
Packit 13e616
Packit 13e616
	OSM_LOG_ENTER(p_vend->p_log);
Packit 13e616
	CL_ASSERT(p_vend);
Packit 13e616
Packit 13e616
	/* anafa has one port - the user didnt supply enough storage space */
Packit 13e616
	if (attr_array_sz < 1) {
Packit 13e616
		status = IB_INSUFFICIENT_MEMORY;
Packit 13e616
		goto Exit;
Packit 13e616
	}
Packit 13e616
Packit 13e616
	/*
Packit 13e616
	 * retrieve the CA info attributes
Packit 13e616
	 */
Packit 13e616
	status = __osm_ca_info_init(p_vend, &ca_info);
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 7004: "
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
Packit 13e616
	*p_num_ports = 1;
Packit 13e616
Packit 13e616
	p_attr_array[0] = ca_info.attr.p_port_attr[0];	/* anafa has only one port */
Packit 13e616
	status = IB_SUCCESS;
Packit 13e616
Packit 13e616
Exit:
Packit 13e616
Packit 13e616
	OSM_LOG_EXIT(p_vend->p_log);
Packit 13e616
	return (status);
Packit 13e616
}
Packit 13e616
Packit 13e616
#endif