Blame opensm/osm_sa_sw_info_record.c

Packit Service 54dbc3
/*
Packit Service 54dbc3
 * Copyright (c) 2004-2009 Voltaire, Inc. All rights reserved.
Packit Service 54dbc3
 * Copyright (c) 2002-2005 Mellanox Technologies LTD. All rights reserved.
Packit Service 54dbc3
 * Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
Packit Service 54dbc3
 * Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved.
Packit Service 54dbc3
 *
Packit Service 54dbc3
 * This software is available to you under a choice of one of two
Packit Service 54dbc3
 * licenses.  You may choose to be licensed under the terms of the GNU
Packit Service 54dbc3
 * General Public License (GPL) Version 2, available from the file
Packit Service 54dbc3
 * COPYING in the main directory of this source tree, or the
Packit Service 54dbc3
 * OpenIB.org BSD license below:
Packit Service 54dbc3
 *
Packit Service 54dbc3
 *     Redistribution and use in source and binary forms, with or
Packit Service 54dbc3
 *     without modification, are permitted provided that the following
Packit Service 54dbc3
 *     conditions are met:
Packit Service 54dbc3
 *
Packit Service 54dbc3
 *      - Redistributions of source code must retain the above
Packit Service 54dbc3
 *        copyright notice, this list of conditions and the following
Packit Service 54dbc3
 *        disclaimer.
Packit Service 54dbc3
 *
Packit Service 54dbc3
 *      - Redistributions in binary form must reproduce the above
Packit Service 54dbc3
 *        copyright notice, this list of conditions and the following
Packit Service 54dbc3
 *        disclaimer in the documentation and/or other materials
Packit Service 54dbc3
 *        provided with the distribution.
Packit Service 54dbc3
 *
Packit Service 54dbc3
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Packit Service 54dbc3
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
Packit Service 54dbc3
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Packit Service 54dbc3
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
Packit Service 54dbc3
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
Packit Service 54dbc3
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
Packit Service 54dbc3
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
Packit Service 54dbc3
 * SOFTWARE.
Packit Service 54dbc3
 *
Packit Service 54dbc3
 */
Packit Service 54dbc3
Packit Service 54dbc3
/*
Packit Service 54dbc3
 * Abstract:
Packit Service 54dbc3
 *    Implementation of osm_sir_rcv_t.
Packit Service 54dbc3
 * This object represents the SwitchInfo Receiver object.
Packit Service 54dbc3
 * This object is part of the opensm family of objects.
Packit Service 54dbc3
 */
Packit Service 54dbc3
Packit Service 54dbc3
#if HAVE_CONFIG_H
Packit Service 54dbc3
#  include <config.h>
Packit Service 54dbc3
#endif				/* HAVE_CONFIG_H */
Packit Service 54dbc3
Packit Service 54dbc3
#include <string.h>
Packit Service 54dbc3
#include <iba/ib_types.h>
Packit Service 54dbc3
#include <complib/cl_debug.h>
Packit Service 54dbc3
#include <complib/cl_qlist.h>
Packit Service 54dbc3
#include <opensm/osm_file_ids.h>
Packit Service 54dbc3
#define FILE_ID OSM_FILE_SA_SW_INFO_RECORD_C
Packit Service 54dbc3
#include <vendor/osm_vendor_api.h>
Packit Service 54dbc3
#include <opensm/osm_node.h>
Packit Service 54dbc3
#include <opensm/osm_helper.h>
Packit Service 54dbc3
#include <opensm/osm_pkey.h>
Packit Service 54dbc3
#include <opensm/osm_sa.h>
Packit Service 54dbc3
Packit Service 54dbc3
#define SA_SIR_RESP_SIZE SA_ITEM_RESP_SIZE(swinfo_rec)
Packit Service 54dbc3
Packit Service 54dbc3
typedef struct osm_sir_search_ctxt {
Packit Service 54dbc3
	const ib_switch_info_record_t *p_rcvd_rec;
Packit Service 54dbc3
	ib_net64_t comp_mask;
Packit Service 54dbc3
	cl_qlist_t *p_list;
Packit Service 54dbc3
	osm_sa_t *sa;
Packit Service 54dbc3
	const osm_physp_t *p_req_physp;
Packit Service 54dbc3
} osm_sir_search_ctxt_t;
Packit Service 54dbc3
Packit Service 54dbc3
static ib_api_status_t sir_rcv_new_sir(IN osm_sa_t * sa,
Packit Service 54dbc3
				       IN const osm_switch_t * p_sw,
Packit Service 54dbc3
				       IN cl_qlist_t * p_list,
Packit Service 54dbc3
				       IN ib_net16_t lid)
