Blame osmtest/osmt_inform.c

Packit 13e616
/*
Packit 13e616
 * Copyright (c) 2006-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
#ifdef OSM_VENDOR_INTF_MTL
Packit 13e616
/*
Packit 13e616
 * Abstract:
Packit 13e616
 *    Implementation of InformInfo testing flow..
Packit 13e616
 *    Top level is osmt_run_inform_info_flow:
Packit 13e616
 *     osmt_bind_inform_qp
Packit 13e616
 *     osmt_reg_unreg_inform_info
Packit 13e616
 *     osmt_send_trap_wait_for_forward
Packit 13e616
 *
Packit 13e616
 */
Packit 13e616
Packit 13e616
#include <unistd.h>
Packit 13e616
#include <stdio.h>
Packit 13e616
#include <stdlib.h>
Packit 13e616
#include <string.h>
Packit 13e616
#include <complib/cl_debug.h>
Packit 13e616
#include <vendor/osm_vendor_mlx_hca.h>
Packit 13e616
#include "osmtest.h"
Packit 13e616
#include "osmt_inform.h"
Packit 13e616
Packit 13e616
/*
Packit 13e616
 * Prepare an asynchronous QP (rcv) for sending inform info and
Packit 13e616
 * handling the incoming reports.
Packit 13e616
 *
Packit 13e616
 */
Packit 13e616
ib_api_status_t
Packit 13e616
osmt_bind_inform_qp(IN osmtest_t * const p_osmt, OUT osmt_qp_ctx_t * p_qp_ctx)
Packit 13e616
{
Packit 13e616
	ib_net64_t port_guid;
Packit 13e616
	VAPI_hca_hndl_t hca_hndl;
Packit 13e616
	VAPI_hca_id_t hca_id;
Packit 13e616
	uint32_t port_num;
Packit 13e616
	VAPI_ret_t vapi_ret;
Packit 13e616
	IB_MGT_ret_t mgt_ret;
Packit 13e616
	uint8_t hca_index;
Packit 13e616
	osm_log_t *p_log = &p_osmt->log;
Packit 13e616
	ib_api_status_t status = IB_SUCCESS;
Packit 13e616
Packit 13e616
	OSM_LOG_ENTER(p_log);
Packit 13e616
Packit 13e616
	port_guid = p_osmt->local_port.port_guid;
Packit 13e616
Packit 13e616
	OSM_LOG(p_log, OSM_LOG_DEBUG, "Binding to port 0x%" PRIx64 "\n",
Packit 13e616
		cl_ntoh64(port_guid));
Packit 13e616
Packit 13e616
	/* obtain the hca name and port num from the guid */
Packit 13e616
	OSM_LOG(p_log, OSM_LOG_DEBUG,
Packit 13e616
		"Finding CA and Port that owns port guid 0x%" PRIx64 "\n",
Packit 13e616
		port_guid);
Packit 13e616
Packit 13e616
	mgt_ret =
Packit 13e616
	    osm_vendor_get_guid_ca_and_port(p_osmt->p_vendor,
Packit 13e616
					    port_guid,
Packit 13e616
					    &hca_hndl,
Packit 13e616
					    &hca_id[0], &hca_index, &port_num);
Packit 13e616
	if (mgt_ret != IB_MGT_OK) {
Packit 13e616
		OSM_LOG(p_log, OSM_LOG_ERROR, "ERR 0109: "
Packit 13e616
			"Unable to obtain CA and port (%d).\n");
Packit 13e616
		status = IB_ERROR;
Packit 13e616
		goto Exit;
Packit 13e616
	}
Packit 13e616
#define OSMT_MTL_REVERSE_QP1_WELL_KNOWN_Q_KEY 0x80010000
Packit 13e616
Packit 13e616
	strncpy(p_qp_ctx->qp_bind_hndl.hca_id, hca_id, sizeof(hca_id));
Packit 13e616
	p_qp_ctx->qp_bind_hndl.hca_hndl = hca_hndl;
Packit 13e616
	p_qp_ctx->qp_bind_hndl.port_num = port_num;
Packit 13e616
	p_qp_ctx->qp_bind_hndl.max_outs_sq = 10;
Packit 13e616
	p_qp_ctx->qp_bind_hndl.max_outs_rq = 10;
Packit 13e616
	p_qp_ctx->qp_bind_hndl.qkey = OSMT_MTL_REVERSE_QP1_WELL_KNOWN_Q_KEY;
Packit 13e616
Packit 13e616
	vapi_ret = osmt_mtl_init_opened_hca(&p_qp_ctx->qp_bind_hndl);
Packit 13e616
	if (vapi_ret != VAPI_OK) {
Packit 13e616
		OSM_LOG(p_log, OSM_LOG_ERROR, "ERR 0114: "
Packit 13e616
			"Error initializing QP.\n");
Packit 13e616
		status = IB_ERROR;
Packit 13e616
		goto Exit;
Packit 13e616
	}
Packit 13e616
Packit 13e616
	/* we use the pre-allocated buffers for send and receive :
Packit 13e616
	   send from buf[0]
Packit 13e616
	   receive from buf[2]
Packit 13e616
	 */
Packit 13e616
	p_qp_ctx->p_send_buf =
Packit 13e616
	    (uint8_t *) p_qp_ctx->qp_bind_hndl.buf_ptr + GRH_LEN;
Packit 13e616
	p_qp_ctx->p_recv_buf =
Packit 13e616
	    (uint8_t *) p_qp_ctx->qp_bind_hndl.buf_ptr + 2 * (GRH_LEN +
Packit 13e616
							      MAD_BLOCK_SIZE);
Packit 13e616
Packit 13e616
	/* Need to clear assigned memory of p_send_buf - before using it to send any data */
Packit 13e616
	memset(p_qp_ctx->p_send_buf, 0, MAD_BLOCK_SIZE);
Packit 13e616
Packit 13e616
	status = IB_SUCCESS;
Packit 13e616
	OSM_LOG(p_log, OSM_LOG_DEBUG, "Initialized QP:0x%X in VAPI Mode\n",
Packit 13e616
		p_qp_ctx->qp_bind_hndl.qp_id);
Packit 13e616
Packit 13e616
	OSM_LOG(p_log, OSM_LOG_DEBUG, "Binding to IB_MGT SMI\n");
Packit 13e616
Packit 13e616
	/* we also need a QP0 handle for sending packets */
Packit 13e616
	mgt_ret = IB_MGT_get_handle(hca_id, port_num, IB_MGT_SMI,
Packit 13e616
				    &(p_qp_ctx->ib_mgt_qp0_handle));
Packit 13e616
	if (IB_MGT_OK != mgt_ret) {
Packit 13e616
		OSM_LOG(p_log, OSM_LOG_ERROR, "ERR 0115: "
Packit 13e616
			"Error obtaining IB_MGT handle to SMI\n");
Packit 13e616
		status = IB_ERROR;
Packit 13e616
		goto Exit;
Packit 13e616
	}
Packit 13e616
Packit 13e616
Exit:
Packit 13e616
	OSM_LOG_EXIT(p_log);
Packit 13e616
	return status;
Packit 13e616
}
Packit 13e616
Packit 13e616
/*
Packit 13e616
 * Close the QP
Packit 13e616
 */
