xref: /freebsd/contrib/ofed/libibmad/cc.c (revision 87181516ef48be852d5e5fee53c6e0dbfc62f21e)
1*d6b92ffaSHans Petter Selasky /*
2*d6b92ffaSHans Petter Selasky  * Copyright (c) 2011 Lawrence Livermore National Lab.  All rights reserved.
3*d6b92ffaSHans Petter Selasky  *
4*d6b92ffaSHans Petter Selasky  * This software is available to you under a choice of one of two
5*d6b92ffaSHans Petter Selasky  * licenses.  You may choose to be licensed under the terms of the GNU
6*d6b92ffaSHans Petter Selasky  * General Public License (GPL) Version 2, available from the file
7*d6b92ffaSHans Petter Selasky  * COPYING in the main directory of this source tree, or the
8*d6b92ffaSHans Petter Selasky  * OpenIB.org BSD license below:
9*d6b92ffaSHans Petter Selasky  *
10*d6b92ffaSHans Petter Selasky  *     Redistribution and use in source and binary forms, with or
11*d6b92ffaSHans Petter Selasky  *     without modification, are permitted provided that the following
12*d6b92ffaSHans Petter Selasky  *     conditions are met:
13*d6b92ffaSHans Petter Selasky  *
14*d6b92ffaSHans Petter Selasky  *      - Redistributions of source code must retain the above
15*d6b92ffaSHans Petter Selasky  *        copyright notice, this list of conditions and the following
16*d6b92ffaSHans Petter Selasky  *        disclaimer.
17*d6b92ffaSHans Petter Selasky  *
18*d6b92ffaSHans Petter Selasky  *      - Redistributions in binary form must reproduce the above
19*d6b92ffaSHans Petter Selasky  *        copyright notice, this list of conditions and the following
20*d6b92ffaSHans Petter Selasky  *        disclaimer in the documentation and/or other materials
21*d6b92ffaSHans Petter Selasky  *        provided with the distribution.
22*d6b92ffaSHans Petter Selasky  *
23*d6b92ffaSHans Petter Selasky  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24*d6b92ffaSHans Petter Selasky  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25*d6b92ffaSHans Petter Selasky  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26*d6b92ffaSHans Petter Selasky  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27*d6b92ffaSHans Petter Selasky  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28*d6b92ffaSHans Petter Selasky  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29*d6b92ffaSHans Petter Selasky  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30*d6b92ffaSHans Petter Selasky  * SOFTWARE.
31*d6b92ffaSHans Petter Selasky  *
32*d6b92ffaSHans Petter Selasky  */
33*d6b92ffaSHans Petter Selasky 
34*d6b92ffaSHans Petter Selasky #if HAVE_CONFIG_H
35*d6b92ffaSHans Petter Selasky #  include <config.h>
36*d6b92ffaSHans Petter Selasky #endif				/* HAVE_CONFIG_H */
37*d6b92ffaSHans Petter Selasky 
38*d6b92ffaSHans Petter Selasky #include <stdio.h>
39*d6b92ffaSHans Petter Selasky #include <stdlib.h>
40*d6b92ffaSHans Petter Selasky #include <string.h>
41*d6b92ffaSHans Petter Selasky 
42*d6b92ffaSHans Petter Selasky #include <infiniband/umad.h>
43*d6b92ffaSHans Petter Selasky #include <infiniband/mad.h>
44*d6b92ffaSHans Petter Selasky #include "mad_internal.h"
45*d6b92ffaSHans Petter Selasky 
46*d6b92ffaSHans Petter Selasky #undef DEBUG
47*d6b92ffaSHans Petter Selasky #define DEBUG 	if (ibdebug)	IBWARN
48*d6b92ffaSHans Petter Selasky 
cc_query_status_via(void * rcvbuf,ib_portid_t * portid,unsigned attrid,unsigned mod,unsigned timeout,int * rstatus,const struct ibmad_port * srcport,uint64_t cckey)49*d6b92ffaSHans Petter Selasky void *cc_query_status_via(void *rcvbuf, ib_portid_t * portid,
50*d6b92ffaSHans Petter Selasky 			  unsigned attrid, unsigned mod, unsigned timeout,
51*d6b92ffaSHans Petter Selasky 			  int *rstatus, const struct ibmad_port * srcport,
52*d6b92ffaSHans Petter Selasky 			  uint64_t cckey)
53*d6b92ffaSHans Petter Selasky {
54*d6b92ffaSHans Petter Selasky 	ib_rpc_cc_t rpc = { 0 };
55*d6b92ffaSHans Petter Selasky 	void *res;
56*d6b92ffaSHans Petter Selasky 
57*d6b92ffaSHans Petter Selasky 	DEBUG("attr 0x%x mod 0x%x route %s", attrid, mod, portid2str(portid));
58*d6b92ffaSHans Petter Selasky 	rpc.method = IB_MAD_METHOD_GET;
59*d6b92ffaSHans Petter Selasky 	rpc.attr.id = attrid;
60*d6b92ffaSHans Petter Selasky 	rpc.attr.mod = mod;
61*d6b92ffaSHans Petter Selasky 	rpc.timeout = timeout;
62*d6b92ffaSHans Petter Selasky 	if (attrid == IB_CC_ATTR_CONGESTION_LOG) {
63*d6b92ffaSHans Petter Selasky 		rpc.datasz = IB_CC_LOG_DATA_SZ;
64*d6b92ffaSHans Petter Selasky 		rpc.dataoffs = IB_CC_LOG_DATA_OFFS;
65*d6b92ffaSHans Petter Selasky 	}
66*d6b92ffaSHans Petter Selasky 	else {
67*d6b92ffaSHans Petter Selasky 		rpc.datasz = IB_CC_DATA_SZ;
68*d6b92ffaSHans Petter Selasky 		rpc.dataoffs = IB_CC_DATA_OFFS;
69*d6b92ffaSHans Petter Selasky 	}
70*d6b92ffaSHans Petter Selasky 	rpc.mgtclass = IB_CC_CLASS;
71*d6b92ffaSHans Petter Selasky 	rpc.cckey = cckey;
72*d6b92ffaSHans Petter Selasky 
73*d6b92ffaSHans Petter Selasky 	portid->qp = 1;
74*d6b92ffaSHans Petter Selasky 	if (!portid->qkey)
75*d6b92ffaSHans Petter Selasky 		portid->qkey = IB_DEFAULT_QP1_QKEY;
76*d6b92ffaSHans Petter Selasky 
77*d6b92ffaSHans Petter Selasky 	res = mad_rpc(srcport, (ib_rpc_t *)&rpc, portid, rcvbuf, rcvbuf);
78*d6b92ffaSHans Petter Selasky 	if (rstatus)
79*d6b92ffaSHans Petter Selasky 		*rstatus = rpc.rstatus;
80*d6b92ffaSHans Petter Selasky 
81*d6b92ffaSHans Petter Selasky 	return res;
82*d6b92ffaSHans Petter Selasky }
83*d6b92ffaSHans Petter Selasky 
cc_config_status_via(void * payload,void * rcvbuf,ib_portid_t * portid,unsigned attrid,unsigned mod,unsigned timeout,int * rstatus,const struct ibmad_port * srcport,uint64_t cckey)84*d6b92ffaSHans Petter Selasky void *cc_config_status_via(void *payload, void *rcvbuf, ib_portid_t * portid,
85*d6b92ffaSHans Petter Selasky                            unsigned attrid, unsigned mod, unsigned timeout,
86*d6b92ffaSHans Petter Selasky                            int *rstatus, const struct ibmad_port * srcport,
87*d6b92ffaSHans Petter Selasky                            uint64_t cckey)
88*d6b92ffaSHans Petter Selasky {
89*d6b92ffaSHans Petter Selasky 	ib_rpc_cc_t rpc = { 0 };
90*d6b92ffaSHans Petter Selasky 	void *res;
91*d6b92ffaSHans Petter Selasky 
92*d6b92ffaSHans Petter Selasky 	DEBUG("attr 0x%x mod 0x%x route %s", attrid, mod, portid2str(portid));
93*d6b92ffaSHans Petter Selasky 	rpc.method = IB_MAD_METHOD_SET;
94*d6b92ffaSHans Petter Selasky 	rpc.attr.id = attrid;
95*d6b92ffaSHans Petter Selasky 	rpc.attr.mod = mod;
96*d6b92ffaSHans Petter Selasky 	rpc.timeout = timeout;
97*d6b92ffaSHans Petter Selasky 	if (attrid == IB_CC_ATTR_CONGESTION_LOG) {
98*d6b92ffaSHans Petter Selasky 		rpc.datasz = IB_CC_LOG_DATA_SZ;
99*d6b92ffaSHans Petter Selasky 		rpc.dataoffs = IB_CC_LOG_DATA_OFFS;
100*d6b92ffaSHans Petter Selasky 	}
101*d6b92ffaSHans Petter Selasky 	else {
102*d6b92ffaSHans Petter Selasky 		rpc.datasz = IB_CC_DATA_SZ;
103*d6b92ffaSHans Petter Selasky 		rpc.dataoffs = IB_CC_DATA_OFFS;
104*d6b92ffaSHans Petter Selasky 	}
105*d6b92ffaSHans Petter Selasky 	rpc.mgtclass = IB_CC_CLASS;
106*d6b92ffaSHans Petter Selasky 	rpc.cckey = cckey;
107*d6b92ffaSHans Petter Selasky 
108*d6b92ffaSHans Petter Selasky 	portid->qp = 1;
109*d6b92ffaSHans Petter Selasky 	if (!portid->qkey)
110*d6b92ffaSHans Petter Selasky 		portid->qkey = IB_DEFAULT_QP1_QKEY;
111*d6b92ffaSHans Petter Selasky 
112*d6b92ffaSHans Petter Selasky 	res = mad_rpc(srcport, (ib_rpc_t *)&rpc, portid, payload, rcvbuf);
113*d6b92ffaSHans Petter Selasky 	if (rstatus)
114*d6b92ffaSHans Petter Selasky 		*rstatus = rpc.rstatus;
115*d6b92ffaSHans Petter Selasky 
116*d6b92ffaSHans Petter Selasky 	return res;
117*d6b92ffaSHans Petter Selasky }
118*d6b92ffaSHans Petter Selasky 
119*d6b92ffaSHans Petter Selasky 
120