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_resp_t.
39 * This object represents the generic attribute responder.
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 **********************************************************************/
62 osm_resp_make_resp_smp(IN osm_sm_t * sm,
63 IN const ib_smp_t * const p_src_smp,
64 IN const ib_net16_t status,
65 IN const uint8_t * const p_payload,
66 OUT ib_smp_t * const p_dest_smp)
68 OSM_LOG_ENTER(sm->p_log);
70 CL_ASSERT(p_dest_smp);
72 CL_ASSERT(!ib_smp_is_response(p_src_smp));
74 *p_dest_smp = *p_src_smp;
75 if (p_src_smp->method == IB_MAD_METHOD_GET ||
76 p_src_smp->method == IB_MAD_METHOD_SET) {
77 p_dest_smp->method = IB_MAD_METHOD_GET_RESP;
78 p_dest_smp->status = status;
79 } else if (p_src_smp->method == IB_MAD_METHOD_TRAP) {
80 p_dest_smp->method = IB_MAD_METHOD_TRAP_REPRESS;
81 p_dest_smp->status = 0;
83 OSM_LOG(sm->p_log, OSM_LOG_ERROR, "ERR 1302: "
84 "src smp method unsupported 0x%X\n", p_src_smp->method);
88 if (p_src_smp->mgmt_class == IB_MCLASS_SUBN_DIR)
89 p_dest_smp->status |= IB_SMP_DIRECTION;
91 p_dest_smp->dr_dlid = p_dest_smp->dr_slid;
92 p_dest_smp->dr_slid = p_dest_smp->dr_dlid;
93 memcpy(&p_dest_smp->data, p_payload, IB_SMP_DATA_SIZE);
96 OSM_LOG_EXIT(sm->p_log);
99 /**********************************************************************
100 **********************************************************************/
102 osm_resp_send(IN osm_sm_t * sm,
103 IN const osm_madw_t * const p_req_madw,
104 IN const ib_net16_t mad_status,
105 IN const uint8_t * const p_payload)
107 const ib_smp_t *p_req_smp;
110 ib_api_status_t status = IB_SUCCESS;
112 OSM_LOG_ENTER(sm->p_log);
114 CL_ASSERT(p_req_madw);
115 CL_ASSERT(p_payload);
117 /* do nothing if we are exiting ... */
121 p_madw = osm_mad_pool_get(sm->p_mad_pool,
122 osm_madw_get_bind_handle(p_req_madw),
123 MAD_BLOCK_SIZE, NULL);
125 if (p_madw == NULL) {
126 OSM_LOG(sm->p_log, OSM_LOG_ERROR,
127 "ERR 1301: Unable to acquire MAD\n");
128 status = IB_INSUFFICIENT_RESOURCES;
133 Copy the request smp to the response smp, then just
134 update the necessary fields.
136 p_smp = osm_madw_get_smp_ptr(p_madw);
137 p_req_smp = osm_madw_get_smp_ptr(p_req_madw);
138 osm_resp_make_resp_smp(sm, p_req_smp, mad_status, p_payload, p_smp);
139 p_madw->mad_addr.dest_lid =
140 p_req_madw->mad_addr.addr_type.smi.source_lid;
141 p_madw->mad_addr.addr_type.smi.source_lid =
142 p_req_madw->mad_addr.dest_lid;
144 p_madw->resp_expected = FALSE;
145 p_madw->fail_msg = CL_DISP_MSGID_NONE;
147 OSM_LOG(sm->p_log, OSM_LOG_DEBUG, "Responding to %s (0x%X)"
148 "\n\t\t\t\tattribute modifier 0x%X, TID 0x%" PRIx64 "\n",
149 ib_get_sm_attr_str(p_smp->attr_id), cl_ntoh16(p_smp->attr_id),
150 cl_ntoh32(p_smp->attr_mod), cl_ntoh64(p_smp->trans_id));
152 osm_vl15_post(sm->p_vl15, p_madw);
155 OSM_LOG_EXIT(sm->p_log);