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.
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_file_ids.h>
51 #define FILE_ID OSM_FILE_RESP_C
52 #include <opensm/osm_madw.h>
53 #include <opensm/osm_attrib_req.h>
54 #include <opensm/osm_log.h>
55 #include <opensm/osm_helper.h>
56 #include <opensm/osm_mad_pool.h>
57 #include <opensm/osm_vl15intf.h>
58 #include <opensm/osm_msgdef.h>
59 #include <opensm/osm_opensm.h>
61 static void resp_make_resp_smp(IN osm_sm_t * sm, IN const ib_smp_t * p_src_smp,
63 IN const uint8_t * p_payload,
64 OUT ib_smp_t * p_dest_smp)
66 OSM_LOG_ENTER(sm->p_log);
68 CL_ASSERT(p_dest_smp);
70 CL_ASSERT(!ib_smp_is_response(p_src_smp));
72 *p_dest_smp = *p_src_smp;
73 if (p_src_smp->method == IB_MAD_METHOD_GET ||
74 p_src_smp->method == IB_MAD_METHOD_SET) {
75 p_dest_smp->method = IB_MAD_METHOD_GET_RESP;
76 p_dest_smp->status = status;
77 } else if (p_src_smp->method == IB_MAD_METHOD_TRAP) {
78 p_dest_smp->method = IB_MAD_METHOD_TRAP_REPRESS;
79 p_dest_smp->status = 0;
81 OSM_LOG(sm->p_log, OSM_LOG_ERROR, "ERR 1302: "
82 "src smp method unsupported 0x%X\n", p_src_smp->method);
86 if (p_src_smp->mgmt_class == IB_MCLASS_SUBN_DIR)
87 p_dest_smp->status |= IB_SMP_DIRECTION;
89 p_dest_smp->dr_dlid = p_dest_smp->dr_slid;
90 p_dest_smp->dr_slid = p_dest_smp->dr_dlid;
91 memcpy(&p_dest_smp->data, p_payload, IB_SMP_DATA_SIZE);
94 OSM_LOG_EXIT(sm->p_log);
97 ib_api_status_t osm_resp_send(IN osm_sm_t * sm,
98 IN const osm_madw_t * p_req_madw,
99 IN ib_net16_t mad_status,
100 IN const uint8_t * p_payload)
102 const ib_smp_t *p_req_smp;
105 ib_api_status_t status = IB_SUCCESS;
107 OSM_LOG_ENTER(sm->p_log);
109 CL_ASSERT(p_req_madw);
110 CL_ASSERT(p_payload);
112 /* do nothing if we are exiting ... */
116 p_madw = osm_mad_pool_get(sm->p_mad_pool,
117 osm_madw_get_bind_handle(p_req_madw),
118 MAD_BLOCK_SIZE, NULL);
120 if (p_madw == NULL) {
121 OSM_LOG(sm->p_log, OSM_LOG_ERROR,
122 "ERR 1301: Unable to acquire MAD\n");
123 status = IB_INSUFFICIENT_RESOURCES;
128 Copy the request smp to the response smp, then just
129 update the necessary fields.
131 p_smp = osm_madw_get_smp_ptr(p_madw);
132 p_req_smp = osm_madw_get_smp_ptr(p_req_madw);
133 resp_make_resp_smp(sm, p_req_smp, mad_status, p_payload, p_smp);
134 p_madw->mad_addr.dest_lid =
135 p_req_madw->mad_addr.addr_type.smi.source_lid;
136 p_madw->mad_addr.addr_type.smi.source_lid =
137 p_req_madw->mad_addr.dest_lid;
139 p_madw->resp_expected = FALSE;
140 p_madw->fail_msg = CL_DISP_MSGID_NONE;
142 OSM_LOG(sm->p_log, OSM_LOG_DEBUG, "Responding to %s (0x%X)"
143 "\n\t\t\t\tattribute modifier 0x%X, TID 0x%" PRIx64 "\n",
144 ib_get_sm_attr_str(p_smp->attr_id), cl_ntoh16(p_smp->attr_id),
145 cl_ntoh32(p_smp->attr_mod), cl_ntoh64(p_smp->trans_id));
147 osm_vl15_post(sm->p_vl15, p_madw);
150 OSM_LOG_EXIT(sm->p_log);