xref: /freebsd/contrib/ofed/libibmad/gs.c (revision 87181516ef48be852d5e5fee53c6e0dbfc62f21e)
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 
47*d6b92ffaSHans Petter Selasky #undef DEBUG
48*d6b92ffaSHans Petter Selasky #define DEBUG 	if (ibdebug)	IBWARN
49*d6b92ffaSHans Petter Selasky 
pma_query_via(void * rcvbuf,ib_portid_t * dest,int port,unsigned timeout,unsigned id,const struct ibmad_port * srcport)50*d6b92ffaSHans Petter Selasky uint8_t *pma_query_via(void *rcvbuf, ib_portid_t * dest, int port,
51*d6b92ffaSHans Petter Selasky 		       unsigned timeout, unsigned id,
52*d6b92ffaSHans Petter Selasky 		       const struct ibmad_port * srcport)
53*d6b92ffaSHans Petter Selasky {
54*d6b92ffaSHans Petter Selasky 	ib_rpc_v1_t rpc = { 0 };
55*d6b92ffaSHans Petter Selasky 	ib_rpc_t *rpcold = (ib_rpc_t *)(void *)&rpc;
56*d6b92ffaSHans Petter Selasky 	int lid = dest->lid;
57*d6b92ffaSHans Petter Selasky 	void *p_ret;
58*d6b92ffaSHans Petter Selasky 
59*d6b92ffaSHans Petter Selasky 	DEBUG("lid %u port %d", lid, port);
60*d6b92ffaSHans Petter Selasky 
61*d6b92ffaSHans Petter Selasky 	if (lid == -1) {
62*d6b92ffaSHans Petter Selasky 		IBWARN("only lid routed is supported");
63*d6b92ffaSHans Petter Selasky 		return NULL;
64*d6b92ffaSHans Petter Selasky 	}
65*d6b92ffaSHans Petter Selasky 
66*d6b92ffaSHans Petter Selasky 	rpc.mgtclass = IB_PERFORMANCE_CLASS | IB_MAD_RPC_VERSION1;
67*d6b92ffaSHans Petter Selasky 	rpc.method = IB_MAD_METHOD_GET;
68*d6b92ffaSHans Petter Selasky 	rpc.attr.id = id;
69*d6b92ffaSHans Petter Selasky 
70*d6b92ffaSHans Petter Selasky 	/* Same for attribute IDs */
71*d6b92ffaSHans Petter Selasky 	mad_set_field(rcvbuf, 0, IB_PC_PORT_SELECT_F, port);
72*d6b92ffaSHans Petter Selasky 	rpc.attr.mod = 0;
73*d6b92ffaSHans Petter Selasky 	rpc.timeout = timeout;
74*d6b92ffaSHans Petter Selasky 	rpc.datasz = IB_PC_DATA_SZ;
75*d6b92ffaSHans Petter Selasky 	rpc.dataoffs = IB_PC_DATA_OFFS;
76*d6b92ffaSHans Petter Selasky 
77*d6b92ffaSHans Petter Selasky 	if (!dest->qp)
78*d6b92ffaSHans Petter Selasky 		dest->qp = 1;
79*d6b92ffaSHans Petter Selasky 	if (!dest->qkey)
80*d6b92ffaSHans Petter Selasky 		dest->qkey = IB_DEFAULT_QP1_QKEY;
81*d6b92ffaSHans Petter Selasky 
82*d6b92ffaSHans Petter Selasky 	p_ret = mad_rpc(srcport, rpcold, dest, rcvbuf, rcvbuf);
83*d6b92ffaSHans Petter Selasky 	errno = rpc.error;
84*d6b92ffaSHans Petter Selasky 	return p_ret;
85*d6b92ffaSHans Petter Selasky }
86*d6b92ffaSHans Petter Selasky 
performance_reset_via(void * rcvbuf,ib_portid_t * dest,int port,unsigned mask,unsigned timeout,unsigned id,const struct ibmad_port * srcport)87*d6b92ffaSHans Petter Selasky uint8_t *performance_reset_via(void *rcvbuf, ib_portid_t * dest,
88*d6b92ffaSHans Petter Selasky 			       int port, unsigned mask, unsigned timeout,
89*d6b92ffaSHans Petter Selasky 			       unsigned id, const struct ibmad_port * srcport)
90*d6b92ffaSHans Petter Selasky {
91*d6b92ffaSHans Petter Selasky 	ib_rpc_v1_t rpc = { 0 };
92*d6b92ffaSHans Petter Selasky 	ib_rpc_t *rpcold = (ib_rpc_t *)(void *)&rpc;
93*d6b92ffaSHans Petter Selasky 
94*d6b92ffaSHans Petter Selasky 	int lid = dest->lid;
95*d6b92ffaSHans Petter Selasky 	void *p_ret;
96*d6b92ffaSHans Petter Selasky 
97*d6b92ffaSHans Petter Selasky 	DEBUG("lid %u port %d mask 0x%x", lid, port, mask);
98*d6b92ffaSHans Petter Selasky 
99*d6b92ffaSHans Petter Selasky 	if (lid == -1) {
100*d6b92ffaSHans Petter Selasky 		IBWARN("only lid routed is supported");
101*d6b92ffaSHans Petter Selasky 		return NULL;
102*d6b92ffaSHans Petter Selasky 	}
103*d6b92ffaSHans Petter Selasky 
104*d6b92ffaSHans Petter Selasky 	if (!mask)
105*d6b92ffaSHans Petter Selasky 		mask = ~0;
106*d6b92ffaSHans Petter Selasky 
107*d6b92ffaSHans Petter Selasky 	rpc.mgtclass = IB_PERFORMANCE_CLASS | IB_MAD_RPC_VERSION1;
108*d6b92ffaSHans Petter Selasky 	rpc.method = IB_MAD_METHOD_SET;
109*d6b92ffaSHans Petter Selasky 	rpc.attr.id = id;
110*d6b92ffaSHans Petter Selasky 
111*d6b92ffaSHans Petter Selasky 	memset(rcvbuf, 0, IB_MAD_SIZE);
112*d6b92ffaSHans Petter Selasky 
113*d6b92ffaSHans Petter Selasky 	/* Next 2 lines - same for attribute IDs */
114*d6b92ffaSHans Petter Selasky 	mad_set_field(rcvbuf, 0, IB_PC_PORT_SELECT_F, port);
115*d6b92ffaSHans Petter Selasky 	mad_set_field(rcvbuf, 0, IB_PC_COUNTER_SELECT_F, mask);
116*d6b92ffaSHans Petter Selasky 	mask = mask >> 16;
117*d6b92ffaSHans Petter Selasky 	if (id == IB_GSI_PORT_COUNTERS_EXT)
118*d6b92ffaSHans Petter Selasky 		mad_set_field(rcvbuf, 0, IB_PC_EXT_COUNTER_SELECT2_F, mask);
119*d6b92ffaSHans Petter Selasky 	else
120*d6b92ffaSHans Petter Selasky 		mad_set_field(rcvbuf, 0, IB_PC_COUNTER_SELECT2_F, mask);
121*d6b92ffaSHans Petter Selasky 	rpc.attr.mod = 0;
122*d6b92ffaSHans Petter Selasky 	rpc.timeout = timeout;
123*d6b92ffaSHans Petter Selasky 	rpc.datasz = IB_PC_DATA_SZ;
124*d6b92ffaSHans Petter Selasky 	rpc.dataoffs = IB_PC_DATA_OFFS;
125*d6b92ffaSHans Petter Selasky 	if (!dest->qp)
126*d6b92ffaSHans Petter Selasky 		dest->qp = 1;
127*d6b92ffaSHans Petter Selasky 	if (!dest->qkey)
128*d6b92ffaSHans Petter Selasky 		dest->qkey = IB_DEFAULT_QP1_QKEY;
129*d6b92ffaSHans Petter Selasky 
130*d6b92ffaSHans Petter Selasky 	p_ret = mad_rpc(srcport, rpcold, dest, rcvbuf, rcvbuf);
131*d6b92ffaSHans Petter Selasky 	errno = rpc.error;
132*d6b92ffaSHans Petter Selasky 	return p_ret;
133*d6b92ffaSHans Petter Selasky }
134