1219820Sjeff/*
2219820Sjeff * Copyright (c) 2004-2008 Voltaire, Inc. All rights reserved.
3219820Sjeff * Copyright (c) 2002-2005 Mellanox Technologies LTD. All rights reserved.
4219820Sjeff * Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
5219820Sjeff *
6219820Sjeff * This software is available to you under a choice of one of two
7219820Sjeff * licenses.  You may choose to be licensed under the terms of the GNU
8219820Sjeff * General Public License (GPL) Version 2, available from the file
9219820Sjeff * COPYING in the main directory of this source tree, or the
10219820Sjeff * OpenIB.org BSD license below:
11219820Sjeff *
12219820Sjeff *     Redistribution and use in source and binary forms, with or
13219820Sjeff *     without modification, are permitted provided that the following
14219820Sjeff *     conditions are met:
15219820Sjeff *
16219820Sjeff *      - Redistributions of source code must retain the above
17219820Sjeff *        copyright notice, this list of conditions and the following
18219820Sjeff *        disclaimer.
19219820Sjeff *
20219820Sjeff *      - Redistributions in binary form must reproduce the above
21219820Sjeff *        copyright notice, this list of conditions and the following
22219820Sjeff *        disclaimer in the documentation and/or other materials
23219820Sjeff *        provided with the distribution.
24219820Sjeff *
25219820Sjeff * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26219820Sjeff * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27219820Sjeff * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28219820Sjeff * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29219820Sjeff * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30219820Sjeff * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31219820Sjeff * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32219820Sjeff * SOFTWARE.
33219820Sjeff *
34219820Sjeff */
35219820Sjeff
36219820Sjeff/*
37219820Sjeff * Abstract:
38219820Sjeff *    Implementation of osm_nd_rcv_t.
39219820Sjeff * This object represents the NodeDescription Receiver object.
40219820Sjeff * This object is part of the opensm family of objects.
41219820Sjeff */
42219820Sjeff
43219820Sjeff#if HAVE_CONFIG_H
44219820Sjeff#  include <config.h>
45219820Sjeff#endif				/* HAVE_CONFIG_H */
46219820Sjeff
47219820Sjeff#include <string.h>
48219820Sjeff#include <iba/ib_types.h>
49219820Sjeff#include <complib/cl_qmap.h>
50219820Sjeff#include <complib/cl_passivelock.h>
51219820Sjeff#include <complib/cl_debug.h>
52219820Sjeff#include <opensm/osm_madw.h>
53219820Sjeff#include <opensm/osm_log.h>
54219820Sjeff#include <opensm/osm_node.h>
55219820Sjeff#include <opensm/osm_opensm.h>
56219820Sjeff#include <opensm/osm_subnet.h>
57219820Sjeff
58219820Sjeff/**********************************************************************
59219820Sjeff **********************************************************************/
60219820Sjeffstatic void
61219820Sjeff__osm_nd_rcv_process_nd(IN osm_sm_t * sm,
62219820Sjeff			IN osm_node_t * const p_node,
63219820Sjeff			IN const ib_node_desc_t * const p_nd)
64219820Sjeff{
65219820Sjeff	char *tmp_desc;
66219820Sjeff	char print_desc[IB_NODE_DESCRIPTION_SIZE + 1];
67219820Sjeff
68219820Sjeff	OSM_LOG_ENTER(sm->p_log);
69219820Sjeff
70219820Sjeff	memcpy(&p_node->node_desc.description, p_nd, sizeof(*p_nd));
71219820Sjeff
72219820Sjeff	/* also set up a printable version */
73219820Sjeff	memcpy(print_desc, p_nd, sizeof(*p_nd));
74219820Sjeff	print_desc[IB_NODE_DESCRIPTION_SIZE] = '\0';
75219820Sjeff	tmp_desc = remap_node_name(sm->p_subn->p_osm->node_name_map,
76219820Sjeff			cl_ntoh64(osm_node_get_node_guid(p_node)),
77219820Sjeff			print_desc);
78219820Sjeff
79219820Sjeff	/* make a copy for this node to "own" */
80219820Sjeff	if (p_node->print_desc)
81219820Sjeff		free(p_node->print_desc);
82219820Sjeff	p_node->print_desc = tmp_desc;
83219820Sjeff
84219820Sjeff	OSM_LOG(sm->p_log, OSM_LOG_VERBOSE,
85219820Sjeff		"Node 0x%" PRIx64 "\n\t\t\t\tDescription = %s\n",
86219820Sjeff		cl_ntoh64(osm_node_get_node_guid(p_node)), p_node->print_desc);
87219820Sjeff
88219820Sjeff	OSM_LOG_EXIT(sm->p_log);
89219820Sjeff}
90219820Sjeff
91219820Sjeff/**********************************************************************
92219820Sjeff **********************************************************************/
93219820Sjeffvoid osm_nd_rcv_process(IN void *context, IN void *data)
94219820Sjeff{
95219820Sjeff	osm_sm_t *sm = context;
96219820Sjeff	osm_madw_t *p_madw = data;
97219820Sjeff	ib_node_desc_t *p_nd;
98219820Sjeff	ib_smp_t *p_smp;
99219820Sjeff	osm_node_t *p_node;
100219820Sjeff	ib_net64_t node_guid;
101219820Sjeff
102219820Sjeff	CL_ASSERT(sm);
103219820Sjeff
104219820Sjeff	OSM_LOG_ENTER(sm->p_log);
105219820Sjeff
106219820Sjeff	CL_ASSERT(p_madw);
107219820Sjeff
108219820Sjeff	p_smp = osm_madw_get_smp_ptr(p_madw);
109219820Sjeff	p_nd = (ib_node_desc_t *) ib_smp_get_payload_ptr(p_smp);
110219820Sjeff
111219820Sjeff	/*
112219820Sjeff	   Acquire the node object and add the node description.
113219820Sjeff	 */
114219820Sjeff
115219820Sjeff	node_guid = osm_madw_get_nd_context_ptr(p_madw)->node_guid;
116219820Sjeff	CL_PLOCK_EXCL_ACQUIRE(sm->p_lock);
117219820Sjeff	p_node = osm_get_node_by_guid(sm->p_subn, node_guid);
118219820Sjeff	if (!p_node) {
119219820Sjeff		OSM_LOG(sm->p_log, OSM_LOG_ERROR, "ERR 0B01: "
120219820Sjeff			"NodeDescription received for nonexistent node "
121219820Sjeff			"0x%" PRIx64 "\n", cl_ntoh64(node_guid));
122219820Sjeff	} else {
123219820Sjeff		__osm_nd_rcv_process_nd(sm, p_node, p_nd);
124219820Sjeff	}
125219820Sjeff
126219820Sjeff	CL_PLOCK_RELEASE(sm->p_lock);
127219820Sjeff	OSM_LOG_EXIT(sm->p_log);
128219820Sjeff}
129