1321936Shselasky/*
2321936Shselasky * Copyright (c) 2004-2009 Voltaire, Inc. All rights reserved.
3321936Shselasky * Copyright (c) 2002-2007 Mellanox Technologies LTD. All rights reserved.
4321936Shselasky * Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
5321936Shselasky * Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved.
6321936Shselasky *
7321936Shselasky * This software is available to you under a choice of one of two
8321936Shselasky * licenses.  You may choose to be licensed under the terms of the GNU
9321936Shselasky * General Public License (GPL) Version 2, available from the file
10321936Shselasky * COPYING in the main directory of this source tree, or the
11321936Shselasky * OpenIB.org BSD license below:
12321936Shselasky *
13321936Shselasky *     Redistribution and use in source and binary forms, with or
14321936Shselasky *     without modification, are permitted provided that the following
15321936Shselasky *     conditions are met:
16321936Shselasky *
17321936Shselasky *      - Redistributions of source code must retain the above
18321936Shselasky *        copyright notice, this list of conditions and the following
19321936Shselasky *        disclaimer.
20321936Shselasky *
21321936Shselasky *      - Redistributions in binary form must reproduce the above
22321936Shselasky *        copyright notice, this list of conditions and the following
23321936Shselasky *        disclaimer in the documentation and/or other materials
24321936Shselasky *        provided with the distribution.
25321936Shselasky *
26321936Shselasky * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27321936Shselasky * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28321936Shselasky * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29321936Shselasky * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
30321936Shselasky * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
31321936Shselasky * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
32321936Shselasky * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33321936Shselasky * SOFTWARE.
34321936Shselasky *
35321936Shselasky */
36321936Shselasky
37321936Shselasky/*
38321936Shselasky * Abstract:
39321936Shselasky *    Implementation of osm_nd_rcv_t.
40321936Shselasky * This object represents the NodeDescription Receiver object.
41321936Shselasky * This object is part of the opensm family of objects.
42321936Shselasky */
43321936Shselasky
44321936Shselasky#if HAVE_CONFIG_H
45321936Shselasky#  include <config.h>
46321936Shselasky#endif				/* HAVE_CONFIG_H */
47321936Shselasky
48321936Shselasky#include <string.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_NODE_DESC_RCV_C
55321936Shselasky#include <opensm/osm_madw.h>
56321936Shselasky#include <opensm/osm_log.h>
57321936Shselasky#include <opensm/osm_node.h>
58321936Shselasky#include <opensm/osm_opensm.h>
59321936Shselasky#include <opensm/osm_subnet.h>
60321936Shselasky
61321936Shselaskystatic void nd_rcv_process_nd(IN osm_sm_t * sm, IN osm_node_t * p_node,
62321936Shselasky			      IN const ib_node_desc_t * p_nd)
63321936Shselasky{
64321936Shselasky	char *tmp_desc;
65321936Shselasky	char print_desc[IB_NODE_DESCRIPTION_SIZE + 1];
66321936Shselasky
67321936Shselasky	OSM_LOG_ENTER(sm->p_log);
68321936Shselasky
69321936Shselasky	memcpy(&p_node->node_desc.description, p_nd, sizeof(*p_nd));
70321936Shselasky
71321936Shselasky	/* also set up a printable version */
72321936Shselasky	memcpy(print_desc, p_nd, sizeof(*p_nd));
73321936Shselasky	print_desc[IB_NODE_DESCRIPTION_SIZE] = '\0';
74321936Shselasky	tmp_desc = remap_node_name(sm->p_subn->p_osm->node_name_map,
75321936Shselasky				   cl_ntoh64(osm_node_get_node_guid(p_node)),
76321936Shselasky				   print_desc);
77321936Shselasky
78321936Shselasky	/* make a copy for this node to "own" */
79321936Shselasky	if (p_node->print_desc)
80321936Shselasky		free(p_node->print_desc);
81321936Shselasky	p_node->print_desc = tmp_desc;
82321936Shselasky
83321936Shselasky#ifdef ENABLE_OSM_PERF_MGR
84321936Shselasky	/* update the perfmgr entry if available */
85321936Shselasky	osm_perfmgr_update_nodename(&sm->p_subn->p_osm->perfmgr,
86321936Shselasky				cl_ntoh64(osm_node_get_node_guid(p_node)),
87321936Shselasky				p_node->print_desc);
88321936Shselasky#endif				/* ENABLE_OSM_PERF_MGR */
89321936Shselasky
90321936Shselasky	OSM_LOG(sm->p_log, OSM_LOG_VERBOSE,
91321936Shselasky		"Node 0x%" PRIx64 ", Description = %s\n",
92321936Shselasky		cl_ntoh64(osm_node_get_node_guid(p_node)), p_node->print_desc);
93321936Shselasky
94321936Shselasky	OSM_LOG_EXIT(sm->p_log);
95321936Shselasky}
96321936Shselasky
97321936Shselaskyvoid osm_nd_rcv_process(IN void *context, IN void *data)
98321936Shselasky{
99321936Shselasky	osm_sm_t *sm = context;
100321936Shselasky	osm_madw_t *p_madw = data;
101321936Shselasky	ib_node_desc_t *p_nd;
102321936Shselasky	ib_smp_t *p_smp;
103321936Shselasky	osm_node_t *p_node;
104321936Shselasky	ib_net64_t node_guid;
105321936Shselasky
106321936Shselasky	CL_ASSERT(sm);
107321936Shselasky
108321936Shselasky	OSM_LOG_ENTER(sm->p_log);
109321936Shselasky
110321936Shselasky	CL_ASSERT(p_madw);
111321936Shselasky
112321936Shselasky	p_smp = osm_madw_get_smp_ptr(p_madw);
113321936Shselasky	if (ib_smp_get_status(p_smp)) {
114321936Shselasky		OSM_LOG(sm->p_log, OSM_LOG_DEBUG,
115321936Shselasky			"MAD status 0x%x received\n",
116321936Shselasky			cl_ntoh16(ib_smp_get_status(p_smp)));
117321936Shselasky		goto Exit;
118321936Shselasky	}
119321936Shselasky
120321936Shselasky	p_nd = ib_smp_get_payload_ptr(p_smp);
121321936Shselasky
122321936Shselasky	/* Acquire the node object and add the node description. */
123321936Shselasky	node_guid = osm_madw_get_nd_context_ptr(p_madw)->node_guid;
124321936Shselasky	CL_PLOCK_EXCL_ACQUIRE(sm->p_lock);
125321936Shselasky	p_node = osm_get_node_by_guid(sm->p_subn, node_guid);
126321936Shselasky	if (!p_node)
127321936Shselasky		OSM_LOG(sm->p_log, OSM_LOG_ERROR, "ERR 0B01: "
128321936Shselasky			"NodeDescription received for nonexistent node "
129321936Shselasky			"0x%" PRIx64 "\n", cl_ntoh64(node_guid));
130321936Shselasky	else
131321936Shselasky		nd_rcv_process_nd(sm, p_node, p_nd);
132321936Shselasky
133321936Shselasky	CL_PLOCK_RELEASE(sm->p_lock);
134321936ShselaskyExit:
135321936Shselasky	OSM_LOG_EXIT(sm->p_log);
136321936Shselasky}
137