Blame libvendor/osm_vendor_test.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
/*
Packit 13e616
 * Abstract:
Packit 13e616
 *    Implementation of vendor specific transport interface.
Packit 13e616
 *  This is the "Test" vendor which allows compilation and some
Packit 13e616
 *  testing without a real vendor interface.
Packit 13e616
 * These objects are part of the opensm family of objects.
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
#ifdef OSM_VENDOR_INTF_TEST
Packit 13e616
Packit 13e616
#include <stdlib.h>
Packit 13e616
#include <string.h>
Packit 13e616
#include <opensm/osm_log.h>
Packit 13e616
#include <vendor/osm_vendor_test.h>
Packit 13e616
#include <vendor/osm_vendor_api.h>
Packit 13e616
Packit 13e616
void osm_vendor_construct(IN osm_vendor_t * const p_vend)
Packit 13e616
{
Packit 13e616
	memset(p_vend, 0, sizeof(*p_vend));
Packit 13e616
}
Packit 13e616
Packit 13e616
void osm_vendor_destroy(IN osm_vendor_t * const p_vend)
Packit 13e616
{
Packit 13e616
	UNUSED_PARAM(p_vend);
Packit 13e616
}
Packit 13e616
Packit 13e616
void osm_vendor_delete(IN osm_vendor_t ** const pp_vend)
Packit 13e616
{
Packit 13e616
	CL_ASSERT(pp_vend);
Packit 13e616
Packit 13e616
	osm_vendor_destroy(*pp_vend);
Packit 13e616
	free(*pp_vend);
Packit 13e616
	*pp_vend = NULL;
Packit 13e616
}
Packit 13e616
Packit 13e616
ib_api_status_t
Packit 13e616
osm_vendor_init(IN osm_vendor_t * const p_vend,
Packit 13e616
		IN osm_log_t * const p_log, IN const uint32_t timeout)
Packit 13e616
{
Packit 13e616
	OSM_LOG_ENTER(p_log);
Packit 13e616
Packit 13e616
	CL_ASSERT(p_vend);
Packit 13e616
	CL_ASSERT(p_log);
Packit 13e616
Packit 13e616
	p_vend->p_log = p_log;
Packit 13e616
	p_vend->timeout = timeout;
Packit 13e616
	OSM_LOG_EXIT(p_log);
Packit 13e616
	return (IB_SUCCESS);
Packit 13e616
}
Packit 13e616
Packit 13e616
osm_vendor_t *osm_vendor_new(IN osm_log_t * const p_log,
Packit 13e616
			     IN const uint32_t timeout)
Packit 13e616
{
Packit 13e616
	ib_api_status_t status;
Packit 13e616
	osm_vendor_t *p_vend;
Packit 13e616
	OSM_LOG_ENTER(p_log);
Packit 13e616
Packit 13e616
	CL_ASSERT(p_log);
Packit 13e616
Packit 13e616
	p_vend = malloc(sizeof(*p_vend));
Packit 13e616
	if (p_vend != NULL) {
Packit 13e616
		memset(p_vend, 0, sizeof(*p_vend));
Packit 13e616
Packit 13e616
		status = osm_vendor_init(p_vend, p_log, timeout);
Packit 13e616
		if (status != IB_SUCCESS) {
Packit 13e616
			osm_vendor_delete(&p_vend);
Packit 13e616
		}
Packit 13e616
	}
Packit 13e616
Packit 13e616
	OSM_LOG_EXIT(p_log);
Packit 13e616
	return (p_vend);
Packit 13e616
}
Packit 13e616
Packit 13e616
ib_mad_t *osm_vendor_get(IN osm_bind_handle_t h_bind,
Packit 13e616
			 IN const uint32_t size,
Packit 13e616
			 IN osm_vend_wrap_t * const p_vend_wrap)
Packit 13e616
{
Packit 13e616
	osm_vendor_t *p_vend;
Packit 13e616
	ib_mad_t *p_mad;
Packit 13e616
	OSM_LOG_ENTER(h_bind->p_vend->p_log);
Packit 13e616
Packit 13e616
	UNUSED_PARAM(p_vend_wrap);
Packit 13e616
Packit 13e616
	p_vend = h_bind->p_vend;
Packit 13e616
Packit 13e616
	/*
Packit 13e616
	   Simply malloc the MAD off the heap.
Packit 13e616
	 */
Packit 13e616
	p_mad = (ib_mad_t *) malloc(size);
Packit 13e616
Packit 13e616
	osm_log(p_vend->p_log, OSM_LOG_VERBOSE,
Packit 13e616
		"osm_vendor_get: " "MAD %p.\n", p_mad);
Packit 13e616
Packit 13e616
	if (p_mad)
Packit 13e616
		memset(p_mad, 0, size);
Packit 13e616
Packit 13e616
	OSM_LOG_EXIT(p_vend->p_log);
Packit 13e616
	return (p_mad);
Packit 13e616
}
Packit 13e616
Packit 13e616
void
Packit 13e616
osm_vendor_put(IN osm_bind_handle_t h_bind,
Packit 13e616
	       IN osm_vend_wrap_t * const p_vend_wrap,
Packit 13e616
	       IN ib_mad_t * const p_mad)
