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_req_t.
39 * This object represents the generic attribute requester.
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 <opensm/osm_madw.h>
51 #include <opensm/osm_attrib_req.h>
52 #include <opensm/osm_log.h>
53 #include <opensm/osm_helper.h>
54 #include <opensm/osm_mad_pool.h>
55 #include <opensm/osm_vl15intf.h>
56 #include <opensm/osm_msgdef.h>
57 #include <opensm/osm_opensm.h>
59 /**********************************************************************
60 The plock MAY or MAY NOT be held before calling this function.
61 **********************************************************************/
63 osm_req_get(IN osm_sm_t * sm,
64 IN const osm_dr_path_t * const p_path,
65 IN const uint16_t attr_id,
66 IN const uint32_t attr_mod,
67 IN const cl_disp_msgid_t err_msg,
68 IN const osm_madw_context_t * const p_context)
71 ib_api_status_t status = IB_SUCCESS;
76 OSM_LOG_ENTER(sm->p_log);
81 /* do nothing if we are exiting ... */
85 /* p_context may be NULL. */
87 p_madw = osm_mad_pool_get(sm->p_mad_pool,
88 p_path->h_bind, MAD_BLOCK_SIZE, NULL);
91 OSM_LOG(sm->p_log, OSM_LOG_ERROR,
92 "ERR 1101: Unable to acquire MAD\n");
93 status = IB_INSUFFICIENT_RESOURCES;
97 tid = cl_hton64((uint64_t) cl_atomic_inc(&sm->sm_trans_id));
99 OSM_LOG(sm->p_log, OSM_LOG_DEBUG,
100 "Getting %s (0x%X), modifier 0x%X, TID 0x%" PRIx64 "\n",
101 ib_get_sm_attr_str(attr_id), cl_ntoh16(attr_id),
102 cl_ntoh32(attr_mod), cl_ntoh64(tid));
104 ib_smp_init_new(osm_madw_get_smp_ptr(p_madw),
110 sm->p_subn->opt.m_key,
111 p_path->path, IB_LID_PERMISSIVE, IB_LID_PERMISSIVE);
113 p_madw->mad_addr.dest_lid = IB_LID_PERMISSIVE;
114 p_madw->mad_addr.addr_type.smi.source_lid = IB_LID_PERMISSIVE;
115 p_madw->resp_expected = TRUE;
116 p_madw->fail_msg = err_msg;
119 Fill in the mad wrapper context for the recipient.
120 In this case, the only thing the recipient needs is the
125 p_madw->context = *p_context;
127 osm_vl15_post(sm->p_vl15, p_madw);
130 OSM_LOG_EXIT(sm->p_log);
134 /**********************************************************************
135 The plock MAY or MAY NOT be held before calling this function.
136 **********************************************************************/
138 osm_req_set(IN osm_sm_t * sm,
139 IN const osm_dr_path_t * const p_path,
140 IN const uint8_t * const p_payload,
141 IN const size_t payload_size,
142 IN const uint16_t attr_id,
143 IN const uint32_t attr_mod,
144 IN const cl_disp_msgid_t err_msg,
145 IN const osm_madw_context_t * const p_context)
148 ib_api_status_t status = IB_SUCCESS;
153 OSM_LOG_ENTER(sm->p_log);
157 CL_ASSERT(p_payload);
159 /* do nothing if we are exiting ... */
163 /* p_context may be NULL. */
165 p_madw = osm_mad_pool_get(sm->p_mad_pool,
166 p_path->h_bind, MAD_BLOCK_SIZE, NULL);
168 if (p_madw == NULL) {
169 OSM_LOG(sm->p_log, OSM_LOG_ERROR,
170 "ERR 1102: Unable to acquire MAD\n");
171 status = IB_INSUFFICIENT_RESOURCES;
175 tid = cl_hton64((uint64_t) cl_atomic_inc(&sm->sm_trans_id));
177 OSM_LOG(sm->p_log, OSM_LOG_DEBUG,
178 "Setting %s (0x%X), modifier 0x%X, TID 0x%" PRIx64 "\n",
179 ib_get_sm_attr_str(attr_id), cl_ntoh16(attr_id),
180 cl_ntoh32(attr_mod), cl_ntoh64(tid));
182 ib_smp_init_new(osm_madw_get_smp_ptr(p_madw),
188 sm->p_subn->opt.m_key,
189 p_path->path, IB_LID_PERMISSIVE, IB_LID_PERMISSIVE);
191 p_madw->mad_addr.dest_lid = IB_LID_PERMISSIVE;
192 p_madw->mad_addr.addr_type.smi.source_lid = IB_LID_PERMISSIVE;
193 p_madw->resp_expected = TRUE;
194 p_madw->fail_msg = err_msg;
197 Fill in the mad wrapper context for the recipient.
198 In this case, the only thing the recipient needs is the
203 p_madw->context = *p_context;
205 memcpy(osm_madw_get_smp_ptr(p_madw)->data, p_payload, payload_size);
207 osm_vl15_post(sm->p_vl15, p_madw);
210 OSM_LOG_EXIT(sm->p_log);
214 int osm_send_trap144(osm_sm_t *sm, ib_net16_t local)
218 ib_mad_notice_attr_t *ntc;
222 port = osm_get_port_by_guid(sm->p_subn, sm->p_subn->sm_port_guid);
224 OSM_LOG(sm->p_log, OSM_LOG_ERROR,
225 "ERR 1104: cannot find SM port by guid 0x%" PRIx64 "\n",
226 cl_ntoh64(sm->p_subn->sm_port_guid));
230 pi = &port->p_physp->port_info;
232 /* don't bother with sending trap when SMA supports this */
234 pi->capability_mask&(IB_PORT_CAP_HAS_TRAP|IB_PORT_CAP_HAS_CAP_NTC))
237 madw = osm_mad_pool_get(sm->p_mad_pool,
238 osm_sm_mad_ctrl_get_bind_handle(&sm->mad_ctrl),
239 MAD_BLOCK_SIZE, NULL);
241 OSM_LOG(sm->p_log, OSM_LOG_ERROR,
242 "ERR 1105: Unable to acquire MAD\n");
246 madw->mad_addr.dest_lid = pi->master_sm_base_lid;
247 madw->mad_addr.addr_type.smi.source_lid = pi->base_lid;
248 madw->fail_msg = CL_DISP_MSGID_NONE;
250 smp = osm_madw_get_smp_ptr(madw);
251 memset(smp, 0, sizeof(*smp));
254 smp->mgmt_class = IB_MCLASS_SUBN_LID;
256 smp->method = IB_MAD_METHOD_TRAP;
257 smp->trans_id = cl_hton64((uint64_t)cl_atomic_inc(&sm->sm_trans_id));
258 smp->attr_id = IB_MAD_ATTR_NOTICE;
259 smp->m_key = sm->p_subn->opt.m_key;
261 ntc = (ib_mad_notice_attr_t *)smp->data;
263 ntc->generic_type = 0x80 | IB_NOTICE_TYPE_INFO;
264 ib_notice_set_prod_type_ho(ntc, IB_NODE_TYPE_CA);
265 ntc->g_or_v.generic.trap_num = cl_hton16(144);
266 ntc->issuer_lid = pi->base_lid;
267 ntc->data_details.ntc_144.lid = pi->base_lid;
268 ntc->data_details.ntc_144.local_changes = local ?
269 TRAP_144_MASK_OTHER_LOCAL_CHANGES : 0;
270 ntc->data_details.ntc_144.new_cap_mask = pi->capability_mask;
271 ntc->data_details.ntc_144.change_flgs = local;
273 OSM_LOG(sm->p_log, OSM_LOG_DEBUG,
274 "Sending Trap 144, TID 0x%" PRIx64 " to SM lid %u\n",
275 cl_ntoh64(smp->trans_id), cl_ntoh16(pi->master_sm_base_lid));
277 osm_vl15_post(sm->p_vl15, madw);