2 * Copyright (c) 2004-2009 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.
5 * Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved.
7 * This software is available to you under a choice of one of two
8 * licenses. You may choose to be licensed under the terms of the GNU
9 * General Public License (GPL) Version 2, available from the file
10 * COPYING in the main directory of this source tree, or the
11 * OpenIB.org BSD license below:
13 * Redistribution and use in source and binary forms, with or
14 * without modification, are permitted provided that the following
17 * - Redistributions of source code must retain the above
18 * copyright notice, this list of conditions and the following
21 * - Redistributions in binary form must reproduce the above
22 * copyright notice, this list of conditions and the following
23 * disclaimer in the documentation and/or other materials
24 * provided with the distribution.
26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
30 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
31 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
32 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39 * Implementation of osm_smir_rcv_t.
40 * This object represents the SMInfo Receiver object.
41 * This object is part of the opensm family of objects.
46 #endif /* HAVE_CONFIG_H */
49 #include <iba/ib_types.h>
50 #include <complib/cl_qmap.h>
51 #include <complib/cl_passivelock.h>
52 #include <complib/cl_debug.h>
53 #include <complib/cl_qlist.h>
54 #include <opensm/osm_file_ids.h>
55 #define FILE_ID OSM_FILE_SA_SMINFO_RECORD_C
56 #include <vendor/osm_vendor_api.h>
57 #include <opensm/osm_madw.h>
58 #include <opensm/osm_log.h>
59 #include <opensm/osm_subnet.h>
60 #include <opensm/osm_mad_pool.h>
61 #include <opensm/osm_helper.h>
62 #include <opensm/osm_msgdef.h>
63 #include <opensm/osm_port.h>
64 #include <opensm/osm_pkey.h>
65 #include <opensm/osm_remote_sm.h>
66 #include <opensm/osm_sa.h>
67 #include <opensm/osm_opensm.h>
69 #define SA_SMIR_RESP_SIZE SA_ITEM_RESP_SIZE(sminfo_rec)
71 typedef struct osm_smir_search_ctxt {
72 const ib_sminfo_record_t *p_rcvd_rec;
76 const osm_physp_t *p_req_physp;
77 } osm_smir_search_ctxt_t;
79 static ib_api_status_t smir_rcv_new_smir(IN osm_sa_t * sa,
80 IN const osm_port_t * p_port,
81 IN cl_qlist_t * p_list,
82 IN ib_net64_t const guid,
83 IN ib_net32_t const act_count,
84 IN uint8_t const pri_state,
85 IN const osm_physp_t * p_req_physp)
87 osm_sa_item_t *p_rec_item;
88 ib_api_status_t status = IB_SUCCESS;
90 OSM_LOG_ENTER(sa->p_log);
92 p_rec_item = malloc(SA_SMIR_RESP_SIZE);
93 if (p_rec_item == NULL) {
94 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 2801: "
95 "rec_item alloc failed\n");
96 status = IB_INSUFFICIENT_RESOURCES;
100 OSM_LOG(sa->p_log, OSM_LOG_DEBUG,
101 "New SMInfo: GUID 0x%016" PRIx64 "\n", cl_ntoh64(guid));
103 memset(p_rec_item, 0, SA_SMIR_RESP_SIZE);
105 p_rec_item->resp.sminfo_rec.lid = osm_port_get_base_lid(p_port);
106 p_rec_item->resp.sminfo_rec.sm_info.guid = guid;
107 p_rec_item->resp.sminfo_rec.sm_info.act_count = act_count;
108 p_rec_item->resp.sminfo_rec.sm_info.pri_state = pri_state;
110 cl_qlist_insert_tail(p_list, &p_rec_item->list_item);
113 OSM_LOG_EXIT(sa->p_log);
117 static void sa_smir_by_comp_mask(IN osm_sa_t * sa,
118 IN const osm_remote_sm_t * p_rem_sm,
119 osm_smir_search_ctxt_t * p_ctxt)
121 const ib_sminfo_record_t *const p_rcvd_rec = p_ctxt->p_rcvd_rec;
122 const osm_physp_t *const p_req_physp = p_ctxt->p_req_physp;
123 ib_net64_t const comp_mask = p_ctxt->comp_mask;
126 OSM_LOG_ENTER(sa->p_log);
128 if (comp_mask & IB_SMIR_COMPMASK_GUID) {
129 if (p_rem_sm->smi.guid != p_rcvd_rec->sm_info.guid)
133 if (comp_mask & IB_SMIR_COMPMASK_PRIORITY) {
134 if (ib_sminfo_get_priority(&p_rem_sm->smi) !=
135 ib_sminfo_get_priority(&p_rcvd_rec->sm_info))
139 if (comp_mask & IB_SMIR_COMPMASK_SMSTATE) {
140 if (ib_sminfo_get_state(&p_rem_sm->smi) !=
141 ib_sminfo_get_state(&p_rcvd_rec->sm_info))
145 /* Implement any other needed search cases */
146 p_port = osm_get_port_by_guid(sa->p_subn, p_rem_sm->smi.guid);
148 if (p_port == NULL) {
149 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 2810: "
150 "No port for remote sm\n");
154 smir_rcv_new_smir(sa, p_port, p_ctxt->p_list,
155 p_rem_sm->smi.guid, p_rem_sm->smi.act_count,
156 p_rem_sm->smi.pri_state, p_req_physp);
159 OSM_LOG_EXIT(sa->p_log);
162 static void sa_smir_by_comp_mask_cb(IN cl_map_item_t * p_map_item, IN void *cxt)
164 const osm_remote_sm_t *p_rem_sm = (osm_remote_sm_t *) p_map_item;
165 osm_smir_search_ctxt_t *p_ctxt = cxt;
167 sa_smir_by_comp_mask(p_ctxt->sa, p_rem_sm, p_ctxt);
170 void osm_smir_rcv_process(IN void *ctx, IN void *data)
173 osm_madw_t *p_madw = data;
174 const ib_sa_mad_t *sad_mad;
175 const ib_sminfo_record_t *p_rcvd_rec;
176 const osm_port_t *p_port = NULL;
177 const ib_sm_info_t *p_smi;
179 osm_smir_search_ctxt_t context;
180 ib_api_status_t status = IB_SUCCESS;
181 ib_net64_t comp_mask;
182 ib_net64_t port_guid;
183 osm_physp_t *p_req_physp;
184 osm_port_t *local_port;
185 osm_remote_sm_t *p_rem_sm;
186 cl_qmap_t *p_sm_guid_tbl;
191 OSM_LOG_ENTER(sa->p_log);
195 sad_mad = osm_madw_get_sa_mad_ptr(p_madw);
196 p_rcvd_rec = (ib_sminfo_record_t *) ib_sa_mad_get_payload_ptr(sad_mad);
197 comp_mask = sad_mad->comp_mask;
199 CL_ASSERT(sad_mad->attr_id == IB_MAD_ATTR_SMINFO_RECORD);
201 /* we only support SubnAdmGet and SubnAdmGetTable methods */
202 if (sad_mad->method != IB_MAD_METHOD_GET &&
203 sad_mad->method != IB_MAD_METHOD_GETTABLE) {
204 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 2804: "
205 "Unsupported Method (%s) for SMInfoRecord request\n",
206 ib_get_sa_method_str(sad_mad->method));
207 osm_sa_send_error(sa, p_madw, IB_MAD_STATUS_UNSUP_METHOD_ATTR);
211 cl_plock_acquire(sa->p_lock);
213 /* update the requester physical port */
214 p_req_physp = osm_get_physp_by_mad_addr(sa->p_log, sa->p_subn,
215 osm_madw_get_mad_addr_ptr
217 if (p_req_physp == NULL) {
218 cl_plock_release(sa->p_lock);
219 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 2803: "
220 "Cannot find requester physical port\n");
224 if (OSM_LOG_IS_ACTIVE_V2(sa->p_log, OSM_LOG_DEBUG)) {
225 OSM_LOG(sa->p_log, OSM_LOG_DEBUG,
226 "Requester port GUID 0x%" PRIx64 "\n",
227 cl_ntoh64(osm_physp_get_port_guid(p_req_physp)));
228 osm_dump_sm_info_record_v2(sa->p_log, p_rcvd_rec, FILE_ID, OSM_LOG_DEBUG);
231 p_smi = &p_rcvd_rec->sm_info;
233 cl_qlist_init(&rec_list);
235 context.p_rcvd_rec = p_rcvd_rec;
236 context.p_list = &rec_list;
237 context.comp_mask = sad_mad->comp_mask;
239 context.p_req_physp = p_req_physp;
242 If the user specified a LID, it obviously narrows our
243 work load, since we don't have to search every port
245 if (comp_mask & IB_SMIR_COMPMASK_LID) {
246 p_port = osm_get_port_by_lid(sa->p_subn, p_rcvd_rec->lid);
248 status = IB_NOT_FOUND;
249 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 2806: "
250 "No port found with LID %u\n",
251 cl_ntoh16(p_rcvd_rec->lid));
255 if (status == IB_SUCCESS) {
256 /* Handle our own SM first */
257 local_port = osm_get_port_by_guid(sa->p_subn,
258 sa->p_subn->sm_port_guid);
260 cl_plock_release(sa->p_lock);
261 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 2809: "
262 "No port found with GUID 0x%016" PRIx64 "\n",
263 cl_ntoh64(sa->p_subn->sm_port_guid));
267 if (!p_port || local_port == p_port) {
269 osm_physp_share_pkey(sa->p_log, p_req_physp,
271 sa->p_subn->opt.allow_both_pkeys)) {
272 cl_plock_release(sa->p_lock);
273 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 2805: "
274 "Cannot get SMInfo record due to pkey violation\n");
278 /* Check that other search components specified match */
279 if ((comp_mask & IB_SMIR_COMPMASK_GUID) &&
280 sa->p_subn->sm_port_guid != p_smi->guid)
282 if ((comp_mask & IB_SMIR_COMPMASK_PRIORITY) &&
283 sa->p_subn->opt.sm_priority !=
284 ib_sminfo_get_priority(p_smi))
286 if ((comp_mask & IB_SMIR_COMPMASK_SMSTATE) &&
287 sa->p_subn->sm_state != ib_sminfo_get_state(p_smi))
290 /* Now, add local SMInfo to list */
291 pri_state = sa->p_subn->sm_state & 0x0F;
292 pri_state |= (sa->p_subn->opt.sm_priority & 0x0F) << 4;
293 smir_rcv_new_smir(sa, local_port, context.p_list,
294 sa->p_subn->sm_port_guid,
295 cl_ntoh32(sa->p_subn->p_osm->stats.
296 qp0_mads_sent), pri_state,
301 if (p_port && p_port != local_port) {
302 /* Find remote SM corresponding to p_port */
303 port_guid = osm_port_get_guid(p_port);
304 p_sm_guid_tbl = &sa->p_subn->sm_guid_tbl;
306 (osm_remote_sm_t *) cl_qmap_get(p_sm_guid_tbl,
309 (osm_remote_sm_t *) cl_qmap_end(p_sm_guid_tbl))
310 sa_smir_by_comp_mask(sa, p_rem_sm, &context);
312 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 280A: "
313 "No remote SM for GUID 0x%016" PRIx64
314 "\n", cl_ntoh64(port_guid));
315 } else if (!p_port) {
316 /* Go over all other known (remote) SMs */
317 cl_qmap_apply_func(&sa->p_subn->sm_guid_tbl,
318 sa_smir_by_comp_mask_cb, &context);
322 cl_plock_release(sa->p_lock);
324 osm_sa_respond(sa, p_madw, sizeof(ib_sminfo_record_t), &rec_list);
327 OSM_LOG_EXIT(sa->p_log);