Blame opensm/osm_sminfo_rcv.c

Packit 13e616
/*
Packit 13e616
 * Copyright (c) 2004-2009 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
 * Copyright (c) 2013 Oracle and/or its affiliates. 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 osm_sminfo_rcv_t.
Packit 13e616
 * This object represents the SMInfo Receiver object.
Packit 13e616
 * This object is part of the opensm family of objects.
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
#include <iba/ib_types.h>
Packit 13e616
#include <complib/cl_qmap.h>
Packit 13e616
#include <complib/cl_passivelock.h>
Packit 13e616
#include <complib/cl_debug.h>
Packit 13e616
#include <opensm/osm_file_ids.h>
Packit 13e616
#define FILE_ID OSM_FILE_SMINFO_RCV_C
Packit 13e616
#include <opensm/osm_madw.h>
Packit 13e616
#include <opensm/osm_log.h>
Packit 13e616
#include <opensm/osm_node.h>
Packit 13e616
#include <opensm/osm_helper.h>
Packit 13e616
#include <opensm/osm_subnet.h>
Packit 13e616
#include <opensm/osm_sm.h>
Packit 13e616
#include <opensm/osm_opensm.h>
Packit 13e616
Packit 13e616
/**********************************************************************
Packit 13e616
 Return TRUE if the remote sm given (by ib_sm_info_t) is higher,
Packit 13e616
 return FALSE otherwise.
Packit 13e616
 By higher - we mean: SM with higher priority or with same priority
Packit 13e616
 and lower GUID.
Packit 13e616
**********************************************************************/
Packit 13e616
static boolean_t smi_rcv_remote_sm_is_higher(IN osm_sm_t * sm,
Packit 13e616
					     IN const ib_sm_info_t * p_rem_smi)
Packit 13e616
{
Packit 13e616
	return osm_sm_is_greater_than(ib_sminfo_get_priority(p_rem_smi),
Packit 13e616
				      p_rem_smi->guid,
Packit 13e616
				      sm->p_subn->opt.sm_priority,
Packit 13e616
				      sm->p_subn->sm_port_guid);
Packit 13e616
Packit 13e616
}
Packit 13e616
Packit 13e616
static void smi_rcv_process_get_request(IN osm_sm_t * sm,
Packit 13e616
					IN const osm_madw_t * p_madw,
Packit 13e616
					IN boolean_t fill_sm_key)
Packit 13e616
{
Packit 13e616
	uint8_t payload[IB_SMP_DATA_SIZE];
Packit 13e616
	ib_sm_info_t *p_smi = (ib_sm_info_t *) payload;
Packit 13e616
	ib_api_status_t status;
Packit 13e616
Packit 13e616
	OSM_LOG_ENTER(sm->p_log);
Packit 13e616
Packit 13e616
	CL_ASSERT(p_madw);
Packit 13e616
Packit 13e616
	/* No real need to grab the lock for this function. */
Packit 13e616
	memset(payload, 0, sizeof(payload));
Packit 13e616
Packit 13e616
	CL_ASSERT(osm_madw_get_smp_ptr(p_madw)->method == IB_MAD_METHOD_GET);
Packit 13e616
Packit 13e616
	p_smi->guid = sm->p_subn->sm_port_guid;
Packit 13e616
	p_smi->act_count = cl_hton32(sm->p_subn->p_osm->stats.qp0_mads_sent);
Packit 13e616
	p_smi->pri_state = (uint8_t) (sm->p_subn->sm_state |
Packit 13e616
				      sm->p_subn->opt.sm_priority << 4);
Packit 13e616
	p_smi->sm_key = fill_sm_key ? sm->p_subn->opt.sm_key : 0;
Packit 13e616
Packit 13e616
	status = osm_resp_send(sm, p_madw, 0, payload);
Packit 13e616
	if (status != IB_SUCCESS) {
Packit 13e616
		OSM_LOG(sm->p_log, OSM_LOG_ERROR, "ERR 2F02: "
Packit 13e616
			"Error sending SMInfo response (%s)\n",
Packit 13e616
			ib_get_err_str(status));
Packit 13e616
		goto Exit;
Packit 13e616
	}
Packit 13e616
Packit 13e616
Exit:
Packit 13e616
	OSM_LOG_EXIT(sm->p_log);
Packit 13e616
}
Packit 13e616
Packit 13e616
/**********************************************************************
Packit 13e616
 * Check if the p_smp received is legal.
Packit 13e616
 * Current checks:
Packit 13e616
 *   MADHeader:AttributeModifier of ACKNOWLEDGE that was not sent by a
Packit 13e616
 *             Standby SM.
Packit 13e616
 *   MADHeader:AttributeModifiers of HANDOVER/DISABLE/STANDBY/DISCOVER
Packit 13e616
 *             that was not sent by a Master SM.
Packit 13e616
 * FUTURE - TO DO:
Packit 13e616
 *   Check that the SM_Key matches.
Packit 13e616
 **********************************************************************/
