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_smir_rcv_t.
39 * This object represents the SMInfo 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_qmap.h>
50 #include <complib/cl_passivelock.h>
51 #include <complib/cl_debug.h>
52 #include <complib/cl_qlist.h>
53 #include <vendor/osm_vendor_api.h>
54 #include <opensm/osm_madw.h>
55 #include <opensm/osm_log.h>
56 #include <opensm/osm_subnet.h>
57 #include <opensm/osm_mad_pool.h>
58 #include <opensm/osm_helper.h>
59 #include <opensm/osm_msgdef.h>
60 #include <opensm/osm_port.h>
61 #include <opensm/osm_pkey.h>
62 #include <opensm/osm_remote_sm.h>
63 #include <opensm/osm_sa.h>
64 #include <opensm/osm_opensm.h>
66 typedef struct osm_smir_item {
67 cl_list_item_t list_item;
68 ib_sminfo_record_t 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
80 __osm_smir_rcv_new_smir(IN osm_sa_t * sa,
81 IN const osm_port_t * const p_port,
82 IN cl_qlist_t * const p_list,
83 IN ib_net64_t const guid,
84 IN ib_net32_t const act_count,
85 IN uint8_t const pri_state,
86 IN const osm_physp_t * const p_req_physp)
88 osm_smir_item_t *p_rec_item;
89 ib_api_status_t status = IB_SUCCESS;
91 OSM_LOG_ENTER(sa->p_log);
93 p_rec_item = malloc(sizeof(*p_rec_item));
94 if (p_rec_item == NULL) {
95 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 2801: "
96 "rec_item alloc failed\n");
97 status = IB_INSUFFICIENT_RESOURCES;
101 OSM_LOG(sa->p_log, OSM_LOG_DEBUG,
102 "New SMInfo: GUID 0x%016" PRIx64 "\n", cl_ntoh64(guid));
104 memset(p_rec_item, 0, sizeof(*p_rec_item));
106 p_rec_item->rec.lid = osm_port_get_base_lid(p_port);
107 p_rec_item->rec.sm_info.guid = guid;
108 p_rec_item->rec.sm_info.act_count = act_count;
109 p_rec_item->rec.sm_info.pri_state = pri_state;
111 cl_qlist_insert_tail(p_list, &p_rec_item->list_item);
114 OSM_LOG_EXIT(sa->p_log);
118 /**********************************************************************
119 **********************************************************************/
121 __osm_sa_smir_by_comp_mask(IN osm_sa_t * sa,
122 IN const osm_remote_sm_t * const p_rem_sm,
123 osm_smir_search_ctxt_t * const p_ctxt)
125 const ib_sminfo_record_t *const p_rcvd_rec = p_ctxt->p_rcvd_rec;
126 const osm_physp_t *const p_req_physp = p_ctxt->p_req_physp;
127 ib_net64_t const comp_mask = p_ctxt->comp_mask;
129 OSM_LOG_ENTER(sa->p_log);
131 if (comp_mask & IB_SMIR_COMPMASK_GUID) {
132 if (p_rem_sm->smi.guid != p_rcvd_rec->sm_info.guid)
136 if (comp_mask & IB_SMIR_COMPMASK_PRIORITY) {
137 if (ib_sminfo_get_priority(&p_rem_sm->smi) !=
138 ib_sminfo_get_priority(&p_rcvd_rec->sm_info))
142 if (comp_mask & IB_SMIR_COMPMASK_SMSTATE) {
143 if (ib_sminfo_get_state(&p_rem_sm->smi) !=
144 ib_sminfo_get_state(&p_rcvd_rec->sm_info))
148 /* Implement any other needed search cases */
150 __osm_smir_rcv_new_smir(sa, p_rem_sm->p_port, p_ctxt->p_list,
152 p_rem_sm->smi.act_count,
153 p_rem_sm->smi.pri_state, p_req_physp);
156 OSM_LOG_EXIT(sa->p_log);
159 /**********************************************************************
160 **********************************************************************/
162 __osm_sa_smir_by_comp_mask_cb(IN cl_map_item_t * const p_map_item,
165 const osm_remote_sm_t *const p_rem_sm = (osm_remote_sm_t *) p_map_item;
166 osm_smir_search_ctxt_t *const p_ctxt =
167 (osm_smir_search_ctxt_t *) context;
169 __osm_sa_smir_by_comp_mask(p_ctxt->sa, p_rem_sm, p_ctxt);
172 /**********************************************************************
173 **********************************************************************/
174 void osm_smir_rcv_process(IN void *ctx, IN void *data)
177 osm_madw_t *p_madw = data;
178 const ib_sa_mad_t *sad_mad;
179 const ib_sminfo_record_t *p_rcvd_rec;
180 const osm_port_t *p_port = NULL;
181 const ib_sm_info_t *p_smi;
183 osm_smir_search_ctxt_t context;
184 ib_api_status_t status = IB_SUCCESS;
185 ib_net64_t comp_mask;
186 ib_net64_t port_guid;
187 osm_physp_t *p_req_physp;
188 osm_port_t *local_port;
189 osm_remote_sm_t *p_rem_sm;
190 cl_qmap_t *p_sm_guid_tbl;
195 OSM_LOG_ENTER(sa->p_log);
199 sad_mad = osm_madw_get_sa_mad_ptr(p_madw);
201 (ib_sminfo_record_t *) ib_sa_mad_get_payload_ptr(sad_mad);
202 comp_mask = sad_mad->comp_mask;
204 CL_ASSERT(sad_mad->attr_id == IB_MAD_ATTR_SMINFO_RECORD);
206 /* we only support SubnAdmGet and SubnAdmGetTable methods */
207 if (sad_mad->method != IB_MAD_METHOD_GET &&
208 sad_mad->method != IB_MAD_METHOD_GETTABLE) {
209 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 2804: "
210 "Unsupported Method (%s)\n",
211 ib_get_sa_method_str(sad_mad->method));
212 osm_sa_send_error(sa, p_madw, IB_MAD_STATUS_UNSUP_METHOD_ATTR);
216 /* update the requester physical port. */
217 p_req_physp = osm_get_physp_by_mad_addr(sa->p_log, sa->p_subn,
218 osm_madw_get_mad_addr_ptr
220 if (p_req_physp == NULL) {
221 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 2803: "
222 "Cannot find requester physical port\n");
226 if (osm_log_is_active(sa->p_log, OSM_LOG_DEBUG))
227 osm_dump_sm_info_record(sa->p_log, p_rcvd_rec, OSM_LOG_DEBUG);
229 p_smi = &p_rcvd_rec->sm_info;
231 cl_qlist_init(&rec_list);
233 context.p_rcvd_rec = p_rcvd_rec;
234 context.p_list = &rec_list;
235 context.comp_mask = sad_mad->comp_mask;
237 context.p_req_physp = p_req_physp;
239 cl_plock_acquire(sa->p_lock);
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) {
247 osm_get_port_by_base_lid(sa->p_subn, p_rcvd_rec->lid,
249 if ((status != IB_SUCCESS) || (p_port == NULL)) {
250 status = IB_NOT_FOUND;
251 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 2806: "
252 "No port found with LID %u\n",
253 cl_ntoh16(p_rcvd_rec->lid));
257 if (status == IB_SUCCESS) {
258 /* Handle our own SM first */
259 local_port = osm_get_port_by_guid(sa->p_subn,
260 sa->p_subn->sm_port_guid);
262 cl_plock_release(sa->p_lock);
263 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 2809: "
264 "No port found with GUID 0x%016" PRIx64 "\n",
265 cl_ntoh64(sa->p_subn->sm_port_guid));
269 if (!p_port || local_port == p_port) {
271 osm_physp_share_pkey(sa->p_log, p_req_physp,
272 local_port->p_physp)) {
273 cl_plock_release(sa->p_lock);
274 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 2805: "
275 "Cannot get SMInfo record due to pkey violation\n");
279 /* Check that other search components specified match */
280 if ((comp_mask & IB_SMIR_COMPMASK_GUID) &&
281 sa->p_subn->sm_port_guid != p_smi->guid)
283 if ((comp_mask & IB_SMIR_COMPMASK_PRIORITY) &&
284 sa->p_subn->opt.sm_priority !=
285 ib_sminfo_get_priority(p_smi))
287 if ((comp_mask & IB_SMIR_COMPMASK_SMSTATE) &&
288 sa->p_subn->sm_state != ib_sminfo_get_state(p_smi))
291 /* Now, add local SMInfo to list */
292 pri_state = sa->p_subn->sm_state & 0x0F;
294 (sa->p_subn->opt.sm_priority & 0x0F) << 4;
295 __osm_smir_rcv_new_smir(sa, local_port, context.p_list,
296 sa->p_subn->sm_port_guid,
297 cl_ntoh32(sa->p_subn->p_osm->stats.qp0_mads_sent),
298 pri_state, p_req_physp);
302 if (p_port && p_port != local_port) {
303 /* Find remote SM corresponding to p_port */
304 port_guid = osm_port_get_guid(p_port);
305 p_sm_guid_tbl = &sa->p_subn->sm_guid_tbl;
307 (osm_remote_sm_t *) cl_qmap_get(p_sm_guid_tbl,
310 (osm_remote_sm_t *) cl_qmap_end(p_sm_guid_tbl))
311 __osm_sa_smir_by_comp_mask(sa, p_rem_sm,
314 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 280A: "
315 "No remote SM for GUID 0x%016" PRIx64
316 "\n", cl_ntoh64(port_guid));
318 /* Go over all other known (remote) SMs */
319 cl_qmap_apply_func(&sa->p_subn->sm_guid_tbl,
320 __osm_sa_smir_by_comp_mask_cb,
325 cl_plock_release(sa->p_lock);
327 osm_sa_respond(sa, p_madw, sizeof(ib_sminfo_record_t), &rec_list);
330 OSM_LOG_EXIT(sa->p_log);