Packit 13e616
void
Packit 13e616
osmt_unbind_inform_qp(IN osmtest_t * const p_osmt, IN osmt_qp_ctx_t * p_qp_ctx)
Packit 13e616
{
Packit 13e616
	osm_log_t *p_log = &p_osmt->log;
Packit 13e616
Packit 13e616
	OSM_LOG_ENTER(p_log);
Packit 13e616
Packit 13e616
	osmt_mtl_mad_cleanup(&p_qp_ctx->qp_bind_hndl);
Packit 13e616
Packit 13e616
	IB_MGT_release_handle(p_qp_ctx->ib_mgt_qp0_handle);
Packit 13e616
Packit 13e616
	OSM_LOG(p_log, OSM_LOG_DEBUG, "Unbind QP handles\n");
Packit 13e616
	OSM_LOG_EXIT(&p_osmt->log);
Packit 13e616
}
Packit 13e616
Packit 13e616
/*
Packit 13e616
 * Register/Unregister to receive the given InformInfo
Packit 13e616
 *
Packit 13e616
 * Uses the qp context to send the inform info mad.
Packit 13e616
 * Wait for GetResp(InformInfoResp)
Packit 13e616
 *
Packit 13e616
 */
Packit 13e616
ib_api_status_t
Packit 13e616
osmt_reg_unreg_inform_info(IN osmtest_t * p_osmt,
Packit 13e616
			   IN osmt_qp_ctx_t * p_qp_ctx,
Packit 13e616
			   IN ib_inform_info_t * p_inform_info,
Packit 13e616
			   IN uint8_t reg_flag)
