2 * Copyright (c) 2004-2008 Voltaire, Inc. All rights reserved.
3 * Copyright (c) 2002-2005 Mellanox Technologies LTD. All rights reserved.
4 * Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
6 * This software is available to you under a choice of one of two
7 * licenses. You may choose to be licensed under the terms of the GNU
8 * General Public License (GPL) Version 2, available from the file
9 * COPYING in the main directory of this source tree, or the
10 * OpenIB.org BSD license below:
12 * Redistribution and use in source and binary forms, with or
13 * without modification, are permitted provided that the following
16 * - Redistributions of source code must retain the above
17 * copyright notice, this list of conditions and the following
20 * - Redistributions in binary form must reproduce the above
21 * copyright notice, this list of conditions and the following
22 * disclaimer in the documentation and/or other materials
23 * provided with the distribution.
25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
38 * Implementation of osm_nr_rcv_t.
39 * This object represents the NodeInfo Receiver object.
40 * This object is part of the opensm family of objects.
45 #endif /* HAVE_CONFIG_H */
48 #include <iba/ib_types.h>
49 #include <complib/cl_debug.h>
50 #include <complib/cl_qlist.h>
51 #include <vendor/osm_vendor_api.h>
52 #include <opensm/osm_node.h>
53 #include <opensm/osm_helper.h>
54 #include <opensm/osm_pkey.h>
55 #include <opensm/osm_sa.h>
57 typedef struct osm_nr_item {
58 cl_list_item_t list_item;
62 typedef struct osm_nr_search_ctxt {
63 const ib_node_record_t *p_rcvd_rec;
67 const osm_physp_t *p_req_physp;
68 } osm_nr_search_ctxt_t;
70 /**********************************************************************
71 **********************************************************************/
72 static ib_api_status_t
73 __osm_nr_rcv_new_nr(IN osm_sa_t * sa,
74 IN const osm_node_t * const p_node,
75 IN cl_qlist_t * const p_list,
76 IN ib_net64_t const port_guid, IN ib_net16_t const lid)
78 osm_nr_item_t *p_rec_item;
79 ib_api_status_t status = IB_SUCCESS;
81 OSM_LOG_ENTER(sa->p_log);
83 p_rec_item = malloc(sizeof(*p_rec_item));
84 if (p_rec_item == NULL) {
85 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 1D02: "
86 "rec_item alloc failed\n");
87 status = IB_INSUFFICIENT_RESOURCES;
91 OSM_LOG(sa->p_log, OSM_LOG_DEBUG,
92 "New NodeRecord: node 0x%016" PRIx64
93 "\n\t\t\t\tport 0x%016" PRIx64 ", lid %u\n",
94 cl_ntoh64(osm_node_get_node_guid(p_node)),
95 cl_ntoh64(port_guid), cl_ntoh16(lid));
97 memset(p_rec_item, 0, sizeof(*p_rec_item));
99 p_rec_item->rec.lid = lid;
101 p_rec_item->rec.node_info = p_node->node_info;
102 p_rec_item->rec.node_info.port_guid = port_guid;
103 memcpy(&(p_rec_item->rec.node_desc), &(p_node->node_desc),
104 IB_NODE_DESCRIPTION_SIZE);
105 cl_qlist_insert_tail(p_list, &p_rec_item->list_item);
108 OSM_LOG_EXIT(sa->p_log);
112 /**********************************************************************
113 **********************************************************************/
115 __osm_nr_rcv_create_nr(IN osm_sa_t * sa,
116 IN osm_node_t * const p_node,
117 IN cl_qlist_t * const p_list,
118 IN ib_net64_t const match_port_guid,
119 IN ib_net16_t const match_lid,
120 IN const osm_physp_t * const p_req_physp)
122 const osm_physp_t *p_physp;
125 uint16_t match_lid_ho;
127 ib_net16_t base_lid_ho;
128 ib_net16_t max_lid_ho;
130 ib_net64_t port_guid;
132 OSM_LOG_ENTER(sa->p_log);
134 OSM_LOG(sa->p_log, OSM_LOG_DEBUG,
135 "Looking for NodeRecord with LID: %u GUID:0x%016"
136 PRIx64 "\n", cl_ntoh16(match_lid),
137 cl_ntoh64(match_port_guid));
140 For switches, do not return the NodeInfo record
141 for each port on the switch, just for port 0.
143 if (osm_node_get_type(p_node) == IB_NODE_TYPE_SWITCH)
146 num_ports = osm_node_get_num_physp(p_node);
148 for (port_num = 0; port_num < num_ports; port_num++) {
149 p_physp = osm_node_get_physp_ptr(p_node, port_num);
153 /* Check to see if the found p_physp and the requester physp
154 share a pkey. If not - continue */
155 if (!osm_physp_share_pkey(sa->p_log, p_physp, p_req_physp))
158 port_guid = osm_physp_get_port_guid(p_physp);
160 if (match_port_guid && (port_guid != match_port_guid))
163 base_lid = osm_physp_get_base_lid(p_physp);
164 base_lid_ho = cl_ntoh16(base_lid);
165 lmc = osm_physp_get_lmc(p_physp);
166 max_lid_ho = (uint16_t) (base_lid_ho + (1 << lmc) - 1);
167 match_lid_ho = cl_ntoh16(match_lid);
171 We validate that the lid belongs to this node.
173 OSM_LOG(sa->p_log, OSM_LOG_DEBUG,
174 "Comparing LID: %u <= %u <= %u\n",
175 base_lid_ho, match_lid_ho, max_lid_ho);
177 if (match_lid_ho < base_lid_ho
178 || match_lid_ho > max_lid_ho)
182 __osm_nr_rcv_new_nr(sa, p_node, p_list, port_guid, base_lid);
186 OSM_LOG_EXIT(sa->p_log);
189 /**********************************************************************
190 **********************************************************************/
192 __osm_nr_rcv_by_comp_mask(IN cl_map_item_t * const p_map_item, IN void *context)
194 const osm_nr_search_ctxt_t *const p_ctxt =
195 (osm_nr_search_ctxt_t *) context;
196 osm_node_t *const p_node = (osm_node_t *) p_map_item;
197 const ib_node_record_t *const p_rcvd_rec = p_ctxt->p_rcvd_rec;
198 const osm_physp_t *const p_req_physp = p_ctxt->p_req_physp;
199 osm_sa_t *sa = p_ctxt->sa;
200 ib_net64_t const comp_mask = p_ctxt->comp_mask;
201 ib_net64_t match_port_guid = 0;
202 ib_net16_t match_lid = 0;
204 OSM_LOG_ENTER(p_ctxt->sa->p_log);
206 osm_dump_node_info(p_ctxt->sa->p_log,
207 &p_node->node_info, OSM_LOG_VERBOSE);
209 if (comp_mask & IB_NR_COMPMASK_LID)
210 match_lid = p_rcvd_rec->lid;
212 if (comp_mask & IB_NR_COMPMASK_NODEGUID) {
213 OSM_LOG(sa->p_log, OSM_LOG_DEBUG,
214 "Looking for node 0x%016" PRIx64
215 ", found 0x%016" PRIx64 "\n",
216 cl_ntoh64(p_rcvd_rec->node_info.node_guid),
217 cl_ntoh64(osm_node_get_node_guid(p_node)));
219 if ((p_node->node_info.node_guid !=
220 p_rcvd_rec->node_info.node_guid))
223 if (comp_mask & IB_NR_COMPMASK_PORTGUID) {
224 match_port_guid = p_rcvd_rec->node_info.port_guid;
226 if (comp_mask & IB_NR_COMPMASK_SYSIMAGEGUID) {
227 if ((p_node->node_info.sys_guid !=
228 p_rcvd_rec->node_info.sys_guid))
231 if (comp_mask & IB_NR_COMPMASK_BASEVERSION) {
232 if ((p_node->node_info.base_version !=
233 p_rcvd_rec->node_info.base_version))
236 if (comp_mask & IB_NR_COMPMASK_CLASSVERSION) {
237 if ((p_node->node_info.class_version !=
238 p_rcvd_rec->node_info.class_version))
241 if (comp_mask & IB_NR_COMPMASK_NODETYPE) {
242 if ((p_node->node_info.node_type !=
243 p_rcvd_rec->node_info.node_type))
246 if (comp_mask & IB_NR_COMPMASK_NUMPORTS) {
247 if ((p_node->node_info.num_ports !=
248 p_rcvd_rec->node_info.num_ports))
251 if (comp_mask & IB_NR_COMPMASK_PARTCAP) {
252 if ((p_node->node_info.partition_cap !=
253 p_rcvd_rec->node_info.partition_cap))
256 if (comp_mask & IB_NR_COMPMASK_DEVID) {
257 if ((p_node->node_info.device_id !=
258 p_rcvd_rec->node_info.device_id))
261 if (comp_mask & IB_NR_COMPMASK_REV) {
262 if ((p_node->node_info.revision !=
263 p_rcvd_rec->node_info.revision))
266 if (comp_mask & IB_NR_COMPMASK_PORTNUM) {
267 if (ib_node_info_get_local_port_num(&p_node->node_info) !=
268 ib_node_info_get_local_port_num(&p_rcvd_rec->node_info))
271 if (comp_mask & IB_NR_COMPMASK_VENDID) {
272 if (ib_node_info_get_vendor_id(&p_node->node_info) !=
273 ib_node_info_get_vendor_id(&p_rcvd_rec->node_info))
276 if (comp_mask & IB_NR_COMPMASK_NODEDESC) {
277 if (strncmp((char *)&p_node->node_desc,
278 (char *)&p_rcvd_rec->node_desc,
279 sizeof(ib_node_desc_t)))
283 __osm_nr_rcv_create_nr(sa, p_node, p_ctxt->p_list,
284 match_port_guid, match_lid, p_req_physp);
287 OSM_LOG_EXIT(p_ctxt->sa->p_log);
290 /**********************************************************************
291 **********************************************************************/
292 void osm_nr_rcv_process(IN void *ctx, IN void *data)
295 osm_madw_t *p_madw = data;
296 const ib_sa_mad_t *p_rcvd_mad;
297 const ib_node_record_t *p_rcvd_rec;
299 osm_nr_search_ctxt_t context;
300 osm_physp_t *p_req_physp;
304 OSM_LOG_ENTER(sa->p_log);
308 p_rcvd_mad = osm_madw_get_sa_mad_ptr(p_madw);
309 p_rcvd_rec = (ib_node_record_t *) ib_sa_mad_get_payload_ptr(p_rcvd_mad);
311 CL_ASSERT(p_rcvd_mad->attr_id == IB_MAD_ATTR_NODE_RECORD);
313 /* we only support SubnAdmGet and SubnAdmGetTable methods */
314 if (p_rcvd_mad->method != IB_MAD_METHOD_GET &&
315 p_rcvd_mad->method != IB_MAD_METHOD_GETTABLE) {
316 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 1D05: "
317 "Unsupported Method (%s)\n",
318 ib_get_sa_method_str(p_rcvd_mad->method));
319 osm_sa_send_error(sa, p_madw, IB_MAD_STATUS_UNSUP_METHOD_ATTR);
323 /* update the requester physical port. */
324 p_req_physp = osm_get_physp_by_mad_addr(sa->p_log, sa->p_subn,
325 osm_madw_get_mad_addr_ptr
327 if (p_req_physp == NULL) {
328 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 1D04: "
329 "Cannot find requester physical port\n");
333 if (osm_log_is_active(sa->p_log, OSM_LOG_DEBUG))
334 osm_dump_node_record(sa->p_log, p_rcvd_rec, OSM_LOG_DEBUG);
336 cl_qlist_init(&rec_list);
338 context.p_rcvd_rec = p_rcvd_rec;
339 context.p_list = &rec_list;
340 context.comp_mask = p_rcvd_mad->comp_mask;
342 context.p_req_physp = p_req_physp;
344 cl_plock_acquire(sa->p_lock);
346 cl_qmap_apply_func(&sa->p_subn->node_guid_tbl,
347 __osm_nr_rcv_by_comp_mask, &context);
349 cl_plock_release(sa->p_lock);
351 osm_sa_respond(sa, p_madw, sizeof(ib_node_record_t), &rec_list);
354 OSM_LOG_EXIT(sa->p_log);