Packit 13e616
static ib_api_status_t smi_rcv_check_set_req_legality(IN const ib_smp_t * p_smp)
Packit 13e616
{
Packit 13e616
	ib_sm_info_t *p_smi;
Packit 13e616
Packit 13e616
	p_smi = ib_smp_get_payload_ptr(p_smp);
Packit 13e616
Packit 13e616
	if (p_smp->attr_mod == IB_SMINFO_ATTR_MOD_ACKNOWLEDGE) {
Packit 13e616
		if (ib_sminfo_get_state(p_smi) == IB_SMINFO_STATE_STANDBY)
Packit 13e616
			return IB_SUCCESS;
Packit 13e616
	} else if (p_smp->attr_mod == IB_SMINFO_ATTR_MOD_HANDOVER ||
Packit 13e616
		   p_smp->attr_mod == IB_SMINFO_ATTR_MOD_DISABLE ||
Packit 13e616
		   p_smp->attr_mod == IB_SMINFO_ATTR_MOD_STANDBY ||
Packit 13e616
		   p_smp->attr_mod == IB_SMINFO_ATTR_MOD_DISCOVER) {
Packit 13e616
		if (ib_sminfo_get_state(p_smi) == IB_SMINFO_STATE_MASTER)
Packit 13e616
			return IB_SUCCESS;
Packit 13e616
	}
Packit 13e616
Packit 13e616
	return IB_INVALID_PARAMETER;
Packit 13e616
}
Packit 13e616
Packit 13e616
static void smi_rcv_process_set_request(IN osm_sm_t * sm,
Packit 13e616
					IN const osm_madw_t * p_madw)