Packit 13e616
{
Packit 13e616
	ib_sa_mad_t *p_sa_mad = (ib_sa_mad_t *) (p_qp_ctx->p_send_buf);
Packit 13e616
	ib_inform_info_t *p_ii = ib_sa_mad_get_payload_ptr(p_sa_mad);	/*  SA Payload */
Packit 13e616
	VAPI_ret_t vapi_ret;
Packit 13e616
	VAPI_wc_desc_t wc_desc;
Packit 13e616
	VAPI_ud_av_hndl_t avh;
Packit 13e616
	static VAPI_wr_id_t wrid = 16198;
Packit 13e616
	osm_log_t *p_log = &p_osmt->log;
Packit 13e616
	ib_api_status_t status = IB_SUCCESS;
Packit 13e616
Packit 13e616
	OSM_LOG_ENTER(&p_osmt->log);
Packit 13e616
Packit 13e616
	/* init the MAD */
Packit 13e616
	ib_mad_init_new((ib_mad_t *) p_sa_mad,
Packit 13e616
			IB_MCLASS_SUBN_ADM,
Packit 13e616
			(uint8_t) 2,
Packit 13e616
			IB_MAD_METHOD_SET, cl_hton64(wrid), (ib_net16_t) 0, 0);
Packit 13e616
	wrid++;
Packit 13e616
	p_sa_mad->attr_id = IB_MAD_ATTR_INFORM_INFO;
Packit 13e616
Packit 13e616
	/* copy the reference inform info */
Packit 13e616
	memcpy(p_ii, p_inform_info, sizeof(ib_inform_info_t));
Packit 13e616
Packit 13e616
	if (reg_flag) {
Packit 13e616
		OSM_LOG(&p_osmt->log, OSM_LOG_INFO,
Packit 13e616
			"Subscribing InformInfo: Traps from lid:0x%X to 0x%X, trap num :0x%X\n",
Packit 13e616
			p_ii->lid_range_begin, p_ii->lid_range_end,
Packit 13e616
			p_ii->g_or_v.generic.trap_num);
Packit 13e616
	} else {
Packit 13e616
		OSM_LOG(&p_osmt->log, OSM_LOG_INFO,
Packit 13e616
			"UnSubscribing InformInfo: Traps from lid:0x%X to 0x%X\n",
Packit 13e616
			p_ii->lid_range_begin, p_ii->lid_range_end);
Packit 13e616
	}
Packit 13e616
Packit 13e616
	/* set the subscribe bit */
Packit 13e616
	if (reg_flag) {
Packit 13e616
		p_ii->subscribe = 1;
Packit 13e616
	} else {
Packit 13e616
		p_ii->subscribe = 0;
Packit 13e616
		/*
Packit 13e616
		 * we need to set the QPN on the mad if we unsubscribe:
Packit 13e616
		 * o13-2.1.1 - QPN Field need to be set when unsubscribing.
Packit 13e616
		 */
Packit 13e616
		ib_inform_info_set_qpn(p_ii,
Packit 13e616
				       cl_hton32(p_qp_ctx->qp_bind_hndl.qp_id.
Packit 13e616
						 qp_num));
Packit 13e616
	}
Packit 13e616
Packit 13e616
	osm_dump_inform_info(&p_osmt->log, p_ii, OSM_LOG_DEBUG);
Packit 13e616
Packit 13e616
	/* --------------------- PREP ------------------------- */
Packit 13e616
	if (osmt_mtl_mad_post_recv_bufs(&p_qp_ctx->qp_bind_hndl, p_qp_ctx->p_recv_buf, 1,	/*  but we need only one mad at a time */
Packit 13e616
					GRH_LEN + MAD_BLOCK_SIZE, wrid) != 1) {
Packit 13e616
		OSM_LOG(p_log, OSM_LOG_ERROR, "ERR 0120: "
Packit 13e616
			"Error posting recv bufs\n");
Packit 13e616
		status = IB_ERROR;
Packit 13e616
		goto Exit;
Packit 13e616
	}
Packit 13e616
	OSM_LOG(p_log, OSM_LOG_DEBUG, "Posted recv bufs\n");
Packit 13e616
Packit 13e616
	vapi_ret =
Packit 13e616
	    osmt_mtl_create_av(&p_qp_ctx->qp_bind_hndl,
Packit 13e616
			       p_osmt->local_port.sm_lid, &avh);
Packit 13e616
	if (vapi_ret != VAPI_OK) {
Packit 13e616
		OSM_LOG(p_log, OSM_LOG_ERROR, "ERR 0121: "
Packit 13e616
			"Error Preparing AVH (%s)\n",
Packit 13e616
			VAPI_strerror_sym(vapi_ret));
Packit 13e616
		status = IB_ERROR;
Packit 13e616
		goto Exit;
Packit 13e616
	}
Packit 13e616
	OSM_LOG(p_log, OSM_LOG_DEBUG, "Prepared AVH\n");
Packit 13e616
Packit 13e616
	if (osm_log_is_active(p_log, OSM_LOG_DEBUG)) {
Packit 13e616
		osm_dump_sa_mad(p_log, (ib_sa_mad_t *) (p_qp_ctx->p_send_buf),
Packit 13e616
				OSM_LOG_DEBUG);
Packit 13e616
#if 0
Packit 13e616
		for (i = 56; i < 253; i++) {
Packit 13e616
			if (i % 8 == 0) {
Packit 13e616
				printf("\n %d : ", i);
Packit 13e616
			}
Packit 13e616
			printf("0x%02X ", p_qp_ctx->p_send_buf[i]);
Packit 13e616
		}
Packit 13e616
#endif
Packit 13e616
		printf("\n");
Packit 13e616
	}
Packit 13e616
Packit 13e616
	/* --------------------- SEND ------------------------- */
Packit 13e616
	vapi_ret = osmt_mtl_mad_send(&p_qp_ctx->qp_bind_hndl, wrid, p_qp_ctx->p_send_buf, 1,	/*  SA is QP1 */
Packit 13e616
				     0,	/*  SL is 0 */
Packit 13e616
				     OSMT_MTL_REVERSE_QP1_WELL_KNOWN_Q_KEY,
Packit 13e616
				     avh);
Packit 13e616
	if (vapi_ret != VAPI_OK) {
Packit 13e616
		OSM_LOG(p_log, OSM_LOG_ERROR, "ERR 0122: "
Packit 13e616
			"Error sending mad (%s)\n",
Packit 13e616
			VAPI_strerror_sym(vapi_ret));
Packit 13e616
		status = IB_ERROR;
Packit 13e616
		goto Exit;
Packit 13e616
	}
Packit 13e616
Packit 13e616
	vapi_ret = osmt_mtl_mad_poll4cqe(p_qp_ctx->qp_bind_hndl.hca_hndl,
Packit 13e616
					 p_qp_ctx->qp_bind_hndl.sq_cq_hndl,
Packit 13e616
					 &wc_desc, 20, 10000, NULL);
Packit 13e616
	if (vapi_ret != VAPI_OK) {
Packit 13e616
		OSM_LOG(p_log, OSM_LOG_ERROR, "ERR 0123: "
Packit 13e616
			"Error getting send completion (%s)\n",
Packit 13e616
			VAPI_strerror_sym(vapi_ret));
Packit 13e616
		status = IB_ERROR;
Packit 13e616
		goto Exit;
Packit 13e616
	}
Packit 13e616
Packit 13e616
	if (wc_desc.status != VAPI_SUCCESS) {
Packit 13e616
		OSM_LOG(p_log, OSM_LOG_ERROR, "ERR 0124: "
Packit 13e616
			"Error on send completion (%s) (%d)\n",
Packit 13e616
			VAPI_strerror_sym(wc_desc.status), wc_desc.status);
Packit 13e616
		status = IB_ERROR;
Packit 13e616
		goto Exit;
Packit 13e616
	}
Packit 13e616
	OSM_LOG(p_log, OSM_LOG_DEBUG, "Sent MAD\n");
Packit 13e616
Packit 13e616
	/* --------------------- RECV ------------------------- */
Packit 13e616
	vapi_ret = osmt_mtl_mad_poll4cqe(p_qp_ctx->qp_bind_hndl.hca_hndl,
Packit 13e616
					 p_qp_ctx->qp_bind_hndl.rq_cq_hndl,
Packit 13e616
					 &wc_desc, 20, 10000, &avh);
Packit 13e616
	if (vapi_ret != VAPI_SUCCESS) {
Packit 13e616
		if (vapi_ret == VAPI_CQ_EMPTY) {
Packit 13e616
			status = IB_TIMEOUT;
Packit 13e616
		} else {
Packit 13e616
			OSM_LOG(p_log, OSM_LOG_ERROR, "ERR 0125: "
Packit 13e616
				"Error receiving mad (%s)\n",
Packit 13e616
				VAPI_strerror_sym(vapi_ret));
Packit 13e616
			status = IB_ERROR;
Packit 13e616
		}
Packit 13e616
		goto Exit;
Packit 13e616
	}
Packit 13e616
Packit 13e616
	/* check to see if successful - by examination of the subscribe bit */
Packit 13e616
	p_sa_mad = (ib_sa_mad_t *) (p_qp_ctx->p_recv_buf + GRH_LEN);
Packit 13e616
Packit 13e616
	if (p_sa_mad->status != IB_SUCCESS) {
Packit 13e616
		OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, "Remote error = %s\n",
Packit 13e616
			ib_get_mad_status_str((ib_mad_t *) p_sa_mad));
Packit 13e616
		status = IB_REMOTE_ERROR;
Packit 13e616
		goto Exit;
Packit 13e616
	}