Packit Service 54dbc3
{
Packit Service 54dbc3
	osm_sa_item_t *p_rec_item;
Packit Service 54dbc3
	ib_api_status_t status = IB_SUCCESS;
Packit Service 54dbc3
Packit Service 54dbc3
	OSM_LOG_ENTER(sa->p_log);
Packit Service 54dbc3
Packit Service 54dbc3
	p_rec_item = malloc(SA_SIR_RESP_SIZE);
Packit Service 54dbc3
	if (p_rec_item == NULL) {
Packit Service 54dbc3
		OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 5308: "
Packit Service 54dbc3
			"rec_item alloc failed\n");
Packit Service 54dbc3
		status = IB_INSUFFICIENT_RESOURCES;
Packit Service 54dbc3
		goto Exit;
Packit Service 54dbc3
	}
Packit Service 54dbc3
Packit Service 54dbc3
	OSM_LOG(sa->p_log, OSM_LOG_DEBUG,
Packit Service 54dbc3
		"New SwitchInfoRecord: lid %u\n", cl_ntoh16(lid));
Packit Service 54dbc3
Packit Service 54dbc3
	memset(p_rec_item, 0, SA_SIR_RESP_SIZE);
Packit Service 54dbc3
Packit Service 54dbc3
	p_rec_item->resp.swinfo_rec.lid = lid;
Packit Service 54dbc3
	p_rec_item->resp.swinfo_rec.switch_info = p_sw->switch_info;
Packit Service 54dbc3
Packit Service 54dbc3
	cl_qlist_insert_tail(p_list, &p_rec_item->list_item);
Packit Service 54dbc3
Packit Service 54dbc3
Exit:
Packit Service 54dbc3
	OSM_LOG_EXIT(sa->p_log);
Packit Service 54dbc3
	return status;
Packit Service 54dbc3
}
Packit Service 54dbc3
Packit Service 54dbc3
static void sir_rcv_create_sir(IN osm_sa_t * sa, IN const osm_switch_t * p_sw,
Packit Service 54dbc3
			       IN cl_qlist_t * p_list, IN ib_net16_t match_lid,
Packit Service 54dbc3
			       IN const osm_physp_t * p_req_physp)
Packit Service 54dbc3
{
Packit Service 54dbc3
	osm_port_t *p_port;
Packit Service 54dbc3
	const osm_physp_t *p_physp;
Packit Service 54dbc3
	uint16_t match_lid_ho;
Packit Service 54dbc3
	ib_net16_t min_lid_ho;
Packit Service 54dbc3
	ib_net16_t max_lid_ho;
Packit Service 54dbc3
Packit Service 54dbc3
	OSM_LOG_ENTER(sa->p_log);
Packit Service 54dbc3
Packit Service 54dbc3
	OSM_LOG(sa->p_log, OSM_LOG_DEBUG,
Packit Service 54dbc3
		"Looking for SwitchInfoRecord with LID: %u\n",
Packit Service 54dbc3
		cl_ntoh16(match_lid));
Packit Service 54dbc3
Packit Service 54dbc3
	/* In switches, the port guid is the node guid. */
Packit Service 54dbc3
	p_port =
Packit Service 54dbc3
	    osm_get_port_by_guid(sa->p_subn, p_sw->p_node->node_info.port_guid);
Packit Service 54dbc3
	if (!p_port) {
Packit Service 54dbc3
		OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 530A: "
Packit Service 54dbc3
			"Failed to find Port by Node Guid:0x%016" PRIx64
Packit Service 54dbc3
			"\n", cl_ntoh64(p_sw->p_node->node_info.node_guid));
Packit Service 54dbc3
		goto Exit;
Packit Service 54dbc3
	}
Packit Service 54dbc3
Packit Service 54dbc3
	/* check that the requester physp and the current physp are under
Packit Service 54dbc3
	   the same partition. */
Packit Service 54dbc3
	p_physp = p_port->p_physp;
Packit Service 54dbc3
	if (!p_physp) {
Packit Service 54dbc3
		OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 530B: "
Packit Service 54dbc3
			"Failed to find default physical Port by Node Guid:0x%016"
Packit Service 54dbc3
			PRIx64 "\n",
Packit Service 54dbc3
			cl_ntoh64(p_sw->p_node->node_info.node_guid));
Packit Service 54dbc3
		goto Exit;