Packit 13e616
{
Packit 13e616
	uint8_t payload[IB_SMP_DATA_SIZE];
Packit 13e616
	ib_smp_t *p_smp;
Packit 13e616
	ib_sm_info_t *p_smi = (ib_sm_info_t *) payload;
Packit 13e616
	ib_sm_info_t *sm_smi;
Packit 13e616
	ib_api_status_t status;
Packit 13e616
	osm_sm_signal_t sm_signal;
Packit 13e616
Packit 13e616
	OSM_LOG_ENTER(sm->p_log);
Packit 13e616
Packit 13e616
	CL_ASSERT(p_madw);
Packit 13e616
Packit 13e616
	memset(payload, 0, sizeof(payload));
Packit 13e616
Packit 13e616
	p_smp = osm_madw_get_smp_ptr(p_madw);
Packit 13e616
	sm_smi = ib_smp_get_payload_ptr(p_smp);
Packit 13e616
Packit 13e616
	if (p_smp->method != IB_MAD_METHOD_SET) {
Packit 13e616
		OSM_LOG(sm->p_log, OSM_LOG_ERROR, "ERR 2F03: "
Packit 13e616
			"Unsupported set method 0x%X\n", p_smp->method);
Packit 13e616
		goto Exit;
Packit 13e616
	}
Packit 13e616
Packit 13e616
	CL_PLOCK_ACQUIRE(sm->p_lock);
Packit 13e616
Packit 13e616
	p_smi->guid = sm->p_subn->sm_port_guid;
Packit 13e616
	p_smi->act_count = cl_hton32(sm->p_subn->p_osm->stats.qp0_mads_sent);
Packit 13e616
	p_smi->pri_state = (uint8_t) (sm->p_subn->sm_state |
Packit 13e616
				      sm->p_subn->opt.sm_priority << 4);
Packit 13e616
	p_smi->sm_key = sm->p_subn->opt.sm_key;
Packit 13e616
Packit 13e616
	/* Check the legality of the packet */
Packit 13e616
	status = smi_rcv_check_set_req_legality(p_smp);
Packit 13e616
	if (status != IB_SUCCESS) {
Packit 13e616
		OSM_LOG(sm->p_log, OSM_LOG_ERROR, "ERR 2F04: "
Packit 13e616
			"Check legality failed. AttributeModifier:0x%X RemoteState:%s\n",
Packit 13e616
			p_smp->attr_mod,
Packit 13e616
			osm_get_sm_mgr_state_str(ib_sminfo_get_state(sm_smi)));
Packit 13e616
		status = osm_resp_send(sm, p_madw, 7, payload);
Packit 13e616
		if (status != IB_SUCCESS)
Packit 13e616
			OSM_LOG(sm->p_log, OSM_LOG_ERROR, "ERR 2F05: "
Packit 13e616
				"Error sending SMInfo response (%s)\n",
Packit 13e616
				ib_get_err_str(status));
Packit 13e616
		CL_PLOCK_RELEASE(sm->p_lock);
Packit 13e616
		goto Exit;
Packit 13e616
	}
Packit 13e616
Packit 13e616
	/* translate from IB_SMINFO_ATTR to OSM_SM_SIGNAL */
Packit 13e616
	switch (p_smp->attr_mod) {
Packit 13e616
	case IB_SMINFO_ATTR_MOD_HANDOVER:
Packit 13e616
		sm_signal = OSM_SM_SIGNAL_HANDOVER;
Packit 13e616
		break;
Packit 13e616
	case IB_SMINFO_ATTR_MOD_ACKNOWLEDGE:
Packit 13e616
		sm_signal = OSM_SM_SIGNAL_ACKNOWLEDGE;
Packit 13e616
		break;
Packit 13e616
	case IB_SMINFO_ATTR_MOD_DISABLE:
Packit 13e616
		sm_signal = OSM_SM_SIGNAL_DISABLE;
Packit 13e616
		break;
Packit 13e616
	case IB_SMINFO_ATTR_MOD_STANDBY:
Packit 13e616
		sm_signal = OSM_SM_SIGNAL_STANDBY;
Packit 13e616
		break;
Packit 13e616
	case IB_SMINFO_ATTR_MOD_DISCOVER:
Packit 13e616
		sm_signal = OSM_SM_SIGNAL_DISCOVER;
Packit 13e616
		break;
Packit 13e616
	default:
Packit 13e616
		/*
Packit 13e616
		   This code shouldn't be reached - checked in the
Packit 13e616
		   check legality
Packit 13e616
		 */
Packit 13e616
		OSM_LOG(sm->p_log, OSM_LOG_ERROR, "ERR 2F06: "
Packit 13e616
			"THIS CODE SHOULD NOT BE REACHED!!\n");
Packit 13e616
		CL_PLOCK_RELEASE(sm->p_lock);
Packit 13e616
		goto Exit;
Packit 13e616
	}
Packit 13e616
Packit 13e616
	CL_PLOCK_RELEASE(sm->p_lock);
Packit 13e616
Packit 13e616
	/* check legality of the needed transition in the SM state machine */
Packit 13e616
	status = osm_sm_state_mgr_check_legality(sm, sm_signal);
Packit 13e616
	if (status != IB_SUCCESS) {
Packit 13e616
		OSM_LOG(sm->p_log, OSM_LOG_ERROR, "ERR 2F07: "
Packit 13e616
			"Failed check of legality of needed SM transition. "
Packit 13e616
			"AttributeModifier:0x%X RemoteState:%s\n",
Packit 13e616
			p_smp->attr_mod,
Packit 13e616
			osm_get_sm_mgr_state_str(ib_sminfo_get_state(sm_smi)));
Packit 13e616
		status = osm_resp_send(sm, p_madw, 7, payload);
Packit 13e616
		if (status != IB_SUCCESS)
Packit 13e616
			OSM_LOG(sm->p_log, OSM_LOG_ERROR, "ERR 2F08: "
Packit 13e616
				"Error sending SMInfo response (%s)\n",
Packit 13e616
				ib_get_err_str(status));
Packit 13e616
		goto Exit;
Packit 13e616
	}
Packit 13e616
Packit 13e616
	/* the SubnSet(SMInfo) command is ok. Send a response. */
Packit 13e616
	status = osm_resp_send(sm, p_madw, 0, payload);
Packit 13e616
	if (status != IB_SUCCESS)
Packit 13e616
		OSM_LOG(sm->p_log, OSM_LOG_ERROR, "ERR 2F09: "
Packit 13e616
			"Error sending SMInfo response (%s)\n",
Packit 13e616
			ib_get_err_str(status));
Packit 13e616
Packit 13e616
	/* it is a legal packet - act according to it */
Packit 13e616
Packit 13e616
	/* if the AttributeModifier is STANDBY - need to save on the sm in */
Packit 13e616
	/* the master_sm_guid variable - the guid of the current master. */
Packit 13e616
	if (p_smp->attr_mod == IB_SMINFO_ATTR_MOD_STANDBY) {
Packit 13e616
		OSM_LOG(sm->p_log, OSM_LOG_VERBOSE,
Packit 13e616
			"Received a STANDBY signal. Updating "
Packit 13e616
			"sm_state_mgr master_guid: 0x%016" PRIx64 "\n",
Packit 13e616
			cl_ntoh64(sm_smi->guid));
Packit 13e616
		CL_PLOCK_EXCL_ACQUIRE(sm->p_lock);
Packit 13e616
		sm->master_sm_guid = sm_smi->guid;
Packit 13e616
		CL_PLOCK_RELEASE(sm->p_lock);
Packit 13e616
	}
Packit 13e616
Packit 13e616
	status = osm_sm_state_mgr_process(sm, sm_signal);
Packit 13e616
Packit 13e616
	if (status != IB_SUCCESS)
Packit 13e616
		OSM_LOG(sm->p_log, OSM_LOG_ERROR, "ERR 2F10: "
Packit 13e616
			"Error in SM state transition (%s)\n",
Packit 13e616
			ib_get_err_str(status));
Packit 13e616
Packit 13e616
Exit:
Packit 13e616
	OSM_LOG_EXIT(sm->p_log);
Packit 13e616
}
Packit 13e616
Packit 13e616
static void smi_rcv_process_get_sm(IN osm_sm_t * sm,
Packit 13e616
				   IN const osm_remote_sm_t * p_sm,
Packit 13e616
				   boolean_t light_sweep)