Packit 13e616
Packit 13e616
	if (p_sa_mad->method != IB_MAD_METHOD_GET_RESP) {
Packit 13e616
		OSM_LOG(&p_osmt->log, OSM_LOG_ERROR,
Packit 13e616
			"Expected IB_MAD_METHOD_GET_RESP but got:(%X)\n",
Packit 13e616
			p_sa_mad->method);
Packit 13e616
		status = IB_REMOTE_ERROR;
Packit 13e616
		goto Exit;
Packit 13e616
	}
Packit 13e616
Packit 13e616
	if (p_sa_mad->attr_id != IB_MAD_ATTR_INFORM_INFO) {
Packit 13e616
		OSM_LOG(&p_osmt->log, OSM_LOG_ERROR,
Packit 13e616
			"Expected IB_MAD_ATTR_INFORM_INFO but got:(%X)\n",
Packit 13e616
			cl_ntoh16(p_sa_mad->attr_id));
Packit 13e616
		status = IB_REMOTE_ERROR;
Packit 13e616
		goto Exit;
Packit 13e616
	}
Packit 13e616
Packit 13e616
	p_ii = ib_sa_mad_get_payload_ptr(p_sa_mad);
Packit 13e616
	if (!p_ii->subscribe) {
Packit 13e616
		OSM_LOG(p_log, OSM_LOG_ERROR, "ERR 0126: "
Packit 13e616
			"Subscribe/Unsubscribe Failed\n");
Packit 13e616
		status = IB_REMOTE_ERROR;
Packit 13e616
	}
Packit 13e616
Packit 13e616
Exit:
Packit 13e616
	OSM_LOG_EXIT(&p_osmt->log);
Packit 13e616
	return status;
Packit 13e616
}
Packit 13e616
Packit 13e616
/*
Packit 13e616
 * Send a trap (Subn LID Route) Trap(Notice) through the regular
Packit 13e616
 * connection QP connection (targeted at QP0)
Packit 13e616
 *
Packit 13e616
 * Wait for the trap repress
Packit 13e616
 */
Packit 13e616
ib_api_status_t
Packit 13e616
osmt_send_trap_wait_for_forward(IN osmtest_t * const p_osmt,
Packit 13e616
				IN osmt_qp_ctx_t * p_qp_ctx)
