1219820Sjeff/* 2219820Sjeff * Copyright (c) 2004-2008 Voltaire, Inc. All rights reserved. 3219820Sjeff * Copyright (c) 2002-2005 Mellanox Technologies LTD. All rights reserved. 4219820Sjeff * Copyright (c) 1996-2003 Intel Corporation. All rights reserved. 5219820Sjeff * 6219820Sjeff * This software is available to you under a choice of one of two 7219820Sjeff * licenses. You may choose to be licensed under the terms of the GNU 8219820Sjeff * General Public License (GPL) Version 2, available from the file 9219820Sjeff * COPYING in the main directory of this source tree, or the 10219820Sjeff * OpenIB.org BSD license below: 11219820Sjeff * 12219820Sjeff * Redistribution and use in source and binary forms, with or 13219820Sjeff * without modification, are permitted provided that the following 14219820Sjeff * conditions are met: 15219820Sjeff * 16219820Sjeff * - Redistributions of source code must retain the above 17219820Sjeff * copyright notice, this list of conditions and the following 18219820Sjeff * disclaimer. 19219820Sjeff * 20219820Sjeff * - Redistributions in binary form must reproduce the above 21219820Sjeff * copyright notice, this list of conditions and the following 22219820Sjeff * disclaimer in the documentation and/or other materials 23219820Sjeff * provided with the distribution. 24219820Sjeff * 25219820Sjeff * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 26219820Sjeff * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27219820Sjeff * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28219820Sjeff * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 29219820Sjeff * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 30219820Sjeff * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 31219820Sjeff * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 32219820Sjeff * SOFTWARE. 33219820Sjeff * 34219820Sjeff */ 35219820Sjeff 36219820Sjeff/* 37219820Sjeff * Abstract: 38219820Sjeff * Implementation of osm_resp_t. 39219820Sjeff * This object represents the generic attribute responder. 40219820Sjeff * This object is part of the opensm family of objects. 41219820Sjeff */ 42219820Sjeff 43219820Sjeff#if HAVE_CONFIG_H 44219820Sjeff# include <config.h> 45219820Sjeff#endif /* HAVE_CONFIG_H */ 46219820Sjeff 47219820Sjeff#include <string.h> 48219820Sjeff#include <iba/ib_types.h> 49219820Sjeff#include <complib/cl_debug.h> 50219820Sjeff#include <opensm/osm_madw.h> 51219820Sjeff#include <opensm/osm_attrib_req.h> 52219820Sjeff#include <opensm/osm_log.h> 53219820Sjeff#include <opensm/osm_helper.h> 54219820Sjeff#include <opensm/osm_mad_pool.h> 55219820Sjeff#include <opensm/osm_vl15intf.h> 56219820Sjeff#include <opensm/osm_msgdef.h> 57219820Sjeff#include <opensm/osm_opensm.h> 58219820Sjeff 59219820Sjeff/********************************************************************** 60219820Sjeff **********************************************************************/ 61219820Sjeffstatic void 62219820Sjeffosm_resp_make_resp_smp(IN osm_sm_t * sm, 63219820Sjeff IN const ib_smp_t * const p_src_smp, 64219820Sjeff IN const ib_net16_t status, 65219820Sjeff IN const uint8_t * const p_payload, 66219820Sjeff OUT ib_smp_t * const p_dest_smp) 67219820Sjeff{ 68219820Sjeff OSM_LOG_ENTER(sm->p_log); 69219820Sjeff 70219820Sjeff CL_ASSERT(p_dest_smp); 71219820Sjeff CL_ASSERT(p_src_smp); 72219820Sjeff CL_ASSERT(!ib_smp_is_response(p_src_smp)); 73219820Sjeff 74219820Sjeff *p_dest_smp = *p_src_smp; 75219820Sjeff if (p_src_smp->method == IB_MAD_METHOD_GET || 76219820Sjeff p_src_smp->method == IB_MAD_METHOD_SET) { 77219820Sjeff p_dest_smp->method = IB_MAD_METHOD_GET_RESP; 78219820Sjeff p_dest_smp->status = status; 79219820Sjeff } else if (p_src_smp->method == IB_MAD_METHOD_TRAP) { 80219820Sjeff p_dest_smp->method = IB_MAD_METHOD_TRAP_REPRESS; 81219820Sjeff p_dest_smp->status = 0; 82219820Sjeff } else { 83219820Sjeff OSM_LOG(sm->p_log, OSM_LOG_ERROR, "ERR 1302: " 84219820Sjeff "src smp method unsupported 0x%X\n", p_src_smp->method); 85219820Sjeff goto Exit; 86219820Sjeff } 87219820Sjeff 88219820Sjeff if (p_src_smp->mgmt_class == IB_MCLASS_SUBN_DIR) 89219820Sjeff p_dest_smp->status |= IB_SMP_DIRECTION; 90219820Sjeff 91219820Sjeff p_dest_smp->dr_dlid = p_dest_smp->dr_slid; 92219820Sjeff p_dest_smp->dr_slid = p_dest_smp->dr_dlid; 93219820Sjeff memcpy(&p_dest_smp->data, p_payload, IB_SMP_DATA_SIZE); 94219820Sjeff 95219820SjeffExit: 96219820Sjeff OSM_LOG_EXIT(sm->p_log); 97219820Sjeff} 98219820Sjeff 99219820Sjeff/********************************************************************** 100219820Sjeff **********************************************************************/ 101219820Sjeffib_api_status_t 102219820Sjeffosm_resp_send(IN osm_sm_t * sm, 103219820Sjeff IN const osm_madw_t * const p_req_madw, 104219820Sjeff IN const ib_net16_t mad_status, 105219820Sjeff IN const uint8_t * const p_payload) 106219820Sjeff{ 107219820Sjeff const ib_smp_t *p_req_smp; 108219820Sjeff ib_smp_t *p_smp; 109219820Sjeff osm_madw_t *p_madw; 110219820Sjeff ib_api_status_t status = IB_SUCCESS; 111219820Sjeff 112219820Sjeff OSM_LOG_ENTER(sm->p_log); 113219820Sjeff 114219820Sjeff CL_ASSERT(p_req_madw); 115219820Sjeff CL_ASSERT(p_payload); 116219820Sjeff 117219820Sjeff /* do nothing if we are exiting ... */ 118219820Sjeff if (osm_exit_flag) 119219820Sjeff goto Exit; 120219820Sjeff 121219820Sjeff p_madw = osm_mad_pool_get(sm->p_mad_pool, 122219820Sjeff osm_madw_get_bind_handle(p_req_madw), 123219820Sjeff MAD_BLOCK_SIZE, NULL); 124219820Sjeff 125219820Sjeff if (p_madw == NULL) { 126219820Sjeff OSM_LOG(sm->p_log, OSM_LOG_ERROR, 127219820Sjeff "ERR 1301: Unable to acquire MAD\n"); 128219820Sjeff status = IB_INSUFFICIENT_RESOURCES; 129219820Sjeff goto Exit; 130219820Sjeff } 131219820Sjeff 132219820Sjeff /* 133219820Sjeff Copy the request smp to the response smp, then just 134219820Sjeff update the necessary fields. 135219820Sjeff */ 136219820Sjeff p_smp = osm_madw_get_smp_ptr(p_madw); 137219820Sjeff p_req_smp = osm_madw_get_smp_ptr(p_req_madw); 138219820Sjeff osm_resp_make_resp_smp(sm, p_req_smp, mad_status, p_payload, p_smp); 139219820Sjeff p_madw->mad_addr.dest_lid = 140219820Sjeff p_req_madw->mad_addr.addr_type.smi.source_lid; 141219820Sjeff p_madw->mad_addr.addr_type.smi.source_lid = 142219820Sjeff p_req_madw->mad_addr.dest_lid; 143219820Sjeff 144219820Sjeff p_madw->resp_expected = FALSE; 145219820Sjeff p_madw->fail_msg = CL_DISP_MSGID_NONE; 146219820Sjeff 147219820Sjeff OSM_LOG(sm->p_log, OSM_LOG_DEBUG, "Responding to %s (0x%X)" 148219820Sjeff "\n\t\t\t\tattribute modifier 0x%X, TID 0x%" PRIx64 "\n", 149219820Sjeff ib_get_sm_attr_str(p_smp->attr_id), cl_ntoh16(p_smp->attr_id), 150219820Sjeff cl_ntoh32(p_smp->attr_mod), cl_ntoh64(p_smp->trans_id)); 151219820Sjeff 152219820Sjeff osm_vl15_post(sm->p_vl15, p_madw); 153219820Sjeff 154219820SjeffExit: 155219820Sjeff OSM_LOG_EXIT(sm->p_log); 156219820Sjeff return (status); 157219820Sjeff} 158