Packit 13e616
{
Packit 13e616
	const ib_sm_info_t *p_smi;
Packit 13e616
Packit 13e616
	OSM_LOG_ENTER(sm->p_log);
Packit 13e616
Packit 13e616
	p_smi = &p_sm->smi;
Packit 13e616
Packit 13e616
	OSM_LOG(sm->p_log, OSM_LOG_VERBOSE,
Packit 13e616
		"Detected SM 0x%016" PRIx64 " in state %u (%s)\n",
Packit 13e616
		cl_ntoh64(p_smi->guid), ib_sminfo_get_state(p_smi),
Packit 13e616
		osm_get_sm_mgr_state_str(ib_sminfo_get_state(p_smi)));
Packit 13e616
Packit 13e616
	/* Check the state of this SM vs. our own. */
Packit 13e616
	switch (sm->p_subn->sm_state) {
Packit 13e616
	case IB_SMINFO_STATE_NOTACTIVE:
Packit 13e616
		break;
Packit 13e616
Packit 13e616
	case IB_SMINFO_STATE_DISCOVERING:
Packit 13e616
		switch (ib_sminfo_get_state(p_smi)) {
Packit 13e616
		case IB_SMINFO_STATE_NOTACTIVE:
Packit 13e616
			break;
Packit 13e616
		case IB_SMINFO_STATE_MASTER:
Packit 13e616
			sm->master_sm_found = 1;
Packit 13e616
			/* save on the sm the guid of the current master. */
Packit 13e616
			OSM_LOG(sm->p_log, OSM_LOG_VERBOSE,
Packit 13e616
				"Found master SM. Updating sm_state_mgr master_guid: 0x%016"
Packit 13e616
				PRIx64 "\n", cl_ntoh64(p_smi->guid));
Packit 13e616
			sm->master_sm_guid = p_smi->guid;
Packit 13e616
			break;
Packit 13e616
		case IB_SMINFO_STATE_DISCOVERING:
Packit 13e616
		case IB_SMINFO_STATE_STANDBY:
Packit 13e616
			if (smi_rcv_remote_sm_is_higher(sm, p_smi)) {
Packit 13e616
				/* the remote is a higher sm - need to stop sweeping */
Packit 13e616
				sm->master_sm_found = 1;
Packit 13e616
				/* save on the sm the guid of the higher SM we found - */
Packit 13e616
				/* we will poll it - as long as it lives - we should be in Standby. */
Packit 13e616
				OSM_LOG(sm->p_log, OSM_LOG_VERBOSE,
Packit 13e616
					"Found higher SM. Updating sm_state_mgr master_guid:"
Packit 13e616
					" 0x%016" PRIx64 "\n",
Packit 13e616
					cl_ntoh64(p_smi->guid));
Packit 13e616
				sm->master_sm_guid = p_smi->guid;
Packit 13e616
			}
Packit 13e616
			break;
Packit 13e616
		default:
Packit 13e616
			break;
Packit 13e616
		}
Packit 13e616
		break;
Packit 13e616
Packit 13e616
	case IB_SMINFO_STATE_STANDBY:
Packit 13e616
		/* if the guid of the SM that sent us this response is equal to the */
Packit 13e616
		/* p_sm_mgr->master_guid - then this is a signal that the polling */
Packit 13e616
		switch (ib_sminfo_get_state(p_smi)) {
Packit 13e616
		case IB_SMINFO_STATE_MASTER:
Packit 13e616
			/* This means the master is alive */
Packit 13e616
			/* Signal that to the SM state mgr */
Packit 13e616
			osm_sm_state_mgr_signal_master_is_alive(sm);
Packit 13e616
Packit 13e616
			if (!smi_rcv_remote_sm_is_higher(sm, p_smi))
Packit 13e616
				osm_send_trap144(sm,
Packit 13e616
						 TRAP_144_MASK_SM_PRIORITY_CHANGE);
Packit 13e616
			break;
Packit 13e616
		case IB_SMINFO_STATE_STANDBY:
Packit 13e616
			/* This should be the response from the sm we are polling. */
Packit 13e616
			/* If it is - then signal master is alive */
Packit 13e616
			if (sm->master_sm_guid == p_sm->smi.guid) {
Packit 13e616
				/* Make sure that it is an SM with higher priority than us.
Packit 13e616
				   If we started polling it when it was master, and it moved
Packit 13e616
				   to standby - then it might be with a lower priority than
Packit 13e616
				   us - and then we don't want to continue polling it. */
Packit 13e616
				if (smi_rcv_remote_sm_is_higher(sm, p_smi))
Packit 13e616
					osm_sm_state_mgr_signal_master_is_alive
Packit 13e616
					    (sm);
Packit 13e616
			}
Packit 13e616
			break;
Packit 13e616
		default:
Packit 13e616
			/* any other state - do nothing */
Packit 13e616
			break;
Packit 13e616
		}
Packit 13e616
		break;
Packit 13e616
Packit 13e616
	case IB_SMINFO_STATE_MASTER:
Packit 13e616
		switch (ib_sminfo_get_state(p_smi)) {
Packit 13e616
		case IB_SMINFO_STATE_MASTER:
Packit 13e616
			/* If this is a response due to our polling, this means that we are
Packit 13e616
			 * waiting for a handover from this SM, and it is still alive -
Packit 13e616
			 * signal that. If we detected the remote SM with higher priority
Packit 13e616
			 * we should init a heavy sweep in order to go STANDBY. If we
Packit 13e616
			 * detected a remote SM with lower priority, we should resend trap144
Packit 13e616
			 * as it might not get it and we don't want to wait for a HANDOVER
Packit 13e616
			 * forever.
Packit 13e616
			 */
Packit 13e616
			if (sm->polling_sm_guid) {
Packit 13e616
				if (smi_rcv_remote_sm_is_higher(sm, p_smi))
Packit 13e616
					sm->p_subn->force_heavy_sweep = TRUE;
Packit 13e616
				else {
Packit 13e616
					/* Update master_sm_guid to the GUID of the newly
Packit 13e616
					 * found MASTER SM and send trap 144 to it.
Packit 13e616
					 */
Packit 13e616
					sm->master_sm_guid = sm->polling_sm_guid;
Packit 13e616
					osm_send_trap144(sm, TRAP_144_MASK_SM_PRIORITY_CHANGE);
Packit 13e616
				}
Packit 13e616
				osm_sm_state_mgr_signal_master_is_alive(sm);
Packit 13e616
			} else {
Packit 13e616
				/* This is a response we got while sweeping the subnet.
Packit 13e616
				 *
Packit 13e616
				 * If this is during a heavy sweep, we will handle a case of
Packit 13e616
				 * handover needed later on, when the sweep is done and all
Packit 13e616
				 * SMs are recognized.
Packit 13e616
				 *
Packit 13e616
				 * If this is during a light sweep, initiate a heavy sweep
Packit 13e616
				 * to initiate handover scenarios.
Packit 13e616
				 *
Packit 13e616
				 * Note that it does not matter if the remote SM is lower
Packit 13e616
				 * or higher priority.  If it is lower priority, we must
Packit 13e616
				 * wait for it HANDOVER.  If it is higher priority, we need
Packit 13e616
				 * to HANDOVER to it.  Both cases are handled after doing
Packit 13e616
				 * a heavy sweep.
Packit 13e616
				 */
Packit 13e616
				if (light_sweep)
Packit 13e616
					sm->p_subn->force_heavy_sweep = TRUE;
Packit 13e616
			}
Packit 13e616
			break;
Packit 13e616
		case IB_SMINFO_STATE_STANDBY:
Packit 13e616
			if (light_sweep &&
Packit 13e616
			    smi_rcv_remote_sm_is_higher(sm, p_smi))
Packit 13e616
				sm->p_subn->force_heavy_sweep = TRUE;
Packit 13e616
			break;
Packit 13e616
		default:
Packit 13e616
			/* any other state - do nothing */
Packit 13e616
			break;
Packit 13e616
		}
Packit 13e616
		break;
Packit 13e616
Packit 13e616
	default:
Packit 13e616
		break;
Packit 13e616
	}
Packit 13e616
Packit 13e616
	OSM_LOG_EXIT(sm->p_log);
Packit 13e616
}
Packit 13e616
Packit 13e616
static void smi_rcv_process_get_response(IN osm_sm_t * sm,
Packit 13e616
					 IN const osm_madw_t * p_madw)