Packit 13e616
{
Packit 13e616
	ib_smp_t *p_smp = (ib_smp_t *) (p_qp_ctx->p_send_buf);
Packit 13e616
	ib_mad_notice_attr_t *p_ntc = ib_smp_get_payload_ptr(p_smp);
Packit 13e616
	ib_sa_mad_t *p_sa_mad;
Packit 13e616
	IB_MGT_ret_t mgt_res;
Packit 13e616
	VAPI_ret_t vapi_ret;
Packit 13e616
	VAPI_wc_desc_t wc_desc;
Packit 13e616
	VAPI_ud_av_hndl_t avh;
Packit 13e616
	IB_ud_av_t av;
Packit 13e616
	static VAPI_wr_id_t wrid = 2222;
Packit 13e616
	osm_log_t *p_log = &p_osmt->log;
Packit 13e616
	ib_api_status_t status = IB_SUCCESS;
Packit 13e616
Packit 13e616
	OSM_LOG_ENTER(p_log);
Packit 13e616
Packit 13e616
	OSM_LOG(p_log, OSM_LOG_INFO,
Packit 13e616
		"Sending Traps to QP0 of SA LID:0x%X\n",
Packit 13e616
		p_osmt->local_port.sm_lid);
Packit 13e616
Packit 13e616
	/* init the MAD */
Packit 13e616
	memset(p_smp, 0, sizeof(ib_smp_t));
Packit 13e616
	ib_mad_init_new((ib_mad_t *) p_smp,
Packit 13e616
			IB_MCLASS_SUBN_LID,
Packit 13e616
			(uint8_t) 2,
Packit 13e616
			IB_MAD_METHOD_TRAP, cl_hton64(wrid), (ib_net16_t) 0, 0);
Packit 13e616
Packit 13e616
	wrid++;
Packit 13e616
	p_smp->attr_id = IB_MAD_ATTR_NOTICE;
Packit 13e616
Packit 13e616
	/* prepare the notice */
Packit 13e616
	p_ntc->generic_type = 0x82;	/*  generic, type = 2 */
Packit 13e616
	ib_notice_set_prod_type_ho(p_ntc, 1);
Packit 13e616
	p_ntc->g_or_v.generic.trap_num = cl_hton16(0x26);
Packit 13e616
	p_ntc->issuer_lid = cl_hton16(2);
Packit 13e616
Packit 13e616
	/* --------------------- PREP ------------------------- */
Packit 13e616
	if (osmt_mtl_mad_post_recv_bufs(&p_qp_ctx->qp_bind_hndl, p_qp_ctx->p_recv_buf, 1,	/*  we need to receive both trap repress and report */
Packit 13e616
					GRH_LEN + MAD_BLOCK_SIZE, wrid) != 1) {
Packit 13e616
		OSM_LOG(p_log, OSM_LOG_ERROR, "ERR 0127: "
Packit 13e616
			"Error posting recv bufs\n");
Packit 13e616
		status = IB_ERROR;
Packit 13e616
		goto Exit;
Packit 13e616
	}
Packit 13e616
	OSM_LOG(p_log, OSM_LOG_DEBUG, "Posted recv bufs\n");
Packit 13e616
Packit 13e616
	av.dlid = p_osmt->local_port.sm_lid;
Packit 13e616
	av.grh_flag = FALSE;
Packit 13e616
Packit 13e616
	/*  EZ: returned in HACK: use constants */
Packit 13e616
	av.static_rate = 0;	/*  p_mad_addr->static_rate; */
Packit 13e616
	av.src_path_bits = 1;	/*  p_mad_addr->path_bits; */
Packit 13e616
	av.sl = 0;		/*  p_mad_addr->addr_type.gsi.service_level; */
Packit 13e616
Packit 13e616
	OSM_LOG(p_log, OSM_LOG_DEBUG,
Packit 13e616
		"av.dlid 0x%X, av.static_rate %d, av.path_bits %d\n",
Packit 13e616
		cl_ntoh16(av.dlid), av.static_rate, av.src_path_bits);
Packit 13e616
Packit 13e616
	/* send it */
Packit 13e616
	mgt_res = IB_MGT_send_mad(p_qp_ctx->ib_mgt_qp0_handle, p_smp,	/*  actual payload */
Packit 13e616
				  &av,	/*  address vector */
Packit 13e616
				  wrid,	/*  casting the mad wrapper pointer for err cb */
Packit 13e616
				  p_osmt->opt.transaction_timeout);
Packit 13e616
	if (mgt_res != IB_MGT_OK) {
Packit 13e616
		OSM_LOG(p_log, OSM_LOG_ERROR, "ERR 0128: "
Packit 13e616
			"Error sending mad (%d)\n", mgt_res);
Packit 13e616
		status = IB_ERROR;
Packit 13e616
		goto Exit;
Packit 13e616
	}
Packit 13e616
Packit 13e616
	vapi_ret =
Packit 13e616
	    osmt_mtl_create_av(&p_qp_ctx->qp_bind_hndl,
Packit 13e616
			       p_osmt->local_port.sm_lid, &avh);
Packit 13e616
	if (vapi_ret != VAPI_OK) {
Packit 13e616
		OSM_LOG(p_log, OSM_LOG_ERROR, "ERR 0129: "
Packit 13e616
			"Error Preparing AVH (%s)\n",
Packit 13e616
			VAPI_strerror_sym(vapi_ret));
Packit 13e616
		status = IB_ERROR;
Packit 13e616
		goto Exit;
Packit 13e616
	}
Packit 13e616
	OSM_LOG(p_log, OSM_LOG_DEBUG, "Prepared AVH\n");
Packit 13e616
Packit 13e616
	OSM_LOG(p_log, OSM_LOG_DEBUG, "Trap MAD Sent\n");
Packit 13e616
Packit 13e616
	/* --------------------- RECV ------------------------- */
Packit 13e616
	vapi_ret = osmt_mtl_mad_poll4cqe(p_qp_ctx->qp_bind_hndl.hca_hndl,
Packit 13e616
					 p_qp_ctx->qp_bind_hndl.rq_cq_hndl,
Packit 13e616
					 &wc_desc, 200, 10000, &avh);
Packit 13e616
	if (vapi_ret != VAPI_SUCCESS) {
Packit 13e616
		if (vapi_ret == VAPI_CQ_EMPTY) {
Packit 13e616
			OSM_LOG(p_log, OSM_LOG_ERROR, "ERR 0130: "
Packit 13e616
				"Timeout receiving mad (%s)\n",
Packit 13e616
				VAPI_strerror_sym(vapi_ret));
Packit 13e616
			status = IB_TIMEOUT;
Packit 13e616
		} else {
Packit 13e616
			OSM_LOG(p_log, OSM_LOG_ERROR, "ERR 0131: "
Packit 13e616
				"Error receiving mad (%s)\n",
Packit 13e616
				VAPI_strerror_sym(vapi_ret));
Packit 13e616
			status = IB_ERROR;
Packit 13e616
		}
Packit 13e616
		goto Exit;
Packit 13e616
	}
Packit 13e616
Packit 13e616
	/* check to see if successful - by examination of the subscribe bit */
Packit 13e616
	p_sa_mad = (ib_sa_mad_t *) (p_qp_ctx->p_recv_buf + GRH_LEN);
Packit 13e616
Packit 13e616
	if (p_sa_mad->method == IB_MAD_METHOD_REPORT) {
Packit 13e616
		if (p_sa_mad->attr_id == IB_MAD_ATTR_NOTICE) {
Packit 13e616
			OSM_LOG(p_log, OSM_LOG_INFO, "Received the Report!\n");
Packit 13e616
			status = IB_SUCCESS;
Packit 13e616
		} else {
Packit 13e616
			OSM_LOG(p_log, OSM_LOG_ERROR, "ERR 1020"
Packit 13e616
				"Did not receive a Report(Notice) but attr:%d\n",
Packit 13e616
				cl_ntoh16(p_sa_mad->attr_id));
Packit 13e616
			status = IB_ERROR;
Packit 13e616
		}
Packit 13e616
	} else {
Packit 13e616
		OSM_LOG(p_log, OSM_LOG_ERROR, "ERR 1020"
Packit 13e616
			"Received an Unexpected Method:%d\n", p_smp->method);
Packit 13e616
		status = IB_ERROR;
Packit 13e616
	}
Packit 13e616
Packit 13e616
Exit:
Packit 13e616
	OSM_LOG_EXIT(p_log);
Packit 13e616
	return status;
Packit 13e616
}
Packit 13e616
Packit 13e616
/*
Packit 13e616
 * Wait for a trap on QPn
Packit 13e616
 *
Packit 13e616
 */
