aboutsummaryrefslogtreecommitdiff
blob: 497a69d027ece28b6d985275605eddd4e86e4010 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
diff --git a/infiniband-diags/configure.in b/infiniband-diags/configure.in
index 58eea0a..7d277b2 100644
--- a/infiniband-diags/configure.in
+++ b/infiniband-diags/configure.in
@@ -40,10 +40,6 @@ AC_CHECK_LIB(ibmad, port_performance_ext_query, [],
 	AC_MSG_ERROR([port_performance_ext_query() not found. diags require more recent libibmad.]))
 AC_CHECK_LIB(osmcomp, cl_thread_init, [],
 	AC_MSG_ERROR([cl_thread_init() not found. diags require libosmcomp.]))
-AC_CHECK_LIB(osmvendor, osmv_query_sa, [],
-	AC_MSG_ERROR([osmv_query_sa() not found. diags require libosmvendor.]), [-lopensm])
-AC_CHECK_LIB(opensm, osm_log_init_v2, [],
-	AC_MSG_ERROR([osm_log_init_v2() not found. diags require libopensm.]))
 fi
 
 dnl Checks for header files.
diff --git a/infiniband-diags/src/saquery.c b/infiniband-diags/src/saquery.c
index 5361184..0a997cf 100644
--- a/infiniband-diags/src/saquery.c
+++ b/infiniband-diags/src/saquery.c
@@ -42,20 +42,33 @@
 #include <arpa/inet.h>
 #include <ctype.h>
 #include <string.h>
+#include <errno.h>
 
 #define _GNU_SOURCE
 #include <getopt.h>
 
+#include <infiniband/umad.h>
 #include <infiniband/mad.h>
-#include <infiniband/opensm/osm_log.h>
-#include <infiniband/vendor/osm_vendor_api.h>
-#include <infiniband/vendor/osm_vendor_sa_api.h>
-#include <infiniband/opensm/osm_mad_pool.h>
+#include <infiniband/iba/ib_types.h>
 #include <infiniband/complib/cl_debug.h>
 #include <infiniband/complib/cl_nodenamemap.h>
 
 #include "ibdiag_common.h"
 
