]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/ofed/opensm/opensm/osm_lin_fwd_rcv.c
MFV r357608: Limit memory usage in xz(1) instead of in tuklib.
[FreeBSD/FreeBSD.git] / contrib / ofed / opensm / opensm / osm_lin_fwd_rcv.c
1 /*
2  * Copyright (c) 2004-2009 Voltaire, Inc. All rights reserved.
3  * Copyright (c) 2002-2005,2008 Mellanox Technologies LTD. All rights reserved.
4  * Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
5  * Copyright (c) 2009 Sun Microsystems, Inc. All rights reserved.
6  * Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved.
7  *
8  * This software is available to you under a choice of one of two
9  * licenses.  You may choose to be licensed under the terms of the GNU
10  * General Public License (GPL) Version 2, available from the file
11  * COPYING in the main directory of this source tree, or the
12  * OpenIB.org BSD license below:
13  *
14  *     Redistribution and use in source and binary forms, with or
15  *     without modification, are permitted provided that the following
16  *     conditions are met:
17  *
18  *      - Redistributions of source code must retain the above
19  *        copyright notice, this list of conditions and the following
20  *        disclaimer.
21  *
22  *      - Redistributions in binary form must reproduce the above
23  *        copyright notice, this list of conditions and the following
24  *        disclaimer in the documentation and/or other materials
25  *        provided with the distribution.
26  *
27  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
28  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
29  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
30  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
31  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
32  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
33  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
34  * SOFTWARE.
35  *
36  */
37
38 /*
39  * Abstract:
40  *    Implementation of osm_lft_rcv_t.
41  * This object represents the Linear Forwarding Table Receiver object.
42  * This object is part of the opensm family of objects.
43  */
44
45 #if HAVE_CONFIG_H
46 #  include <config.h>
47 #endif                          /* HAVE_CONFIG_H */
48
49 #include <string.h>
50 #include <complib/cl_debug.h>
51 #include <opensm/osm_file_ids.h>
52 #define FILE_ID OSM_FILE_LIN_FWD_RCV_C
53 #include <opensm/osm_switch.h>
54 #include <opensm/osm_sm.h>
55 #include <opensm/osm_event_plugin.h>
56 #include <opensm/osm_opensm.h>
57
58 void osm_lft_rcv_process(IN void *context, IN void *data)
59 {
60         osm_sm_t *sm = context;
61         osm_madw_t *p_madw = data;
62         ib_smp_t *p_smp;
63         uint32_t block_num;
64         osm_switch_t *p_sw;
65         osm_lft_context_t *p_lft_context;
66         uint8_t *p_block;
67         ib_net64_t node_guid;
68         osm_epi_lft_change_event_t lft_change;
69         ib_api_status_t status;
70
71         CL_ASSERT(sm);
72
73         OSM_LOG_ENTER(sm->p_log);
74
75         CL_ASSERT(p_madw);
76
77         p_smp = osm_madw_get_smp_ptr(p_madw);
78         p_block = ib_smp_get_payload_ptr(p_smp);
79         block_num = cl_ntoh32(p_smp->attr_mod);
80
81         /*
82            Acquire the switch object for this switch.
83          */
84         p_lft_context = osm_madw_get_lft_context_ptr(p_madw);
85         node_guid = p_lft_context->node_guid;
86
87         if (ib_smp_get_status(p_smp)) {
88                 OSM_LOG(sm->p_log, OSM_LOG_DEBUG,
89                         "MAD status 0x%x received\n",
90                         cl_ntoh16(ib_smp_get_status(p_smp)));
91                 goto Exit;
92         }
93
94         CL_PLOCK_EXCL_ACQUIRE(sm->p_lock);
95         p_sw = osm_get_switch_by_guid(sm->p_subn, node_guid);
96
97         if (!p_sw) {
98                 OSM_LOG(sm->p_log, OSM_LOG_ERROR, "ERR 0401: "
99                         "LFT received for nonexistent node "
100                         "0x%" PRIx64 "\n", cl_ntoh64(node_guid));
101         } else {
102                 status = osm_switch_set_lft_block(p_sw, p_block, block_num);
103                 if (status == IB_SUCCESS) {
104                         if (sm->p_subn->first_time_master_sweep == FALSE) {
105                                 lft_change.p_sw = p_sw;
106                                 lft_change.flags = LFT_CHANGED_BLOCK;
107                                 lft_change.lft_top = 0;
108                                 lft_change.block_num = block_num;
109                                 osm_opensm_report_event(sm->p_subn->p_osm,
110                                                         OSM_EVENT_ID_LFT_CHANGE,
111                                                         &lft_change);
112                         }
113                 } else {
114                         OSM_LOG(sm->p_log, OSM_LOG_ERROR, "ERR 0402: "
115                                 "Setting forwarding table block %u failed (%s)"
116                                 ", Switch 0x%" PRIx64 " %s\n", block_num,
117                                 ib_get_err_str(status), cl_ntoh64(node_guid),
118                                 p_sw->p_node->print_desc);
119                 }
120         }
121
122         CL_PLOCK_RELEASE(sm->p_lock);
123 Exit:
124         OSM_LOG_EXIT(sm->p_log);
125 }