Packit 13e616
ib_api_status_t
Packit 13e616
osmt_trap_wait(IN osmtest_t * const p_osmt, IN osmt_qp_ctx_t * p_qp_ctx)
Packit 13e616
{
Packit 13e616
	ib_smp_t *p_smp = (ib_smp_t *) (p_qp_ctx->p_send_buf);
Packit 13e616
	ib_sa_mad_t *p_sa_mad;
Packit 13e616
	VAPI_ret_t vapi_ret;
Packit 13e616
	VAPI_wc_desc_t wc_desc;
Packit 13e616
	osm_log_t *p_log = &p_osmt->log;
Packit 13e616
	ib_api_status_t status = IB_SUCCESS;
Packit 13e616
Packit 13e616
	OSM_LOG_ENTER(p_log);
Packit 13e616
Packit 13e616
	OSM_LOG(p_log, OSM_LOG_INFO,
Packit 13e616
		"Waiting for Traps under QP:0x%X of SA LID:0x%X\n",
Packit 13e616
		cl_ntoh16(p_osmt->local_port.sm_lid));
Packit 13e616
Packit 13e616
	/* --------------------- RECV ------------------------- */
Packit 13e616
	vapi_ret = osmt_mtl_mad_poll4cqe(p_qp_ctx->qp_bind_hndl.hca_hndl,
Packit 13e616
					 p_qp_ctx->qp_bind_hndl.rq_cq_hndl,
Packit 13e616
					 &wc_desc,
Packit 13e616
					 // 200,
Packit 13e616
					 p_osmt->opt.wait_time * 100,
Packit 13e616
					 10000, NULL);
Packit 13e616
	if (vapi_ret != VAPI_SUCCESS) {
Packit 13e616
		if (vapi_ret == VAPI_CQ_EMPTY) {
Packit 13e616
			OSM_LOG(p_log, OSM_LOG_ERROR, "ERR 0130: "
Packit 13e616
				"Timeout receiving mad (%s)\n",
Packit 13e616
				VAPI_strerror_sym(vapi_ret));
Packit 13e616
			status = IB_TIMEOUT;
Packit 13e616
		} else {
Packit 13e616
			OSM_LOG(p_log, OSM_LOG_ERROR, "ERR 0131: "
Packit 13e616
				"Error receiving mad (%s)\n",
Packit 13e616
				VAPI_strerror_sym(vapi_ret));
Packit 13e616
			status = IB_ERROR;
Packit 13e616
		}
Packit 13e616
		goto Exit;
Packit 13e616
	}
Packit 13e616
Packit 13e616
	/* check to see if successful - by examination of the subscribe bit */
Packit 13e616
	p_sa_mad = (ib_sa_mad_t *) (p_qp_ctx->p_recv_buf + GRH_LEN);
Packit 13e616
Packit 13e616
	if (p_sa_mad->method == IB_MAD_METHOD_REPORT) {
Packit 13e616
		if (p_sa_mad->attr_id == IB_MAD_ATTR_NOTICE) {
Packit 13e616
			OSM_LOG(&p_osmt->log, OSM_LOG_INFO,
Packit 13e616
				"Received the Report!\n");
Packit 13e616
			status = IB_SUCCESS;
Packit 13e616
		} else {
Packit 13e616
			OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, "ERR 1020"
Packit 13e616
				"Did not receive a Report(Notice) but attr:%d\n",
Packit 13e616
				cl_ntoh16(p_sa_mad->attr_id));
Packit 13e616
			status = IB_ERROR;
Packit 13e616
		}
Packit 13e616
	} else {
Packit 13e616
		OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, "ERR 1020"
Packit 13e616
			"Received an Unexpected Method:%d\n", p_smp->method);
Packit 13e616
		status = IB_ERROR;
Packit 13e616
	}
Packit 13e616
Packit 13e616
Exit:
Packit 13e616
	OSM_LOG_EXIT(p_log);
Packit 13e616
	return status;
Packit 13e616
}
Packit 13e616
Packit 13e616
/*
Packit 13e616
 * Initialize an inform info attribute:
Packit 13e616
 * Catch all traps in the lid range of the p_osmt
Packit 13e616
 *
Packit 13e616
 */
Packit 13e616
ib_api_status_t
Packit 13e616
osmt_init_inform_info(IN osmtest_t * const p_osmt, OUT ib_inform_info_t * p_ii)
Packit 13e616
{
Packit 13e616
Packit 13e616
	memset(p_ii, 0, sizeof(ib_inform_info_t));
Packit 13e616
	/*  p_ii->lid_range_begin = cl_hton16(1); */
Packit 13e616
	p_ii->lid_range_begin = 0xFFFF;
Packit 13e616
	p_ii->lid_range_end = cl_hton16(p_osmt->max_lid);
Packit 13e616
	p_ii->is_generic = 1;	/*  have to choose */
Packit 13e616
	p_ii->trap_type = 0xFFFF;	/*  ALL */
Packit 13e616
	p_ii->g_or_v.generic.trap_num = 0xFFFF;	/*  ALL */
Packit 13e616
	p_ii->g_or_v.generic.node_type_lsb = 0xFFFF;	/*  ALL */
Packit 13e616
	p_ii->g_or_v.generic.node_type_msb = 0xFF;	/*  ALL */
Packit 13e616
	return IB_SUCCESS;
Packit 13e616
}
Packit 13e616
Packit 13e616
ib_api_status_t
Packit 13e616
osmt_init_inform_info_by_trap(IN osmtest_t * const p_osmt,
Packit 13e616
			      IN ib_net16_t trap_num,
Packit 13e616
			      OUT ib_inform_info_t * p_ii)