Packit 13e616
{
Packit 13e616
	osm_vendor_t *p_vend;
Packit 13e616
Packit 13e616
	OSM_LOG_ENTER(h_bind->p_vend->p_log);
Packit 13e616
Packit 13e616
	UNUSED_PARAM(p_vend_wrap);
Packit 13e616
Packit 13e616
	p_vend = h_bind->p_vend;
Packit 13e616
Packit 13e616
	osm_log(p_vend->p_log, OSM_LOG_VERBOSE,
Packit 13e616
		"osm_vendor_put: " "MAD %p.\n", p_mad);
Packit 13e616
Packit 13e616
	/*
Packit 13e616
	   Return the MAD to the heap.
Packit 13e616
	 */
Packit 13e616
	free(p_mad);
Packit 13e616
Packit 13e616
	OSM_LOG_EXIT(p_vend->p_log);
Packit 13e616
}
Packit 13e616
Packit 13e616
ib_api_status_t
Packit 13e616
osm_vendor_send(IN osm_bind_handle_t h_bind,
Packit 13e616
		IN osm_vend_wrap_t * const p_vend_wrap,
Packit 13e616
		IN osm_mad_addr_t * const p_mad_addr,
Packit 13e616
		IN ib_mad_t * const p_mad,
Packit 13e616
		IN void *transaction_context, IN boolean_t const resp_expected)
Packit 13e616
{
Packit 13e616
	osm_vendor_t *p_vend = h_bind->p_vend;
Packit 13e616
Packit 13e616
	OSM_LOG_ENTER(p_vend->p_log);
Packit 13e616
Packit 13e616
	UNUSED_PARAM(p_vend_wrap);
Packit 13e616
	UNUSED_PARAM(p_mad_addr);
Packit 13e616
	UNUSED_PARAM(transaction_context);
Packit 13e616
	UNUSED_PARAM(resp_expected);
Packit 13e616
Packit 13e616
	osm_log(p_vend->p_log, OSM_LOG_VERBOSE,
Packit 13e616
		"osm_vendor_send: " "MAD %p.\n", p_mad);
Packit 13e616
Packit 13e616
	OSM_LOG_EXIT(p_vend->p_log);
Packit 13e616
	return (IB_SUCCESS);
Packit 13e616
}
Packit 13e616
Packit 13e616
osm_bind_handle_t
Packit 13e616
osm_vendor_bind(IN osm_vendor_t * const p_vend,
Packit 13e616
		IN osm_bind_info_t * const p_bind_info,
Packit 13e616
		IN osm_mad_pool_t * const p_mad_pool,
Packit 13e616
		IN osm_vend_mad_recv_callback_t mad_recv_callback,
Packit 13e616
		IN void *context)
Packit 13e616
{
Packit 13e616
	osm_bind_handle_t h_bind;
Packit 13e616
Packit 13e616
	OSM_LOG_ENTER(p_vend->p_log);
Packit 13e616
Packit 13e616
	CL_ASSERT(p_vend);
Packit 13e616
	CL_ASSERT(p_bind_info);
Packit 13e616
	CL_ASSERT(p_mad_pool);
Packit 13e616
	CL_ASSERT(mad_recv_callback);
Packit 13e616
	CL_ASSERT(context);
Packit 13e616
Packit 13e616
	UNUSED_PARAM(p_vend);
Packit 13e616
	UNUSED_PARAM(p_mad_pool);
Packit 13e616
	UNUSED_PARAM(mad_recv_callback);
Packit 13e616
	UNUSED_PARAM(context);
Packit 13e616
Packit 13e616
	h_bind = (osm_bind_handle_t) malloc(sizeof(*h_bind));
Packit 13e616
	if (h_bind != NULL) {
Packit 13e616
		memset(h_bind, 0, sizeof(*h_bind));
Packit 13e616
		h_bind->p_vend = p_vend;
Packit 13e616
		h_bind->port_guid = p_bind_info->port_guid;
Packit 13e616
		h_bind->mad_class = p_bind_info->mad_class;
Packit 13e616
		h_bind->class_version = p_bind_info->class_version;
Packit 13e616
		h_bind->is_responder = p_bind_info->is_responder;
Packit 13e616
		h_bind->is_trap_processor = p_bind_info->is_trap_processor;
Packit 13e616
		h_bind->is_report_processor = p_bind_info->is_report_processor;
Packit 13e616
		h_bind->send_q_size = p_bind_info->send_q_size;
Packit 13e616
		h_bind->recv_q_size = p_bind_info->recv_q_size;
Packit 13e616
	}
Packit 13e616
Packit 13e616
	OSM_LOG_EXIT(p_vend->p_log);
Packit 13e616
	return (h_bind);
Packit 13e616
}
Packit 13e616
Packit 13e616
ib_api_status_t
Packit 13e616
osm_vendor_get_ports(IN osm_vendor_t * const p_vend,
Packit 13e616
		     IN ib_net64_t * const p_guids,
Packit 13e616
		     IN uint32_t * const num_guids)
Packit 13e616
{
Packit 13e616
	OSM_LOG_ENTER(p_vend->p_log);
Packit 13e616
Packit 13e616
	*p_guids = CL_NTOH64(0x0000000000001234);
Packit 13e616
	*num_guids = 1;
Packit 13e616
Packit 13e616
	OSM_LOG_EXIT(p_vend->p_log);
Packit 13e616
	return (IB_SUCCESS);
Packit 13e616
}
Packit 13e616
Packit 13e616
ib_api_status_t osm_vendor_local_lid_change(IN osm_bind_handle_t h_bind)
Packit 13e616
{
Packit 13e616
	osm_vendor_t *p_vend = h_bind->p_vend;
Packit 13e616
Packit 13e616
	OSM_LOG_ENTER(p_vend->p_log);
Packit 13e616
Packit 13e616
	OSM_LOG_EXIT(p_vend->p_log);
Packit 13e616
Packit 13e616
	return (IB_SUCCESS);
Packit 13e616
}
Packit 13e616
Packit 13e616
void osm_vendor_set_debug(IN osm_vendor_t * const p_vend, IN int32_t level)
Packit 13e616
{
Packit 13e616
Packit 13e616
}
Packit 13e616
Packit 13e616
#endif				/* OSM_VENDOR_INTF_TEST */