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