Packit Service 54dbc3
	}
Packit Service 54dbc3
	if (!osm_physp_share_pkey(sa->p_log, p_req_physp, p_physp,
Packit Service 54dbc3
				  sa->p_subn->opt.allow_both_pkeys))
Packit Service 54dbc3
		goto Exit;
Packit Service 54dbc3
Packit Service 54dbc3
	/* get the port 0 of the switch */
Packit Service 54dbc3
	osm_port_get_lid_range_ho(p_port, &min_lid_ho, &max_lid_ho);
Packit Service 54dbc3
Packit Service 54dbc3
	match_lid_ho = cl_ntoh16(match_lid);
Packit Service 54dbc3
	if (match_lid_ho) {
Packit Service 54dbc3
		/*
Packit Service 54dbc3
		   We validate that the lid belongs to this switch.
Packit Service 54dbc3
		 */
Packit Service 54dbc3
		OSM_LOG(sa->p_log, OSM_LOG_DEBUG,
Packit Service 54dbc3
			"Comparing LID: %u <= %u <= %u\n",
Packit Service 54dbc3
			min_lid_ho, match_lid_ho, max_lid_ho);
Packit Service 54dbc3
Packit Service 54dbc3
		if (match_lid_ho < min_lid_ho || match_lid_ho > max_lid_ho)
Packit Service 54dbc3
			goto Exit;
Packit Service 54dbc3
Packit Service 54dbc3
	}
Packit Service 54dbc3
Packit Service 54dbc3
	sir_rcv_new_sir(sa, p_sw, p_list, osm_port_get_base_lid(p_port));
Packit Service 54dbc3
Packit Service 54dbc3
Exit:
Packit Service 54dbc3
	OSM_LOG_EXIT(sa->p_log);
Packit Service 54dbc3
}
Packit Service 54dbc3
Packit Service 54dbc3
static void sir_rcv_by_comp_mask(IN cl_map_item_t * p_map_item, IN void *cxt)
Packit Service 54dbc3
{
Packit Service 54dbc3
	const osm_sir_search_ctxt_t *p_ctxt = cxt;
Packit Service 54dbc3
	const osm_switch_t *p_sw = (osm_switch_t *) p_map_item;
Packit Service 54dbc3
	const ib_switch_info_record_t *const p_rcvd_rec = p_ctxt->p_rcvd_rec;
Packit Service 54dbc3
	const osm_physp_t *const p_req_physp = p_ctxt->p_req_physp;
Packit Service 54dbc3
	osm_sa_t *sa = p_ctxt->sa;
Packit Service 54dbc3
	ib_net64_t const comp_mask = p_ctxt->comp_mask;
Packit Service 54dbc3
	ib_net16_t match_lid = 0;
Packit Service 54dbc3
Packit Service 54dbc3
	OSM_LOG_ENTER(p_ctxt->sa->p_log);
Packit Service 54dbc3
Packit Service 54dbc3
	osm_dump_switch_info_v2(p_ctxt->sa->p_log, &p_sw->switch_info,
Packit Service 54dbc3
			        FILE_ID, OSM_LOG_VERBOSE);
Packit Service 54dbc3
Packit Service 54dbc3
	if (comp_mask & IB_SWIR_COMPMASK_LID) {
Packit Service 54dbc3
		match_lid = p_rcvd_rec->lid;
Packit Service 54dbc3
		if (!match_lid)
Packit Service 54dbc3
			goto Exit;
Packit Service 54dbc3
	}
Packit Service 54dbc3
Packit Service 54dbc3
	sir_rcv_create_sir(sa, p_sw, p_ctxt->p_list, match_lid, p_req_physp);
Packit Service 54dbc3
Packit Service 54dbc3
Exit:
Packit Service 54dbc3
	OSM_LOG_EXIT(p_ctxt->sa->p_log);
Packit Service 54dbc3
}
Packit Service 54dbc3
Packit Service 54dbc3
void osm_sir_rcv_process(IN void *ctx, IN void *data)
Packit Service 54dbc3
{
Packit Service 54dbc3
	osm_sa_t *sa = ctx;
Packit Service 54dbc3
	osm_madw_t *p_madw = data;
Packit Service 54dbc3
	const ib_sa_mad_t *sad_mad;
Packit Service 54dbc3
	const ib_switch_info_record_t *p_rcvd_rec;
Packit Service 54dbc3
	cl_qlist_t rec_list;
Packit Service 54dbc3
	osm_sir_search_ctxt_t context;
Packit Service 54dbc3
	osm_physp_t *p_req_physp;
Packit Service 54dbc3
Packit Service 54dbc3
	CL_ASSERT(sa);
Packit Service 54dbc3
Packit Service 54dbc3
	OSM_LOG_ENTER(sa->p_log);
Packit Service 54dbc3
Packit Service 54dbc3
	CL_ASSERT(p_madw);
Packit Service 54dbc3
Packit Service 54dbc3
	sad_mad = osm_madw_get_sa_mad_ptr(p_madw);
Packit Service 54dbc3
	p_rcvd_rec =
Packit Service 54dbc3
	    (ib_switch_info_record_t *) ib_sa_mad_get_payload_ptr(sad_mad);
Packit Service 54dbc3
Packit Service 54dbc3
	CL_ASSERT(sad_mad->attr_id == IB_MAD_ATTR_SWITCH_INFO_RECORD);
Packit Service 54dbc3
Packit Service 54dbc3
	/* we only support SubnAdmGet and SubnAdmGetTable methods */
Packit Service 54dbc3
	if (sad_mad->method != IB_MAD_METHOD_GET &&
Packit Service 54dbc3
	    sad_mad->method != IB_MAD_METHOD_GETTABLE) {
Packit Service 54dbc3
		OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 5305: "
Packit Service 54dbc3
			"Unsupported Method (%s) for SwitchInfoRecord request\n",
Packit Service 54dbc3
			ib_get_sa_method_str(sad_mad->method));
Packit Service 54dbc3
		osm_sa_send_error(sa, p_madw, IB_MAD_STATUS_UNSUP_METHOD_ATTR);
Packit Service 54dbc3
		goto Exit;
Packit Service 54dbc3
	}
