1321936Shselasky/* 2321936Shselasky * Copyright (c) 2004-2009 Voltaire Inc. All rights reserved. 3321936Shselasky * 4321936Shselasky * This software is available to you under a choice of one of two 5321936Shselasky * licenses. You may choose to be licensed under the terms of the GNU 6321936Shselasky * General Public License (GPL) Version 2, available from the file 7321936Shselasky * COPYING in the main directory of this source tree, or the 8321936Shselasky * OpenIB.org BSD license below: 9321936Shselasky * 10321936Shselasky * Redistribution and use in source and binary forms, with or 11321936Shselasky * without modification, are permitted provided that the following 12321936Shselasky * conditions are met: 13321936Shselasky * 14321936Shselasky * - Redistributions of source code must retain the above 15321936Shselasky * copyright notice, this list of conditions and the following 16321936Shselasky * disclaimer. 17321936Shselasky * 18321936Shselasky * - Redistributions in binary form must reproduce the above 19321936Shselasky * copyright notice, this list of conditions and the following 20321936Shselasky * disclaimer in the documentation and/or other materials 21321936Shselasky * provided with the distribution. 22321936Shselasky * 23321936Shselasky * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 24321936Shselasky * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 25321936Shselasky * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 26321936Shselasky * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 27321936Shselasky * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 28321936Shselasky * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 29321936Shselasky * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 30321936Shselasky * SOFTWARE. 31321936Shselasky * 32321936Shselasky */ 33321936Shselasky 34321936Shselasky#if HAVE_CONFIG_H 35321936Shselasky# include <config.h> 36321936Shselasky#endif /* HAVE_CONFIG_H */ 37321936Shselasky 38321936Shselasky#include <string.h> 39321936Shselasky 40321936Shselasky#include <infiniband/mad.h> 41321936Shselasky 42321936Shselasky#undef DEBUG 43321936Shselasky#define DEBUG if (ibdebug) IBWARN 44321936Shselasky 45321936Shselaskystatic inline int response_expected(int method) 46321936Shselasky{ 47321936Shselasky return method == IB_MAD_METHOD_GET || 48321936Shselasky method == IB_MAD_METHOD_SET || method == IB_MAD_METHOD_TRAP; 49321936Shselasky} 50321936Shselasky 51321936Shselaskyuint8_t *bm_call_via(void *data, ib_portid_t * portid, ib_bm_call_t * call, 52321936Shselasky struct ibmad_port * srcport) 53321936Shselasky{ 54321936Shselasky ib_rpc_t rpc = { 0 }; 55321936Shselasky int resp_expected; 56321936Shselasky struct { 57321936Shselasky uint64_t bkey; 58321936Shselasky uint8_t reserved[32]; 59321936Shselasky uint8_t data[IB_BM_DATA_SZ]; 60321936Shselasky } bm_data; 61321936Shselasky 62321936Shselasky DEBUG("route %s data %p", portid2str(portid), data); 63321936Shselasky if (portid->lid <= 0) { 64321936Shselasky IBWARN("only lid routes are supported"); 65321936Shselasky return NULL; 66321936Shselasky } 67321936Shselasky 68321936Shselasky resp_expected = response_expected(call->method); 69321936Shselasky 70321936Shselasky rpc.mgtclass = IB_BOARD_MGMT_CLASS; 71321936Shselasky 72321936Shselasky rpc.method = call->method; 73321936Shselasky rpc.attr.id = call->attrid; 74321936Shselasky rpc.attr.mod = call->mod; 75321936Shselasky rpc.timeout = resp_expected ? call->timeout : 0; 76321936Shselasky // send data and bkey 77321936Shselasky rpc.datasz = IB_BM_BKEY_AND_DATA_SZ; 78321936Shselasky rpc.dataoffs = IB_BM_BKEY_OFFS; 79321936Shselasky 80321936Shselasky // copy data to a buffer which also includes the bkey 81321936Shselasky bm_data.bkey = htonll(call->bkey); 82321936Shselasky memset(bm_data.reserved, 0, sizeof(bm_data.reserved)); 83321936Shselasky memcpy(bm_data.data, data, IB_BM_DATA_SZ); 84321936Shselasky 85321936Shselasky DEBUG 86321936Shselasky ("method 0x%x attr 0x%x mod 0x%x datasz %d off %d res_ex %d bkey 0x%08x%08x", 87321936Shselasky rpc.method, rpc.attr.id, rpc.attr.mod, rpc.datasz, rpc.dataoffs, 88321936Shselasky resp_expected, (int)(call->bkey >> 32), (int)call->bkey); 89321936Shselasky 90321936Shselasky portid->qp = 1; 91321936Shselasky if (!portid->qkey) 92321936Shselasky portid->qkey = IB_DEFAULT_QP1_QKEY; 93321936Shselasky 94321936Shselasky if (resp_expected) { 95321936Shselasky /* FIXME: no RMPP for now */ 96321936Shselasky if (mad_rpc(srcport, &rpc, portid, &bm_data, &bm_data)) 97321936Shselasky goto return_ok; 98321936Shselasky return NULL; 99321936Shselasky } 100321936Shselasky 101321936Shselasky if (mad_send_via(&rpc, portid, 0, &bm_data, srcport) < 0) 102321936Shselasky return NULL; 103321936Shselasky 104321936Shselaskyreturn_ok: 105321936Shselasky memcpy(data, bm_data.data, IB_BM_DATA_SZ); 106321936Shselasky return data; 107321936Shselasky} 108