1321936Shselasky/*
2321936Shselasky * Copyright (c) 2004-2009 Voltaire, Inc. All rights reserved.
3321936Shselasky * Copyright (c) 2002-2012 Mellanox Technologies LTD. All rights reserved.
4321936Shselasky * Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
5321936Shselasky *
6321936Shselasky * This software is available to you under a choice of one of two
7321936Shselasky * licenses.  You may choose to be licensed under the terms of the GNU
8321936Shselasky * General Public License (GPL) Version 2, available from the file
9321936Shselasky * COPYING in the main directory of this source tree, or the
10321936Shselasky * OpenIB.org BSD license below:
11321936Shselasky *
12321936Shselasky *     Redistribution and use in source and binary forms, with or
13321936Shselasky *     without modification, are permitted provided that the following
14321936Shselasky *     conditions are met:
15321936Shselasky *
16321936Shselasky *      - Redistributions of source code must retain the above
17321936Shselasky *        copyright notice, this list of conditions and the following
18321936Shselasky *        disclaimer.
19321936Shselasky *
20321936Shselasky *      - Redistributions in binary form must reproduce the above
21321936Shselasky *        copyright notice, this list of conditions and the following
22321936Shselasky *        disclaimer in the documentation and/or other materials
23321936Shselasky *        provided with the distribution.
24321936Shselasky *
25321936Shselasky * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26321936Shselasky * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27321936Shselasky * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28321936Shselasky * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29321936Shselasky * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30321936Shselasky * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31321936Shselasky * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32321936Shselasky * SOFTWARE.
33321936Shselasky *
34321936Shselasky */
35321936Shselasky
36321936Shselasky/*
37321936Shselasky * Abstract:
38321936Shselasky *    Implementation of osm_gi_rcv_t.
39321936Shselasky * This object represents the GUIDInfo Receiver object.
40321936Shselasky * This object is part of the opensm family of objects.
41321936Shselasky */
42321936Shselasky
43321936Shselasky#if HAVE_CONFIG_H
44321936Shselasky#  include <config.h>
45321936Shselasky#endif				/* HAVE_CONFIG_H */
46321936Shselasky
47321936Shselasky#include <string.h>
48321936Shselasky#include <stdlib.h>
49321936Shselasky#include <iba/ib_types.h>
50321936Shselasky#include <complib/cl_qmap.h>
51321936Shselasky#include <complib/cl_passivelock.h>
52321936Shselasky#include <complib/cl_debug.h>
53321936Shselasky#include <opensm/osm_file_ids.h>
54321936Shselasky#define FILE_ID OSM_FILE_GUID_INFO_RCV_C
55321936Shselasky#include <vendor/osm_vendor_api.h>
56321936Shselasky#include <opensm/osm_madw.h>
57321936Shselasky#include <opensm/osm_log.h>
58321936Shselasky#include <opensm/osm_node.h>
59321936Shselasky#include <opensm/osm_subnet.h>
60321936Shselasky#include <opensm/osm_mad_pool.h>
61321936Shselasky#include <opensm/osm_msgdef.h>
62321936Shselasky#include <opensm/osm_helper.h>
63321936Shselasky#include <opensm/osm_remote_sm.h>
64321936Shselasky#include <opensm/osm_opensm.h>
65321936Shselasky
66321936Shselaskyvoid osm_gi_rcv_process(IN void *context, IN void *data)
67321936Shselasky{
68321936Shselasky	osm_sm_t *sm = context;
69321936Shselasky	osm_madw_t *p_madw = data;
70321936Shselasky	ib_guid_info_t *p_gi;
71321936Shselasky	ib_smp_t *p_smp;
72321936Shselasky	osm_port_t *p_port;
73321936Shselasky	osm_gi_context_t *p_context;
74321936Shselasky	ib_net64_t port_guid, node_guid;
75321936Shselasky	uint8_t block_num;
76321936Shselasky
77321936Shselasky	CL_ASSERT(sm);
78321936Shselasky
79321936Shselasky	OSM_LOG_ENTER(sm->p_log);
80321936Shselasky
81321936Shselasky	CL_ASSERT(p_madw);
82321936Shselasky
83321936Shselasky	p_smp = osm_madw_get_smp_ptr(p_madw);
84321936Shselasky	p_context = osm_madw_get_gi_context_ptr(p_madw);
85321936Shselasky	p_gi = ib_smp_get_payload_ptr(p_smp);
86321936Shselasky
87321936Shselasky	CL_ASSERT(p_smp->attr_id == IB_MAD_ATTR_GUID_INFO);
88321936Shselasky
89321936Shselasky	block_num = (uint8_t) cl_ntoh32(p_smp->attr_mod);
90321936Shselasky
91321936Shselasky	port_guid = p_context->port_guid;
92321936Shselasky	node_guid = p_context->node_guid;
93321936Shselasky
94321936Shselasky	osm_dump_guid_info_v2(sm->p_log, node_guid, port_guid, block_num, p_gi,
95321936Shselasky			      FILE_ID, OSM_LOG_DEBUG);
96321936Shselasky
97321936Shselasky	if (ib_smp_get_status(p_smp)) {
98321936Shselasky		OSM_LOG(sm->p_log, OSM_LOG_DEBUG,
99321936Shselasky			"MAD status 0x%x received\n",
100321936Shselasky			cl_ntoh16(ib_smp_get_status(p_smp)));
101321936Shselasky		goto Exit;
102321936Shselasky	}
103321936Shselasky
104321936Shselasky	CL_PLOCK_EXCL_ACQUIRE(sm->p_lock);
105321936Shselasky	p_port = osm_get_port_by_guid(sm->p_subn, port_guid);
106321936Shselasky	if (!p_port) {
107321936Shselasky		CL_PLOCK_RELEASE(sm->p_lock);
108321936Shselasky		OSM_LOG(sm->p_log, OSM_LOG_ERROR, "ERR 4701: "
109321936Shselasky			"No port object for port with GUID 0x%" PRIx64
110321936Shselasky			"\n\t\t\t\tfor parent node GUID 0x%" PRIx64
111321936Shselasky			", TID 0x%" PRIx64 "\n",
112321936Shselasky			cl_ntoh64(port_guid), cl_ntoh64(node_guid),
113321936Shselasky			cl_ntoh64(p_smp->trans_id));
114321936Shselasky		goto Exit;
115321936Shselasky	}
116321936Shselasky
117321936Shselasky	CL_PLOCK_RELEASE(sm->p_lock);
118321936Shselasky
119321936ShselaskyExit:
120321936Shselasky	/*
121321936Shselasky	   Release the lock before jumping here!!
122321936Shselasky	 */
123321936Shselasky	OSM_LOG_EXIT(sm->p_log);
124321936Shselasky}
125