Packit Service 54dbc3
Packit Service 54dbc3
	cl_plock_acquire(sa->p_lock);
Packit Service 54dbc3
Packit Service 54dbc3
	/* update the requester physical port */
Packit Service 54dbc3
	p_req_physp = osm_get_physp_by_mad_addr(sa->p_log, sa->p_subn,
Packit Service 54dbc3
						osm_madw_get_mad_addr_ptr
Packit Service 54dbc3
						(p_madw));
Packit Service 54dbc3
	if (p_req_physp == NULL) {
Packit Service 54dbc3
		cl_plock_release(sa->p_lock);
Packit Service 54dbc3
		OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 5304: "
Packit Service 54dbc3
			"Cannot find requester physical port\n");
Packit Service 54dbc3
		goto Exit;
Packit Service 54dbc3
	}
Packit Service 54dbc3
Packit Service 54dbc3
	if (OSM_LOG_IS_ACTIVE_V2(sa->p_log, OSM_LOG_DEBUG)) {
Packit Service 54dbc3
		OSM_LOG(sa->p_log, OSM_LOG_DEBUG,
Packit Service 54dbc3
			"Requester port GUID 0x%" PRIx64 "\n",
Packit Service 54dbc3
			cl_ntoh64(osm_physp_get_port_guid(p_req_physp)));
Packit Service 54dbc3
		osm_dump_switch_info_record_v2(sa->p_log, p_rcvd_rec,
Packit Service 54dbc3
					       FILE_ID, OSM_LOG_DEBUG);
Packit Service 54dbc3
	}
Packit Service 54dbc3
Packit Service 54dbc3
	cl_qlist_init(&rec_list);
Packit Service 54dbc3
Packit Service 54dbc3
	context.p_rcvd_rec = p_rcvd_rec;
Packit Service 54dbc3
	context.p_list = &rec_list;
Packit Service 54dbc3
	context.comp_mask = sad_mad->comp_mask;
Packit Service 54dbc3
	context.sa = sa;
Packit Service 54dbc3
	context.p_req_physp = p_req_physp;
Packit Service 54dbc3
Packit Service 54dbc3
	/* Go over all switches */
Packit Service 54dbc3
	cl_qmap_apply_func(&sa->p_subn->sw_guid_tbl, sir_rcv_by_comp_mask,
Packit Service 54dbc3
			   &context);
Packit Service 54dbc3
Packit Service 54dbc3
	cl_plock_release(sa->p_lock);
Packit Service 54dbc3
Packit Service 54dbc3
	osm_sa_respond(sa, p_madw, sizeof(ib_switch_info_record_t), &rec_list);
Packit Service 54dbc3
Packit Service 54dbc3
Exit:
Packit Service 54dbc3
	OSM_LOG_EXIT(sa->p_log);
Packit Service 54dbc3
}