1*d6b92ffaSHans Petter Selasky /*
2*d6b92ffaSHans Petter Selasky * Copyright (c) 2004-2009 Voltaire Inc. All rights reserved.
3*d6b92ffaSHans Petter Selasky * Copyright (c) 2011 Mellanox Technologies LTD. All rights reserved.
4*d6b92ffaSHans Petter Selasky *
5*d6b92ffaSHans Petter Selasky * This software is available to you under a choice of one of two
6*d6b92ffaSHans Petter Selasky * licenses. You may choose to be licensed under the terms of the GNU
7*d6b92ffaSHans Petter Selasky * General Public License (GPL) Version 2, available from the file
8*d6b92ffaSHans Petter Selasky * COPYING in the main directory of this source tree, or the
9*d6b92ffaSHans Petter Selasky * OpenIB.org BSD license below:
10*d6b92ffaSHans Petter Selasky *
11*d6b92ffaSHans Petter Selasky * Redistribution and use in source and binary forms, with or
12*d6b92ffaSHans Petter Selasky * without modification, are permitted provided that the following
13*d6b92ffaSHans Petter Selasky * conditions are met:
14*d6b92ffaSHans Petter Selasky *
15*d6b92ffaSHans Petter Selasky * - Redistributions of source code must retain the above
16*d6b92ffaSHans Petter Selasky * copyright notice, this list of conditions and the following
17*d6b92ffaSHans Petter Selasky * disclaimer.
18*d6b92ffaSHans Petter Selasky *
19*d6b92ffaSHans Petter Selasky * - Redistributions in binary form must reproduce the above
20*d6b92ffaSHans Petter Selasky * copyright notice, this list of conditions and the following
21*d6b92ffaSHans Petter Selasky * disclaimer in the documentation and/or other materials
22*d6b92ffaSHans Petter Selasky * provided with the distribution.
23*d6b92ffaSHans Petter Selasky *
24*d6b92ffaSHans Petter Selasky * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25*d6b92ffaSHans Petter Selasky * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26*d6b92ffaSHans Petter Selasky * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27*d6b92ffaSHans Petter Selasky * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28*d6b92ffaSHans Petter Selasky * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29*d6b92ffaSHans Petter Selasky * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30*d6b92ffaSHans Petter Selasky * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31*d6b92ffaSHans Petter Selasky * SOFTWARE.
32*d6b92ffaSHans Petter Selasky *
33*d6b92ffaSHans Petter Selasky */
34*d6b92ffaSHans Petter Selasky
35*d6b92ffaSHans Petter Selasky #if HAVE_CONFIG_H
36*d6b92ffaSHans Petter Selasky # include <config.h>
37*d6b92ffaSHans Petter Selasky #endif /* HAVE_CONFIG_H */
38*d6b92ffaSHans Petter Selasky
39*d6b92ffaSHans Petter Selasky #include <stdio.h>
40*d6b92ffaSHans Petter Selasky #include <stdlib.h>
41*d6b92ffaSHans Petter Selasky #include <string.h>
42*d6b92ffaSHans Petter Selasky #include <errno.h>
43*d6b92ffaSHans Petter Selasky
44*d6b92ffaSHans Petter Selasky #include <infiniband/umad.h>
45*d6b92ffaSHans Petter Selasky #include <infiniband/mad.h>
46*d6b92ffaSHans Petter Selasky #include "mad_internal.h"
47*d6b92ffaSHans Petter Selasky
48*d6b92ffaSHans Petter Selasky #undef DEBUG
49*d6b92ffaSHans Petter Selasky #define DEBUG if (ibdebug) IBWARN
50*d6b92ffaSHans Petter Selasky
response_expected(int method)51*d6b92ffaSHans Petter Selasky static inline int response_expected(int method)
52*d6b92ffaSHans Petter Selasky {
53*d6b92ffaSHans Petter Selasky return method == IB_MAD_METHOD_GET ||
54*d6b92ffaSHans Petter Selasky method == IB_MAD_METHOD_SET || method == IB_MAD_METHOD_TRAP;
55*d6b92ffaSHans Petter Selasky }
56*d6b92ffaSHans Petter Selasky
ib_vendor_call(void * data,ib_portid_t * portid,ib_vendor_call_t * call)57*d6b92ffaSHans Petter Selasky uint8_t *ib_vendor_call(void *data, ib_portid_t * portid,
58*d6b92ffaSHans Petter Selasky ib_vendor_call_t * call)
59*d6b92ffaSHans Petter Selasky {
60*d6b92ffaSHans Petter Selasky return ib_vendor_call_via(data, portid, call, ibmp);
61*d6b92ffaSHans Petter Selasky }
62*d6b92ffaSHans Petter Selasky
ib_vendor_call_via(void * data,ib_portid_t * portid,ib_vendor_call_t * call,struct ibmad_port * srcport)63*d6b92ffaSHans Petter Selasky uint8_t *ib_vendor_call_via(void *data, ib_portid_t * portid,
64*d6b92ffaSHans Petter Selasky ib_vendor_call_t * call,
65*d6b92ffaSHans Petter Selasky struct ibmad_port * srcport)
66*d6b92ffaSHans Petter Selasky {
67*d6b92ffaSHans Petter Selasky ib_rpc_v1_t rpc = { 0 };
68*d6b92ffaSHans Petter Selasky ib_rpc_t *rpcold = (ib_rpc_t *)(void *)&rpc;
69*d6b92ffaSHans Petter Selasky int range1 = 0, resp_expected;
70*d6b92ffaSHans Petter Selasky void *p_ret;
71*d6b92ffaSHans Petter Selasky
72*d6b92ffaSHans Petter Selasky DEBUG("route %s data %p", portid2str(portid), data);
73*d6b92ffaSHans Petter Selasky if (portid->lid <= 0)
74*d6b92ffaSHans Petter Selasky return NULL; /* no direct SMI */
75*d6b92ffaSHans Petter Selasky
76*d6b92ffaSHans Petter Selasky if (!(range1 = mad_is_vendor_range1(call->mgmt_class)) &&
77*d6b92ffaSHans Petter Selasky !(mad_is_vendor_range2(call->mgmt_class)))
78*d6b92ffaSHans Petter Selasky return NULL;
79*d6b92ffaSHans Petter Selasky
80*d6b92ffaSHans Petter Selasky resp_expected = response_expected(call->method);
81*d6b92ffaSHans Petter Selasky
82*d6b92ffaSHans Petter Selasky rpc.mgtclass = call->mgmt_class | IB_MAD_RPC_VERSION1;
83*d6b92ffaSHans Petter Selasky
84*d6b92ffaSHans Petter Selasky rpc.method = call->method;
85*d6b92ffaSHans Petter Selasky rpc.attr.id = call->attrid;
86*d6b92ffaSHans Petter Selasky rpc.attr.mod = call->mod;
87*d6b92ffaSHans Petter Selasky rpc.timeout = resp_expected ? call->timeout : 0;
88*d6b92ffaSHans Petter Selasky rpc.datasz =
89*d6b92ffaSHans Petter Selasky range1 ? IB_VENDOR_RANGE1_DATA_SIZE : IB_VENDOR_RANGE2_DATA_SIZE;
90*d6b92ffaSHans Petter Selasky rpc.dataoffs =
91*d6b92ffaSHans Petter Selasky range1 ? IB_VENDOR_RANGE1_DATA_OFFS : IB_VENDOR_RANGE2_DATA_OFFS;
92*d6b92ffaSHans Petter Selasky
93*d6b92ffaSHans Petter Selasky if (!range1)
94*d6b92ffaSHans Petter Selasky rpc.oui = call->oui;
95*d6b92ffaSHans Petter Selasky
96*d6b92ffaSHans Petter Selasky DEBUG
97*d6b92ffaSHans Petter Selasky ("class 0x%x method 0x%x attr 0x%x mod 0x%x datasz %d off %d res_ex %d",
98*d6b92ffaSHans Petter Selasky rpc.mgtclass, rpc.method, rpc.attr.id, rpc.attr.mod, rpc.datasz,
99*d6b92ffaSHans Petter Selasky rpc.dataoffs, resp_expected);
100*d6b92ffaSHans Petter Selasky
101*d6b92ffaSHans Petter Selasky portid->qp = 1;
102*d6b92ffaSHans Petter Selasky if (!portid->qkey)
103*d6b92ffaSHans Petter Selasky portid->qkey = IB_DEFAULT_QP1_QKEY;
104*d6b92ffaSHans Petter Selasky
105*d6b92ffaSHans Petter Selasky if (resp_expected) {
106*d6b92ffaSHans Petter Selasky p_ret = mad_rpc_rmpp(srcport, rpcold, portid, 0, data); /* FIXME: no RMPP for now */
107*d6b92ffaSHans Petter Selasky errno = rpc.error;
108*d6b92ffaSHans Petter Selasky return p_ret;
109*d6b92ffaSHans Petter Selasky }
110*d6b92ffaSHans Petter Selasky
111*d6b92ffaSHans Petter Selasky return mad_send_via(rpcold, portid, 0, data, srcport) < 0 ? 0 : data; /* FIXME: no RMPP for now */
112*d6b92ffaSHans Petter Selasky }
113