+struct sa_bind_handle {
+	int fd, agent;
+	ib_portid_t dport;
+};
+
+struct sa_result {
+	int status;
+	unsigned result_cnt;
+	void *p_result_madw;
+};
+
+#define osmv_query_res_t struct sa_result
+#define osm_bind_handle_t struct sa_bind_handle *
+
 struct query_params {
 	ib_gid_t sgid, dgid, gid, mgid;
 	uint16_t slid, dlid, mlid;
@@ -82,7 +95,7 @@ struct query_cmd {
 
 static char *node_name_map_file = NULL;
 static nn_map_t *node_name_map = NULL;
-static ib_net64_t smkey = OSM_DEFAULT_SA_KEY;
+static ib_net64_t smkey = CL_HTON64(1);
 
 /**
  * Declare some globals because I don't want this to be too complex.
@@ -90,11 +103,6 @@ static ib_net64_t smkey = OSM_DEFAULT_SA_KEY;
 #define MAX_PORTS (8)
 #define DEFAULT_SA_TIMEOUT_MS (1000)
 osmv_query_res_t result;
-osm_log_t log_osm;
-osm_mad_pool_t mad_pool;
-osm_vendor_t *vendor = NULL;
-char *sa_hca_name = NULL;
-uint32_t sa_port_num = 0;
 
 enum {
 	ALL,
@@ -112,6 +120,81 @@ int requested_lid_flag = 0;
 ib_net64_t requested_guid = 0;
 int requested_guid_flag = 0;
 
+static int sa_query(struct sa_bind_handle *h, uint8_t method,
+		    ib_net16_t attr, ib_net32_t mod, ib_net64_t comp_mask,
+		    ib_net64_t sm_key, void *data)
+{
+	ib_rpc_t rpc;
+	void *umad, *mad;
+	int ret, offset, len = 256;
+
+	memset(&rpc, 0, sizeof(rpc));
+	rpc.mgtclass = IB_SA_CLASS;
+	rpc.method = method;
+	rpc.attr.id = cl_ntoh16(attr);
+	rpc.attr.mod = cl_ntoh32(mod);
+	rpc.mask = cl_ntoh64(comp_mask);
+	rpc.datasz = IB_SA_DATA_SIZE;
+	rpc.dataoffs = IB_SA_DATA_OFFS;
+
+	umad = calloc(1, len + umad_size());
+	if (!umad)
+		IBPANIC("cannot alloc mem for umad: %s\n", strerror(errno));
+
+	mad_build_pkt(umad, &rpc, &h->dport, NULL, data);
+
+	/* SA SM_Key (36/8) - temporary done using IB_MAD_MKEY_F */
+	mad_set_field64(umad_get_mad(umad), 12, IB_MAD_MKEY_F, cl_hton64(sm_key));
+
+	if (ibdebug > 1)
+		xdump(stdout, "SA Request:\n", umad_get_mad(umad), len);
+
+	ret = umad_send(h->fd, h->agent, umad, len, ibd_timeout, 0);
+	if (ret < 0)
+		IBPANIC("umad_send failed: attr %u: %s\n",
+			attr, strerror(errno));
+
+recv_mad:
+	ret = umad_recv(h->fd, umad, &len, ibd_timeout);
+	if (ret < 0) {
+		if (errno == ENOSPC) {
+			umad = realloc(umad, umad_size() + len);
+			goto recv_mad;
+		}
+		IBPANIC("umad_recv failed: attr %u: %s\n", attr,
+			strerror(errno));
+	}
+
+	if ((ret = umad_status(umad)))
+		return ret;
+
+	mad = umad_get_mad(umad);
+
+	if (ibdebug > 1)
+		xdump(stdout, "SA Response:\n", mad, len);
+
+	method = mad_get_field(mad, 0, IB_MAD_METHOD_F);
+	offset = mad_get_field(mad, 0, IB_SA_ATTROFFS_F);
+	result.status = mad_get_field(mad, 0, IB_MAD_STATUS_F);
+	result.p_result_madw = mad;
+	if (result.status || !offset)
+		result.result_cnt = 0;
+	else if (method != IB_MAD_METHOD_GET_TABLE)
+		result.result_cnt = 1;
+	else
+		result.result_cnt = (len - IB_SA_DATA_OFFS) / (offset << 3);
+
+	return 0;
+}
+
+static void *osmv_get_query_result(void *mad, unsigned i)
+{
+	int offset = mad_get_field(mad, 0, IB_SA_ATTROFFS_F);
+	return mad + IB_SA_DATA_OFFS + i * (offset << 3);
+}
+
+#define osmv_get_query_node_rec(mad, i) osmv_get_query_result(mad, i)
+
 static unsigned valid_gid(ib_gid_t *gid)
 {
 	ib_gid_t zero_gid = { };
@@ -132,14 +215,6 @@ static void format_buf(char *in, char *out, unsigned size)
 	*out = '\0';
 }
 
-/**
- * Call back for the various record requests.
- */
-static void query_res_cb(osmv_query_res_t * res)
-{
-	result = *res;
-}
-
 static void print_node_desc(ib_node_record_t * node_record)
 {
 	ib_node_info_t *p_ni = &(node_record->node_info);
@@ -683,6 +758,7 @@ static void dump_one_mft_record(void *data)
 		       cl_ntoh16(mftr->mft[i]));
 	printf("\n");
 }