Packit 13e616
{
Packit 13e616
Packit 13e616
	memset(p_ii, 0, sizeof(ib_inform_info_t));
Packit 13e616
	/*  p_ii->lid_range_begin = cl_hton16(1); */
Packit 13e616
	p_ii->lid_range_begin = 0xFFFF;
Packit 13e616
	p_ii->lid_range_end = cl_hton16(p_osmt->max_lid);
Packit 13e616
	p_ii->is_generic = 1;	/*  have to choose */
Packit 13e616
	p_ii->trap_type = 0xFFFF;	/*  ALL */
Packit 13e616
	p_ii->g_or_v.generic.trap_num = trap_num;	/*  ALL */
Packit 13e616
	p_ii->g_or_v.generic.node_type_lsb = 0xFFFF;	/*  ALL */
Packit 13e616
	p_ii->g_or_v.generic.node_type_msb = 0xFF;	/*  ALL */
Packit 13e616
	return IB_SUCCESS;
Packit 13e616
}
Packit 13e616
Packit 13e616
/*
Packit 13e616
 * Run a complete inform info test flow:
Packit 13e616
 * - try to unregister inform info (should fail)
Packit 13e616
 * - register an inform info
Packit 13e616
 * - try to unregister inform info (should succeed)
Packit 13e616
 * - register an inform info
Packit 13e616
 * - send a trap - sleep
Packit 13e616
 * - check that a Report(Notice) arrived that matches the sent trap
Packit 13e616
 *
Packit 13e616
 */
Packit 13e616
ib_api_status_t osmt_run_inform_info_flow(IN osmtest_t * const p_osmt)
Packit 13e616
{
Packit 13e616
	ib_inform_info_t inform_info;
Packit 13e616
	ib_api_status_t status;
Packit 13e616
	osmt_qp_ctx_t qp_ctx;
Packit 13e616
Packit 13e616
	OSM_LOG_ENTER(&p_osmt->log);
Packit 13e616
Packit 13e616
	/* bind the QP */
Packit 13e616
	status = osmt_bind_inform_qp(p_osmt, &qp_ctx);
Packit 13e616
	if (status != IB_SUCCESS) {
Packit 13e616
		goto Exit;
Packit 13e616
	}
Packit 13e616
Packit 13e616
	/* init the inform info */
Packit 13e616
	osmt_init_inform_info(p_osmt, &inform_info);
Packit 13e616
Packit 13e616
	/* first try to unsubscribe */
Packit 13e616
	status = osmt_reg_unreg_inform_info(p_osmt, &qp_ctx, &inform_info, 0);
Packit 13e616
	/* WAS IB_REMOTE_ERROR */
Packit 13e616
	if (status != IB_REMOTE_ERROR) {
Packit 13e616
		if (status != IB_SUCCESS) {
Packit 13e616
			OSM_LOG(&p_osmt->log, OSM_LOG_INFO,
Packit 13e616
				"Error during UnSubscribe: (%s)\n",
Packit 13e616
				ib_get_err_str(status));
Packit 13e616
			goto Exit;
Packit 13e616
		} else {
Packit 13e616
			OSM_LOG(&p_osmt->log, OSM_LOG_INFO,
Packit 13e616
				"Expected Failure to UnSubscribe non existing InformInfo\n");
Packit 13e616
			status = IB_ERROR;
Packit 13e616
			goto Exit;
Packit 13e616
		}
Packit 13e616
	}
Packit 13e616
Packit 13e616
	/* send the inform info registration */
Packit 13e616
	status = osmt_reg_unreg_inform_info(p_osmt, &qp_ctx, &inform_info, 1);
Packit 13e616
	if (status != IB_SUCCESS) {
Packit 13e616
		goto Exit;
Packit 13e616
	}
Packit 13e616
Packit 13e616
	/* send a trap through QP0 and wait on QPN */
Packit 13e616
	status = osmt_send_trap_wait_for_forward(p_osmt, &qp_ctx);
Packit 13e616
	if (status != IB_SUCCESS) {
Packit 13e616
		OSM_LOG(&p_osmt->log, OSM_LOG_INFO,
Packit 13e616
			"Error during Send Trap and Wait For Report: (%s)\n",
Packit 13e616
			ib_get_err_str(status));
Packit 13e616
		goto Exit;
Packit 13e616
	}
Packit 13e616
Packit 13e616
	/* try to unsubscribe for cleanup */
Packit 13e616
	status = osmt_reg_unreg_inform_info(p_osmt, &qp_ctx, &inform_info, 0);
Packit 13e616
Packit 13e616
	if (status != IB_SUCCESS) {
Packit 13e616
		OSM_LOG(&p_osmt->log, OSM_LOG_INFO,
Packit 13e616
			"Error during UnSubscribe: (%s)\n",
Packit 13e616
			ib_get_err_str(status));
Packit 13e616
		goto Exit;
Packit 13e616
	} else {
Packit 13e616
		if (status == IB_REMOTE_ERROR) {
Packit 13e616
			OSM_LOG(&p_osmt->log, OSM_LOG_INFO,
Packit 13e616
				"Remote Error during UnSubscribe\n");
Packit 13e616
			status = IB_ERROR;
Packit 13e616
			goto Exit;
Packit 13e616
		}
Packit 13e616
	}
Packit 13e616
Packit 13e616
Exit:
Packit 13e616
	osmt_unbind_inform_qp(p_osmt, &qp_ctx);
Packit 13e616
	OSM_LOG_EXIT(&p_osmt->log);
Packit 13e616
	return status;
Packit 13e616
}
Packit 13e616
Packit 13e616
/*
Packit 13e616
 * Run a complete inform info test flow:
Packit 13e616
 * - try to unregister inform info (should fail)
Packit 13e616
 * - register an inform info
Packit 13e616
 * - try to unregister inform info (should succeed)
Packit 13e616
 * - register an inform info
Packit 13e616
 * - send a trap - sleep
Packit 13e616
 * - check that a Report(Notice) arrived that match the sent one
Packit 13e616
 *
Packit 13e616
 */