Packit 13e616
{
Packit 13e616
	const ib_smp_t *p_smp;
Packit 13e616
	const ib_sm_info_t *p_smi;
Packit 13e616
	cl_qmap_t *p_sm_tbl;
Packit 13e616
	osm_port_t *p_port;
Packit 13e616
	ib_net64_t port_guid;
Packit 13e616
	osm_remote_sm_t *p_sm;
Packit 13e616
	char buf[256];
Packit 13e616
Packit 13e616
	OSM_LOG_ENTER(sm->p_log);
Packit 13e616
Packit 13e616
	CL_ASSERT(p_madw);
Packit 13e616
Packit 13e616
	p_smp = osm_madw_get_smp_ptr(p_madw);
Packit 13e616
Packit 13e616
	if (p_smp->method != IB_MAD_METHOD_GET_RESP) {
Packit 13e616
		OSM_LOG(sm->p_log, OSM_LOG_ERROR, "ERR 2F11: "
Packit 13e616
			"Unsupported response method 0x%X\n", p_smp->method);
Packit 13e616
		goto Exit;
Packit 13e616
	}
Packit 13e616
Packit 13e616
	p_smi = ib_smp_get_payload_ptr(p_smp);
Packit 13e616
	p_sm_tbl = &sm->p_subn->sm_guid_tbl;
Packit 13e616
	port_guid = p_smi->guid;
Packit 13e616
Packit 13e616
	osm_dump_sm_info_v2(sm->p_log, p_smi, FILE_ID, OSM_LOG_DEBUG);
Packit 13e616
Packit 13e616
	/* Check that the sm_key of the found SM is the same as ours,
Packit 13e616
	   or is zero. If not - OpenSM should ignore this SM */
Packit 13e616
	if (sm->p_subn->opt.sm_key != 0 && p_smi->sm_key != sm->p_subn->opt.sm_key) {
Packit 13e616
		if (p_smp->mgmt_class == IB_MCLASS_SUBN_DIR)
Packit 13e616
			sprint_uint8_arr(buf, sizeof(buf),
Packit 13e616
				p_smp->initial_path, p_smp->hop_count + 1);
Packit 13e616
		else
Packit 13e616
			sprintf(buf, "LID %u",
Packit 13e616
				cl_ntoh16(p_madw->mad_addr.addr_type.smi.source_lid));
Packit 13e616
		OSM_LOG(sm->p_log, OSM_LOG_ERROR, "ERR 2F18: "
Packit 13e616
			"Got SM (%s) with sm_key 0x%016" PRIx64 " that doesn't match our "
Packit 13e616
			"local sm_key. Ignoring SMInfo\n", buf, cl_ntoh64(p_smi->sm_key));
Packit 13e616
		osm_log_v2(sm->p_log, OSM_LOG_SYS, FILE_ID,
Packit 13e616
			   "Found remote SM (%s) with non-matching sm_key\n", buf);
Packit 13e616
		goto Exit;
Packit 13e616
	}
Packit 13e616
Packit 13e616
	/* Determine if we already have another SM object for this SM. */
Packit 13e616
	CL_PLOCK_EXCL_ACQUIRE(sm->p_lock);
Packit 13e616
Packit 13e616
	p_port = osm_get_port_by_guid(sm->p_subn, port_guid);
Packit 13e616
	if (!p_port) {
Packit 13e616
		OSM_LOG(sm->p_log, OSM_LOG_ERROR, "ERR 2F12: "
Packit 13e616
			"No port object for this SM\n");
Packit 13e616
		goto _unlock_and_exit;
Packit 13e616
	}
Packit 13e616
Packit 13e616
	if (osm_port_get_guid(p_port) != p_smi->guid) {
Packit 13e616
		OSM_LOG(sm->p_log, OSM_LOG_ERROR, "ERR 2F13: "
Packit 13e616
			"Bogus SM port GUID, Expected 0x%016" PRIx64
Packit 13e616
			", Received 0x%016" PRIx64 "\n",
Packit 13e616
			cl_ntoh64(osm_port_get_guid(p_port)),
Packit 13e616
			cl_ntoh64(p_smi->guid));
Packit 13e616
		goto _unlock_and_exit;
Packit 13e616
	}
Packit 13e616
Packit 13e616
	if (port_guid == sm->p_subn->sm_port_guid) {
Packit 13e616
		OSM_LOG(sm->p_log, OSM_LOG_VERBOSE,
Packit 13e616
			"Self query response received - SM port 0x%016" PRIx64
Packit 13e616
			"\n", cl_ntoh64(port_guid));
Packit 13e616
		goto _unlock_and_exit;
Packit 13e616
	}
Packit 13e616
Packit 13e616
	p_sm = (osm_remote_sm_t *) cl_qmap_get(p_sm_tbl, port_guid);
Packit 13e616
	if (p_sm == (osm_remote_sm_t *) cl_qmap_end(p_sm_tbl)) {
Packit 13e616
		p_sm = malloc(sizeof(*p_sm));
Packit 13e616
		if (p_sm == NULL) {
Packit 13e616
			OSM_LOG(sm->p_log, OSM_LOG_ERROR, "ERR 2F14: "
Packit 13e616
				"Unable to allocate SM object\n");
Packit 13e616
			goto _unlock_and_exit;
Packit 13e616
		}
Packit 13e616
Packit 13e616
		osm_remote_sm_init(p_sm, p_smi);
Packit 13e616
Packit 13e616
		cl_qmap_insert(p_sm_tbl, port_guid, &p_sm->map_item);
Packit 13e616
	} else
Packit 13e616
		/* We already know this SM. Update the SMInfo attribute. */
Packit 13e616
		p_sm->smi = *p_smi;
Packit 13e616
Packit 13e616
	smi_rcv_process_get_sm(sm, p_sm,
Packit 13e616
			       osm_madw_get_smi_context_ptr(p_madw)->
Packit 13e616
			       light_sweep);
Packit 13e616
Packit 13e616
_unlock_and_exit:
Packit 13e616
	CL_PLOCK_RELEASE(sm->p_lock);
Packit 13e616
Packit 13e616
Exit:
Packit 13e616
	OSM_LOG_EXIT(sm->p_log);
Packit 13e616
}
Packit 13e616
Packit 13e616
static void smi_rcv_process_set_response(IN osm_sm_t * sm,
Packit 13e616
					 IN const osm_madw_t * p_madw)