+
 static void dump_results(osmv_query_res_t * r, void (*dump_func) (void *))
 {
 	int i;
@@ -694,11 +770,8 @@ static void dump_results(osmv_query_res_t * r, void (*dump_func) (void *))
 
 static void return_mad(void)
 {
-	/*
-	 * Return the IB query MAD to the pool as necessary.
-	 */
-	if (result.p_result_madw != NULL) {
-		osm_mad_pool_put(&mad_pool, result.p_result_madw);
+	if (result.p_result_madw) {
+		free(result.p_result_madw - umad_size());
 		result.p_result_madw = NULL;
 	}
 }
@@ -711,32 +784,11 @@ get_any_records(osm_bind_handle_t h,
 		ib_net16_t attr_id, ib_net32_t attr_mod, ib_net64_t comp_mask,
 		void *attr, ib_net16_t attr_offset, ib_net64_t sm_key)
 {
-	ib_api_status_t status;
-	osmv_query_req_t req;
-	osmv_user_query_t user;
-
-	memset(&req, 0, sizeof(req));
-	memset(&user, 0, sizeof(user));
-
-	user.attr_id = attr_id;
-	user.attr_offset = attr_offset;
-	user.attr_mod = attr_mod;
-	user.comp_mask = comp_mask;
-	user.p_attr = attr;
-
-	req.query_type = OSMV_QUERY_USER_DEFINED;
-	req.timeout_ms = ibd_timeout;
-	req.retry_cnt = 1;
-	req.flags = OSM_SA_FLAGS_SYNC;
-	req.query_context = NULL;
-	req.pfn_query_cb = query_res_cb;
-	req.p_query_input = &user;
-	req.sm_key = sm_key;
-
-	if ((status = osmv_query_sa(h, &req)) != IB_SUCCESS) {
-		fprintf(stderr, "Query SA failed: %s\n",
-			ib_get_err_str(status));
-		return status;
+	int ret = sa_query(h, IB_MAD_METHOD_GET_TABLE, attr_id, attr_mod,
+			   comp_mask, sm_key, attr);
+	if (ret) {
+		fprintf(stderr, "Query SA failed: %s\n", ib_get_err_str(ret));
+		return ret;
 	}
 
 	if (result.status != IB_SUCCESS) {
@@ -745,7 +797,7 @@ get_any_records(osm_bind_handle_t h,
 		return result.status;
 	}
 
-	return status;
+	return ret;
 }
 
 /**
@@ -928,34 +980,21 @@ static ib_api_status_t print_node_records(osm_bind_handle_t h)
 
 static ib_api_status_t get_print_class_port_info(osm_bind_handle_t h)
 {
-	osmv_query_req_t req;
-	ib_api_status_t status;
-
-	memset(&req, 0, sizeof(req));
-
-	req.query_type = OSMV_QUERY_CLASS_PORT_INFO;
-	req.timeout_ms = ibd_timeout;
-	req.retry_cnt = 1;
-	req.flags = OSM_SA_FLAGS_SYNC;
-	req.query_context = NULL;
-	req.pfn_query_cb = query_res_cb;
-	req.p_query_input = NULL;
-	req.sm_key = 0;
-
-	if ((status = osmv_query_sa(h, &req)) != IB_SUCCESS) {
+	int ret = sa_query(h, IB_MAD_METHOD_GET, IB_MAD_ATTR_CLASS_PORT_INFO,
+			   0, 0, 0, NULL);
+	if (ret) {
 		fprintf(stderr, "ERROR: Query SA failed: %s\n",
-			ib_get_err_str(status));
-		return (status);
+			ib_get_err_str(ret));
+		return ret;
 	}
 	if (result.status != IB_SUCCESS) {
 		fprintf(stderr, "ERROR: Query result returned: %s\n",
 			ib_get_err_str(result.status));
 		return (result.status);
 	}
-	status = result.status;
 	dump_results(&result, dump_class_port_info);
 	return_mad();
-	return (status);
+	return ret;
 }
 
 static int query_path_records(const struct query_cmd *q, osm_bind_handle_t h,
@@ -1046,11 +1085,8 @@ static ib_api_status_t print_multicast_member_records(osm_bind_handle_t h)
 	return_mad();
 
 return_mc:
-	/* return_mad for the mc_group_result */
-	if (mc_group_result.p_result_madw != NULL) {
-		osm_mad_pool_put(&mad_pool, mc_group_result.p_result_madw);
-		mc_group_result.p_result_madw = NULL;
-	}
+	if (mc_group_result.p_result_madw)
+		free(mc_group_result.p_result_madw - umad_size());
 
 	return (status);
 }
@@ -1366,78 +1402,30 @@ static int query_mft_records(const struct query_cmd *q, osm_bind_handle_t h,
 
 static osm_bind_handle_t get_bind_handle(void)
 {
-	uint32_t i = 0;
-	uint64_t port_guid = (uint64_t) - 1;
-	osm_bind_handle_t h;
-	ib_api_status_t status;
-	ib_port_attr_t attr_array[MAX_PORTS];
-	uint32_t num_ports = MAX_PORTS;
-	uint32_t ca_name_index = 0;
-
-	complib_init();
-
-	osm_log_construct(&log_osm);
-	if ((status = osm_log_init_v2(&log_osm, TRUE, 0x0001, NULL,
-				      0, TRUE)) != IB_SUCCESS) {
-		fprintf(stderr, "Failed to init osm_log: %s\n",
-			ib_get_err_str(status));
-		exit(-1);
-	}
-	osm_log_set_level(&log_osm, OSM_LOG_NONE);
-	if (ibdebug)
-		osm_log_set_level(&log_osm, OSM_LOG_DEFAULT_LEVEL);
-
-	vendor = osm_vendor_new(&log_osm, ibd_timeout);
-	osm_mad_pool_construct(&mad_pool);
-	if ((status = osm_mad_pool_init(&mad_pool)) != IB_SUCCESS) {
-		fprintf(stderr, "Failed to init mad pool: %s\n",
-			ib_get_err_str(status));
-		exit(-1);
-	}
+	static struct sa_bind_handle handle;
+	int mgmt_classes[2] = { IB_SMI_CLASS, IB_SMI_DIRECT_CLASS };
 
-	if ((status =
-	     osm_vendor_get_all_port_attr(vendor, attr_array,
-					  &num_ports)) != IB_SUCCESS) {
-		fprintf(stderr, "Failed to get port attributes: %s\n",
-			ib_get_err_str(status));
-		exit(-1);
-	}
+	madrpc_init(ibd_ca, ibd_ca_port, mgmt_classes, 2);
 
-	for (i = 0; i < num_ports; i++) {
-		if (i > 1 && cl_ntoh64(attr_array[i].port_guid)
-		    != (cl_ntoh64(attr_array[i - 1].port_guid) + 1))
-			ca_name_index++;
-		if (sa_port_num && sa_port_num != attr_array[i].port_num)
-			continue;
-		if (sa_hca_name
-		    && strcmp(sa_hca_name,
-			      vendor->ca_names[ca_name_index]) != 0)
-			continue;
-		if (attr_array[i].link_state == IB_LINK_ACTIVE) {
-			port_guid = attr_array[i].port_guid;
-			break;
-		}
-	}
+	ib_resolve_smlid(&handle.dport, ibd_timeout);
+	if (!handle.dport.lid)
+		IBPANIC("No SM found.");
 
-	if (port_guid == (uint64_t) - 1) {
-		fprintf(stderr,
-			"Failed to find active port, check port status with \"ibstat\"\n");
-		exit(-1);
-	}
+	handle.dport.qp = 1;
+	if (!handle.dport.qkey)
+		handle.dport.qkey = IB_DEFAULT_QP1_QKEY;
 
-	h = osmv_bind_sa(vendor, &mad_pool, port_guid);
+	handle.fd = madrpc_portid();
+	handle.agent = umad_register(handle.fd, IB_SA_CLASS, 2, 1, NULL);
 
-	if (h == OSM_BIND_INVALID_HANDLE) {
-		fprintf(stderr, "Failed to bind to SA\n");
-		exit(-1);
-	}
-	return h;
+	return &handle;
 }
 
-static void clean_up(void)
+static void clean_up(struct sa_bind_handle *h)
 {
-	osm_mad_pool_destroy(&mad_pool);
-	osm_vendor_delete(&vendor);
+	umad_unregister(h->fd, h->agent);
+	umad_close_port(h->fd);
+	umad_done();
 }
 
 static const struct query_cmd query_cmds[] = {
@@ -1847,7 +1835,7 @@ int main(int argc, char **argv)
 
 	if (src_lid)
 		free(src_lid);
-	clean_up();
+	clean_up(h);
 	close_node_name_map(node_name_map);
 	return (status);
 }