]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/ofed/management/libibmad/src/gs.c
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / contrib / ofed / management / libibmad / src / gs.c
1 /*
2  * Copyright (c) 2004-2007 Voltaire Inc.  All rights reserved.
3  *
4  * This software is available to you under a choice of one of two
5  * licenses.  You may choose to be licensed under the terms of the GNU
6  * General Public License (GPL) Version 2, available from the file
7  * COPYING in the main directory of this source tree, or the
8  * OpenIB.org BSD license below:
9  *
10  *     Redistribution and use in source and binary forms, with or
11  *     without modification, are permitted provided that the following
12  *     conditions are met:
13  *
14  *      - Redistributions of source code must retain the above
15  *        copyright notice, this list of conditions and the following
16  *        disclaimer.
17  *
18  *      - Redistributions in binary form must reproduce the above
19  *        copyright notice, this list of conditions and the following
20  *        disclaimer in the documentation and/or other materials
21  *        provided with the distribution.
22  *
23  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30  * SOFTWARE.
31  *
32  */
33
34 #if HAVE_CONFIG_H
35 #  include <config.h>
36 #endif /* HAVE_CONFIG_H */
37
38 #include <stdio.h>
39 #include <stdlib.h>
40 #include <unistd.h>
41 #include <string.h>
42 #include <pthread.h>
43 #include <sys/time.h>
44
45 #include <infiniband/umad.h>
46 #include "mad.h"
47
48 #undef DEBUG
49 #define DEBUG   if (ibdebug)    IBWARN
50
51 static uint8_t *
52 pma_query_via(void *rcvbuf, ib_portid_t *dest, int port,
53               unsigned timeout, unsigned id, const void *srcport)
54 {
55         ib_rpc_t rpc = {0};
56         int lid = dest->lid;
57
58         DEBUG("lid %d port %d", lid, port);
59
60         if (lid == -1) {
61                 IBWARN("only lid routed is supported");
62                 return 0;
63         }
64
65         rpc.mgtclass = IB_PERFORMANCE_CLASS;
66         rpc.method = IB_MAD_METHOD_GET;
67         rpc.attr.id = id;
68
69         /* Same for attribute IDs */
70         mad_set_field(rcvbuf, 0, IB_PC_PORT_SELECT_F, port);
71         rpc.attr.mod = 0;
72         rpc.timeout = timeout;
73         rpc.datasz = IB_PC_DATA_SZ;
74         rpc.dataoffs = IB_PC_DATA_OFFS;
75
76         dest->qp = 1;
77         if (!dest->qkey)
78                 dest->qkey = IB_DEFAULT_QP1_QKEY;
79
80         if (srcport) {
81                 return mad_rpc(srcport, &rpc, dest, rcvbuf, rcvbuf);
82         } else {
83                 return madrpc(&rpc, dest, rcvbuf, rcvbuf);
84         }
85 }
86
87 uint8_t *
88 pma_query(void *rcvbuf, ib_portid_t *dest, int port, unsigned timeout, unsigned id)
89 {
90         return pma_query_via(rcvbuf, dest, port, timeout, id, NULL);
91 }
92
93 uint8_t *
94 perf_classportinfo_query_via(void *rcvbuf, ib_portid_t *dest, int port,
95                              unsigned timeout, const void *srcport)
96 {
97         return pma_query_via(rcvbuf, dest, port, timeout, CLASS_PORT_INFO,
98                              srcport);
99 }
100
101 uint8_t *
102 perf_classportinfo_query(void *rcvbuf, ib_portid_t *dest, int port, unsigned timeout)
103 {
104         return pma_query(rcvbuf, dest, port, timeout, CLASS_PORT_INFO);
105 }
106
107 uint8_t *
108 port_performance_query_via(void *rcvbuf, ib_portid_t *dest, int port,
109                            unsigned timeout, const void *srcport)
110 {
111         return pma_query_via(rcvbuf, dest, port, timeout,
112                              IB_GSI_PORT_COUNTERS, srcport);
113 }
114
115 uint8_t *
116 port_performance_query(void *rcvbuf, ib_portid_t *dest, int port, unsigned timeout)
117 {
118         return pma_query(rcvbuf, dest, port, timeout, IB_GSI_PORT_COUNTERS);
119 }
120
121 static uint8_t *
122 performance_reset_via(void *rcvbuf, ib_portid_t *dest, int port, unsigned mask,
123                       unsigned timeout, unsigned id, const void *srcport)
124 {
125         ib_rpc_t rpc = {0};
126         int lid = dest->lid;
127
128         DEBUG("lid %d port %d mask 0x%x", lid, port, mask);
129
130         if (lid == -1) {
131                 IBWARN("only lid routed is supported");
132                 return 0;
133         }
134
135         if (!mask)
136                 mask = ~0;
137
138         rpc.mgtclass = IB_PERFORMANCE_CLASS;
139         rpc.method = IB_MAD_METHOD_SET;
140         rpc.attr.id = id;
141
142         memset(rcvbuf, 0, IB_MAD_SIZE);
143
144         /* Same for attribute IDs */
145         mad_set_field(rcvbuf, 0, IB_PC_PORT_SELECT_F, port);
146         mad_set_field(rcvbuf, 0, IB_PC_COUNTER_SELECT_F, mask);
147         rpc.attr.mod = 0;
148         rpc.timeout = timeout;
149         rpc.datasz = IB_PC_DATA_SZ;
150         rpc.dataoffs = IB_PC_DATA_OFFS;
151         dest->qp = 1;
152         if (!dest->qkey)
153                 dest->qkey = IB_DEFAULT_QP1_QKEY;
154
155         if (srcport) {
156                 return mad_rpc(srcport, &rpc, dest, rcvbuf, rcvbuf);
157         } else {
158                 return madrpc(&rpc, dest, rcvbuf, rcvbuf);
159         }
160 }
161
162 static uint8_t *
163 performance_reset(void *rcvbuf, ib_portid_t *dest, int port, unsigned mask,
164                   unsigned timeout, unsigned id)
165 {
166         return performance_reset_via(rcvbuf, dest, port, mask, timeout,
167                                      id, NULL);
168 }
169
170 uint8_t *
171 port_performance_reset_via(void *rcvbuf, ib_portid_t *dest, int port,
172                            unsigned mask, unsigned timeout, const void *srcport)
173 {
174         return performance_reset_via(rcvbuf, dest, port, mask, timeout,
175                                      IB_GSI_PORT_COUNTERS, srcport);
176 }
177
178 uint8_t *
179 port_performance_reset(void *rcvbuf, ib_portid_t *dest, int port, unsigned mask,
180                        unsigned timeout)
181 {
182         return performance_reset(rcvbuf, dest, port, mask, timeout, IB_GSI_PORT_COUNTERS);
183 }
184
185 uint8_t *
186 port_performance_ext_query_via(void *rcvbuf, ib_portid_t *dest, int port,
187                                unsigned timeout, const void *srcport)
188 {
189         return pma_query_via(rcvbuf, dest, port, timeout,
190                              IB_GSI_PORT_COUNTERS_EXT, srcport);
191 }
192
193 uint8_t *
194 port_performance_ext_query(void *rcvbuf, ib_portid_t *dest, int port, unsigned timeout)
195 {
196         return pma_query(rcvbuf, dest, port, timeout, IB_GSI_PORT_COUNTERS_EXT);
197 }
198
199 uint8_t *
200 port_performance_ext_reset_via(void *rcvbuf, ib_portid_t *dest, int port,
201                                unsigned mask, unsigned timeout,
202                                const void *srcport)
203 {
204         return performance_reset_via(rcvbuf, dest, port, mask, timeout,
205                                      IB_GSI_PORT_COUNTERS_EXT, srcport);
206 }
207
208 uint8_t *
209 port_performance_ext_reset(void *rcvbuf, ib_portid_t *dest, int port, unsigned mask,
210                            unsigned timeout)
211 {
212         return performance_reset(rcvbuf, dest, port, mask, timeout, IB_GSI_PORT_COUNTERS_EXT);
213 }
214
215 uint8_t *
216 port_samples_control_query_via(void *rcvbuf, ib_portid_t *dest, int port,
217                                unsigned timeout, const void *srcport)
218 {
219         return pma_query_via(rcvbuf, dest, port, timeout,
220                              IB_GSI_PORT_SAMPLES_CONTROL, srcport);
221 }
222
223 uint8_t *
224 port_samples_control_query(void *rcvbuf, ib_portid_t *dest, int port, unsigned timeout)
225 {
226         return pma_query(rcvbuf, dest, port, timeout, IB_GSI_PORT_SAMPLES_CONTROL);
227 }
228
229 uint8_t *
230 port_samples_result_query_via(void *rcvbuf, ib_portid_t *dest, int port,
231                               unsigned timeout, const void *srcport)
232 {
233         return pma_query_via(rcvbuf, dest, port, timeout,
234                              IB_GSI_PORT_SAMPLES_RESULT, srcport);
235 }
236
237 uint8_t *
238 port_samples_result_query(void *rcvbuf, ib_portid_t *dest, int port,  unsigned timeout)
239 {
240         return pma_query(rcvbuf, dest, port, timeout, IB_GSI_PORT_SAMPLES_RESULT);
241 }