Packit 13e616
{
Packit 13e616
	const ib_smp_t *p_smp;
Packit 13e616
	const ib_sm_info_t *p_smi;
Packit 13e616
Packit 13e616
	OSM_LOG_ENTER(sm->p_log);
Packit 13e616
Packit 13e616
	CL_ASSERT(p_madw);
Packit 13e616
Packit 13e616
	p_smp = osm_madw_get_smp_ptr(p_madw);
Packit 13e616
	if (ib_smp_get_status(p_smp)) {
Packit 13e616
		OSM_LOG(sm->p_log, OSM_LOG_DEBUG,
Packit 13e616
			"MAD status 0x%x received\n",
Packit 13e616
			cl_ntoh16(ib_smp_get_status(p_smp)));
Packit 13e616
		goto Exit;
Packit 13e616
	}
Packit 13e616
Packit 13e616
	if (p_smp->method != IB_MAD_METHOD_GET_RESP) {
Packit 13e616
		OSM_LOG(sm->p_log, OSM_LOG_ERROR, "ERR 2F16: "
Packit 13e616
			"Unsupported response method 0x%X\n", p_smp->method);
Packit 13e616
		goto Exit;
Packit 13e616
	}
Packit 13e616
Packit 13e616
	p_smi = ib_smp_get_payload_ptr(p_smp);
Packit 13e616
	osm_dump_sm_info_v2(sm->p_log, p_smi, FILE_ID, OSM_LOG_DEBUG);
Packit 13e616
Packit 13e616
	/* Check the AttributeModifier */
Packit 13e616
	if (p_smp->attr_mod != IB_SMINFO_ATTR_MOD_HANDOVER) {
Packit 13e616
		OSM_LOG(sm->p_log, OSM_LOG_ERROR, "ERR 2F17: "
Packit 13e616
			"Unsupported attribute modifier 0x%X, "
Packit 13e616
			"expected ATTR_MOD_HANDOVER\n",
Packit 13e616
			p_smp->attr_mod);
Packit 13e616
		goto Exit;
Packit 13e616
	}
Packit 13e616
Packit 13e616
	/* This is a response on a HANDOVER request - Nothing to do. */
Packit 13e616
Packit 13e616
Exit:
Packit 13e616
	OSM_LOG_EXIT(sm->p_log);
Packit 13e616
}
Packit 13e616
Packit 13e616
void osm_sminfo_rcv_process(IN void *context, IN void *data)
Packit 13e616
{
Packit 13e616
	osm_sm_t *sm = context;
Packit 13e616
	osm_madw_t *p_madw = data;
Packit 13e616
	ib_smp_t *p_smp;
Packit 13e616
	osm_smi_context_t *p_smi_context;
Packit 13e616
Packit 13e616
	OSM_LOG_ENTER(sm->p_log);
Packit 13e616
Packit 13e616
	CL_ASSERT(p_madw);
Packit 13e616
Packit 13e616
	p_smp = osm_madw_get_smp_ptr(p_madw);
Packit 13e616
	if (ib_smp_get_status(p_smp)) {
Packit 13e616
		OSM_LOG(sm->p_log, OSM_LOG_DEBUG,
Packit 13e616
			"MAD status 0x%x received\n",
Packit 13e616
			cl_ntoh16(ib_smp_get_status(p_smp)));
Packit 13e616
		goto Exit;
Packit 13e616
	}
Packit 13e616
Packit 13e616
	/* Determine if this is a request for our own SMInfo or if
Packit 13e616
	   this is a response to our request for another SM's SMInfo. */
Packit 13e616
	if (ib_smp_is_response(p_smp)) {
Packit 13e616
		const ib_sm_info_t *p_smi = ib_smp_get_payload_ptr(p_smp);
Packit 13e616
Packit 13e616
		/* Get the context - to see if this is a response to a Get or Set method */
Packit 13e616
		p_smi_context = osm_madw_get_smi_context_ptr(p_madw);
Packit 13e616
Packit 13e616
		/* Verify that response is from expected port and there is
Packit 13e616
		   no port moving issue. */
Packit 13e616
		if (p_smi_context->port_guid != p_smi->guid) {
Packit 13e616
			OSM_LOG(sm->p_log, OSM_LOG_ERROR, "ERR 2F19: "
Packit 13e616
				"Unexpected SM port GUID in response"
Packit 13e616
				", Expected 0x%016" PRIx64
Packit 13e616
				", Received 0x%016" PRIx64 "\n",
Packit 13e616
				cl_ntoh64(p_smi_context->port_guid),
Packit 13e616
				cl_ntoh64(p_smi->guid));
Packit 13e616
			goto Exit;
Packit 13e616
		}
Packit 13e616
Packit 13e616
		if (p_smi_context->set_method == FALSE)
Packit 13e616
			/* this is a response to a Get method */
Packit 13e616
			smi_rcv_process_get_response(sm, p_madw);
Packit 13e616
		else
Packit 13e616
			/* this is a response to a Set method */
Packit 13e616
			smi_rcv_process_set_response(sm, p_madw);
Packit 13e616
	} else {
Packit 13e616
		osm_port_t * p_port;
Packit 13e616
		ib_net64_t my_mkey;
Packit 13e616
		uint8_t mpb;
Packit 13e616
		char buf[256];
Packit 13e616
Packit 13e616
		if(!(p_port = osm_get_port_by_guid(sm->p_subn,
Packit 13e616
						   sm->p_subn->sm_port_guid)))
Packit 13e616
			goto Exit;
Packit 13e616
Packit 13e616
		if (!p_port->p_physp)
Packit 13e616
			goto Exit;
Packit 13e616
Packit 13e616
		my_mkey = ib_port_info_get_m_key(&p_port->p_physp->port_info);
Packit 13e616
		mpb = my_mkey ? ib_port_info_get_mpb(&p_port->p_physp->port_info) : 0;
Packit 13e616
Packit 13e616
		if (p_smp->method == IB_MAD_METHOD_GET) {
Packit 13e616
			/* M-Key Authentication */
Packit 13e616
			if (my_mkey && mpb > 1 && my_mkey != p_smp->m_key) {
Packit 13e616
				if (p_smp->mgmt_class == IB_MCLASS_SUBN_DIR)
Packit 13e616
					sprint_uint8_arr(buf, sizeof(buf),
Packit 13e616
					      p_smp->return_path, p_smp->hop_count + 1);
Packit 13e616
				else
Packit 13e616
					sprintf(buf, "LID %u",
Packit 13e616
						cl_ntoh16(p_madw->mad_addr.addr_type.smi.source_lid));
Packit 13e616
				OSM_LOG(sm->p_log, OSM_LOG_ERROR, "ERR 2F1A: "
Packit 13e616
					"SMInfo(GET) sender (%s) authentication failure."
Packit 13e616
					"Ignoring SMInfo\n", buf);
Packit 13e616
				goto Exit;
Packit 13e616
			}
Packit 13e616
			/* If protection bits == 1 but MKEY mismatch, return SM-KEY = 0 */
Packit 13e616
			if (my_mkey && mpb == 1 && my_mkey != p_smp->m_key)
Packit 13e616
				smi_rcv_process_get_request(sm, p_madw, FALSE);
Packit 13e616
			else
Packit 13e616
				smi_rcv_process_get_request(sm, p_madw, TRUE);
Packit 13e616
		} else {
Packit 13e616
			/* M-Key Authentication */
Packit 13e616
			if (my_mkey && my_mkey != p_smp->m_key) {
Packit 13e616
				if (p_smp->mgmt_class == IB_MCLASS_SUBN_DIR)
Packit 13e616
					sprint_uint8_arr(buf, sizeof(buf),
Packit 13e616
					      p_smp->return_path, p_smp->hop_count + 1);
Packit 13e616
				else
Packit 13e616
					sprintf(buf, "LID %u",
Packit 13e616
						cl_ntoh16(p_madw->mad_addr.addr_type.smi.source_lid));
Packit 13e616
				OSM_LOG(sm->p_log, OSM_LOG_ERROR, "ERR 2F1B: "
Packit 13e616
					"SMInfo(SET) sender (%s) authentication failure."
Packit 13e616
					"Ignoring SMInfo\n", buf);
Packit 13e616
				goto Exit;
Packit 13e616
			}
Packit 13e616
			/* This should be a SubnSet request */
Packit 13e616
			smi_rcv_process_set_request(sm, p_madw);
Packit 13e616
		}
Packit 13e616
	}
Packit 13e616
Packit 13e616
Exit:
Packit 13e616
	OSM_LOG_EXIT(sm->p_log);
Packit 13e616
}