1 /*
2 * Copyright (c) 2004-2009 Voltaire Inc. All rights reserved.
3 * Copyright (c) 2011 Mellanox Technologies LTD. All rights reserved.
4 *
5 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU
7 * General Public License (GPL) Version 2, available from the file
8 * COPYING in the main directory of this source tree, or the
9 * OpenIB.org BSD license below:
10 *
11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following
13 * conditions are met:
14 *
15 * - Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
17 * disclaimer.
18 *
19 * - Redistributions in binary form must reproduce the above
20 * copyright notice, this list of conditions and the following
21 * disclaimer in the documentation and/or other materials
22 * provided with the distribution.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31 * SOFTWARE.
32 *
33 */
34
35 #if HAVE_CONFIG_H
36 # include <config.h>
37 #endif /* HAVE_CONFIG_H */
38
39 #include <stdio.h>
40 #include <stdlib.h>
41 #include <string.h>
42 #include <errno.h>
43
44 #include <infiniband/umad.h>
45 #include <infiniband/mad.h>
46
47 #undef DEBUG
48 #define DEBUG if (ibdebug) IBWARN
49
pma_query_via(void * rcvbuf,ib_portid_t * dest,int port,unsigned timeout,unsigned id,const struct ibmad_port * srcport)50 uint8_t *pma_query_via(void *rcvbuf, ib_portid_t * dest, int port,
51 unsigned timeout, unsigned id,
52 const struct ibmad_port * srcport)
53 {
54 ib_rpc_v1_t rpc = { 0 };
55 ib_rpc_t *rpcold = (ib_rpc_t *)(void *)&rpc;
56 int lid = dest->lid;
57 void *p_ret;
58
59 DEBUG("lid %u port %d", lid, port);
60
61 if (lid == -1) {
62 IBWARN("only lid routed is supported");
63 return NULL;
64 }
65
66 rpc.mgtclass = IB_PERFORMANCE_CLASS | IB_MAD_RPC_VERSION1;
67 rpc.method = IB_MAD_METHOD_GET;
68 rpc.attr.id = id;
69
70 /* Same for attribute IDs */
71 mad_set_field(rcvbuf, 0, IB_PC_PORT_SELECT_F, port);
72 rpc.attr.mod = 0;
73 rpc.timeout = timeout;
74 rpc.datasz = IB_PC_DATA_SZ;
75 rpc.dataoffs = IB_PC_DATA_OFFS;
76
77 if (!dest->qp)
78 dest->qp = 1;
79 if (!dest->qkey)
80 dest->qkey = IB_DEFAULT_QP1_QKEY;
81
82 p_ret = mad_rpc(srcport, rpcold, dest, rcvbuf, rcvbuf);
83 errno = rpc.error;
84 return p_ret;
85 }
86
performance_reset_via(void * rcvbuf,ib_portid_t * dest,int port,unsigned mask,unsigned timeout,unsigned id,const struct ibmad_port * srcport)87 uint8_t *performance_reset_via(void *rcvbuf, ib_portid_t * dest,
88 int port, unsigned mask, unsigned timeout,
89 unsigned id, const struct ibmad_port * srcport)
90 {
91 ib_rpc_v1_t rpc = { 0 };
92 ib_rpc_t *rpcold = (ib_rpc_t *)(void *)&rpc;
93
94 int lid = dest->lid;
95 void *p_ret;
96
97 DEBUG("lid %u port %d mask 0x%x", lid, port, mask);
98
99 if (lid == -1) {
100 IBWARN("only lid routed is supported");
101 return NULL;
102 }
103
104 if (!mask)
105 mask = ~0;
106
107 rpc.mgtclass = IB_PERFORMANCE_CLASS | IB_MAD_RPC_VERSION1;
108 rpc.method = IB_MAD_METHOD_SET;
109 rpc.attr.id = id;
110
111 memset(rcvbuf, 0, IB_MAD_SIZE);
112
113 /* Next 2 lines - same for attribute IDs */
114 mad_set_field(rcvbuf, 0, IB_PC_PORT_SELECT_F, port);
115 mad_set_field(rcvbuf, 0, IB_PC_COUNTER_SELECT_F, mask);
116 mask = mask >> 16;
117 if (id == IB_GSI_PORT_COUNTERS_EXT)
118 mad_set_field(rcvbuf, 0, IB_PC_EXT_COUNTER_SELECT2_F, mask);
119 else
120 mad_set_field(rcvbuf, 0, IB_PC_COUNTER_SELECT2_F, mask);
121 rpc.attr.mod = 0;
122 rpc.timeout = timeout;
123 rpc.datasz = IB_PC_DATA_SZ;
124 rpc.dataoffs = IB_PC_DATA_OFFS;
125 if (!dest->qp)
126 dest->qp = 1;
127 if (!dest->qkey)
128 dest->qkey = IB_DEFAULT_QP1_QKEY;
129
130 p_ret = mad_rpc(srcport, rpcold, dest, rcvbuf, rcvbuf);
131 errno = rpc.error;
132 return p_ret;
133 }
134