Packit 13e616
ib_api_status_t osmt_run_trap64_65_flow(IN osmtest_t * const p_osmt)
Packit 13e616
{
Packit 13e616
	ib_inform_info_t inform_info;
Packit 13e616
	ib_api_status_t status;
Packit 13e616
	osmt_qp_ctx_t qp_ctx;
Packit 13e616
Packit 13e616
	OSM_LOG_ENTER(&p_osmt->log);
Packit 13e616
Packit 13e616
	/* bind the QP */
Packit 13e616
	status = osmt_bind_inform_qp(p_osmt, &qp_ctx);
Packit 13e616
	if (status != IB_SUCCESS) {
Packit 13e616
		goto Exit;
Packit 13e616
	}
Packit 13e616
Packit 13e616
	/* init the inform info */
Packit 13e616
	osmt_init_inform_info_by_trap(p_osmt, cl_hton16(64), &inform_info);
Packit 13e616
Packit 13e616
	/* send the inform info registration */
Packit 13e616
	status = osmt_reg_unreg_inform_info(p_osmt, &qp_ctx, &inform_info, 1);
Packit 13e616
	if (status != IB_SUCCESS) {
Packit 13e616
		goto Exit;
Packit 13e616
	}
Packit 13e616
Packit 13e616
  /*--------------------- PREP -------------------------*/
Packit 13e616
	if (osmt_mtl_mad_post_recv_bufs(&qp_ctx.qp_bind_hndl, qp_ctx.p_recv_buf, 1,	/* we need to receive the report */
Packit 13e616
					GRH_LEN + MAD_BLOCK_SIZE, 1) != 1) {
Packit 13e616
		OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, "ERR 0127: "
Packit 13e616
			"Error posting recv bufs for trap 64\n");
Packit 13e616
		status = IB_ERROR;
Packit 13e616
		goto Exit;
Packit 13e616
	}
Packit 13e616
Packit 13e616
	OSM_LOG(&p_osmt->log, OSM_LOG_DEBUG, "Posted recv bufs for trap 64\n");
Packit 13e616
Packit 13e616
	/* init the inform info */
Packit 13e616
	osmt_init_inform_info_by_trap(p_osmt, cl_hton16(65), &inform_info);
Packit 13e616
Packit 13e616
	/* send the inform info registration */
Packit 13e616
	status = osmt_reg_unreg_inform_info(p_osmt, &qp_ctx, &inform_info, 1);
Packit 13e616
	if (status != IB_SUCCESS) {
Packit 13e616
		goto Exit;
Packit 13e616
	}
Packit 13e616
Packit 13e616
  /*--------------------- PREP -------------------------*/
Packit 13e616
	if (osmt_mtl_mad_post_recv_bufs(&qp_ctx.qp_bind_hndl, qp_ctx.p_recv_buf, 1,	/* we need to receive the report */
Packit 13e616
					GRH_LEN + MAD_BLOCK_SIZE, 1) != 1) {
Packit 13e616
		OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, "ERR 0127: "
Packit 13e616
			"Error posting recv bufs for trap 65\n");
Packit 13e616
		status = IB_ERROR;
Packit 13e616
		goto Exit;
Packit 13e616
	}
Packit 13e616
	OSM_LOG(&p_osmt->log, OSM_LOG_DEBUG, "Posted recv bufs for trap 65\n");
Packit 13e616
Packit 13e616
	/* Sleep for x seconds in order to allow external script trap generation */
Packit 13e616
#if 0
Packit 13e616
	sleep(p_osmt->opt.wait_time);
Packit 13e616
#endif
Packit 13e616
Packit 13e616
	/* wait for a trap on QPN */
Packit 13e616
	status = osmt_trap_wait(p_osmt, &qp_ctx);
Packit 13e616
	if (status != IB_SUCCESS) {
Packit 13e616
		OSM_LOG(&p_osmt->log, OSM_LOG_INFO,
Packit 13e616
			"Error during Send Trap and Wait For Report: (%s)\n",
Packit 13e616
			ib_get_err_str(status));
Packit 13e616
		goto Exit;
Packit 13e616
	}
Packit 13e616
Packit 13e616
	/* try to unsubscribe for cleanup */
Packit 13e616
	status = osmt_reg_unreg_inform_info(p_osmt, &qp_ctx, &inform_info, 0);
Packit 13e616
Packit 13e616
	if (status != IB_SUCCESS) {
Packit 13e616
		OSM_LOG(&p_osmt->log, OSM_LOG_INFO,
Packit 13e616
			"Error during UnSubscribe: (%s)\n",
Packit 13e616
			ib_get_err_str(status));
Packit 13e616
		goto Exit;
Packit 13e616
	}
Packit 13e616
Packit 13e616
Exit:
Packit 13e616
	osmt_unbind_inform_qp(p_osmt, &qp_ctx);
Packit 13e616
	OSM_LOG_EXIT(&p_osmt->log);
Packit 13e616
	return status;
Packit 13e616
}
Packit 13e616
Packit 13e616
#endif				/*  OSM_VENDOR_INTF_MTL */