2 * Copyright (c) 2004-2008 Voltaire Inc. All rights reserved.
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:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
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.
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
36 #endif /* HAVE_CONFIG_H */
45 #include <netinet/in.h>
47 #define __STDC_FORMAT_MACROS
50 #include <infiniband/common.h>
51 #include <infiniband/umad.h>
52 #include <infiniband/mad.h>
53 #include <infiniband/complib/cl_nodenamemap.h>
55 #include "ibdiag_common.h"
58 #define DEBUG if (verbose>1) IBWARN
60 static int dest_type = IB_DEST_LID;
63 typedef char *(op_fn_t)(ib_portid_t *dest, char **argv, int argc);
65 typedef struct match_rec {
71 static op_fn_t node_desc, node_info, port_info, switch_info, pkey_table,
72 sl2vl_table, vlarb_table, guid_info;
74 static const match_rec_t match_tbl[] = {
75 { "nodeinfo", node_info },
76 { "nodedesc", node_desc },
77 { "portinfo", port_info, 1 },
78 { "switchinfo", switch_info },
79 { "pkeys", pkey_table, 1 },
80 { "sl2vl", sl2vl_table, 1 },
81 { "vlarb", vlarb_table, 1 },
82 { "guids", guid_info },
86 char *argv0 = "smpquery";
87 static char *node_name_map_file = NULL;
88 static nn_map_t *node_name_map = NULL;
90 /*******************************************/
92 node_desc(ib_portid_t *dest, char **argv, int argc)
96 char nd[IB_SMP_DATA_SIZE];
97 uint8_t data[IB_SMP_DATA_SIZE];
99 char *nodename = NULL;
101 if (!smp_query(data, dest, IB_ATTR_NODE_INFO, 0, 0))
102 return "node info query failed";
104 mad_decode_field(data, IB_NODE_TYPE_F, &node_type);
105 mad_decode_field(data, IB_NODE_GUID_F, &node_guid);
107 if (!smp_query(nd, dest, IB_ATTR_NODE_DESC, 0, 0))
108 return "node desc query failed";
110 nodename = remap_node_name(node_name_map, node_guid, nd);
112 l = strlen(nodename);
114 memset(dots, '.', 32 - l);
121 printf("Node Description:%s%s\n", dots, nodename);
127 node_info(ib_portid_t *dest, char **argv, int argc)
130 char data[IB_SMP_DATA_SIZE];
132 if (!smp_query(data, dest, IB_ATTR_NODE_INFO, 0, 0))
133 return "node info query failed";
135 mad_dump_nodeinfo(buf, sizeof buf, data, sizeof data);
137 printf("# Node info: %s\n%s", portid2str(dest), buf);
142 port_info(ib_portid_t *dest, char **argv, int argc)
145 char data[IB_SMP_DATA_SIZE];
149 portnum = strtol(argv[0], 0, 0);
151 if (!smp_query(data, dest, IB_ATTR_PORT_INFO, portnum, 0))
152 return "port info query failed";
154 mad_dump_portinfo(buf, sizeof buf, data, sizeof data);
156 printf("# Port info: %s port %d\n%s", portid2str(dest), portnum, buf);
161 switch_info(ib_portid_t *dest, char **argv, int argc)
164 char data[IB_SMP_DATA_SIZE];
166 if (!smp_query(data, dest, IB_ATTR_SWITCH_INFO, 0, 0))
167 return "switch info query failed";
169 mad_dump_switchinfo(buf, sizeof buf, data, sizeof data);
171 printf("# Switch info: %s\n%s", portid2str(dest), buf);
176 pkey_table(ib_portid_t *dest, char **argv, int argc)
178 uint8_t data[IB_SMP_DATA_SIZE];
186 portnum = strtol(argv[0], 0, 0);
188 /* Get the partition capacity */
189 if (!smp_query(data, dest, IB_ATTR_NODE_INFO, 0, 0))
190 return "node info query failed";
192 mad_decode_field(data, IB_NODE_TYPE_F, &t);
193 mad_decode_field(data, IB_NODE_NPORTS_F, &phy_ports);
194 if (portnum > phy_ports)
195 return "invalid port number";
197 if ((t == IB_NODE_SWITCH) && (portnum != 0)) {
198 if (!smp_query(data, dest, IB_ATTR_SWITCH_INFO, 0, 0))
199 return "switch info failed";
200 mad_decode_field(data, IB_SW_PARTITION_ENFORCE_CAP_F, &n);
202 mad_decode_field(data, IB_NODE_PARTITION_CAP_F, &n);
204 for (i = 0; i < (n + 31) / 32; i++) {
205 mod = i | (portnum << 16);
206 if (!smp_query(data, dest, IB_ATTR_PKEY_TBL, mod, 0))
207 return "pkey table query failed";
208 if (i + 1 == (n + 31) / 32)
209 k = ((n + 7 - i * 32) / 8) * 8;
212 p = (uint16_t *) data;
213 for (j = 0; j < k; j += 8, p += 8) {
214 printf("%4u: 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x\n",
216 ntohs(p[0]), ntohs(p[1]),
217 ntohs(p[2]), ntohs(p[3]),
218 ntohs(p[4]), ntohs(p[5]),
219 ntohs(p[6]), ntohs(p[7]));
222 printf("%d pkeys capacity for this port\n", n);
227 static char *sl2vl_dump_table_entry(ib_portid_t *dest, int in, int out)
230 char data[IB_SMP_DATA_SIZE];
231 int portnum = (in << 8) | out;
233 if (!smp_query(data, dest, IB_ATTR_SLVL_TABLE, portnum, 0))
234 return "slvl query failed";
236 mad_dump_sltovl(buf, sizeof buf, data, sizeof data);
237 printf("ports: in %2d, out %2d: ", in, out);
243 sl2vl_table(ib_portid_t *dest, char **argv, int argc)
245 uint8_t data[IB_SMP_DATA_SIZE];
246 int type, num_ports, portnum = 0;
251 portnum = strtol(argv[0], 0, 0);
253 if (!smp_query(data, dest, IB_ATTR_NODE_INFO, 0, 0))
254 return "node info query failed";
256 mad_decode_field(data, IB_NODE_TYPE_F, &type);
257 mad_decode_field(data, IB_NODE_NPORTS_F, &num_ports);
258 if (portnum > num_ports)
259 return "invalid port number";
261 printf("# SL2VL table: %s\n", portid2str(dest));
263 for (i = 0 ; i < 16 ; i++)
267 if (type != IB_NODE_SWITCH)
268 return sl2vl_dump_table_entry(dest, 0, 0);
270 for (i = 0 ; i <= num_ports ; i++) {
271 ret = sl2vl_dump_table_entry(dest, i, portnum);
278 static char *vlarb_dump_table_entry(ib_portid_t *dest, int portnum, int offset, unsigned cap)
281 char data[IB_SMP_DATA_SIZE];
283 if (!smp_query(data, dest, IB_ATTR_VL_ARBITRATION,
284 (offset << 16) | portnum, 0))
285 return "vl arb query failed";
286 mad_dump_vlarbitration(buf, sizeof(buf), data, cap * 2);
291 static char *vlarb_dump_table(ib_portid_t *dest, int portnum,
292 char *name, int offset, int cap)
296 printf("# %s priority VL Arbitration Table:", name);
297 ret = vlarb_dump_table_entry(dest, portnum, offset,
298 cap < 32 ? cap : 32);
299 if (!ret && cap > 32)
300 ret = vlarb_dump_table_entry(dest, portnum, offset + 1,
306 vlarb_table(ib_portid_t *dest, char **argv, int argc)
308 uint8_t data[IB_SMP_DATA_SIZE];
310 int type, enhsp0, lowcap, highcap;
314 portnum = strtol(argv[0], 0, 0);
316 /* port number of 0 could mean SP0 or port MAD arrives on */
318 if (!smp_query(data, dest, IB_ATTR_NODE_INFO, 0, 0))
319 return "node info query failed";
321 mad_decode_field(data, IB_NODE_TYPE_F, &type);
322 if (type == IB_NODE_SWITCH) {
323 if (!smp_query(data, dest, IB_ATTR_SWITCH_INFO, 0, 0))
324 return "switch info query failed";
325 mad_decode_field(data, IB_SW_ENHANCED_PORT0_F, &enhsp0);
327 printf("# No VLArbitration tables (BSP0): %s port %d\n",
328 portid2str(dest), 0);
334 if (!smp_query(data, dest, IB_ATTR_PORT_INFO, portnum, 0))
335 return "port info query failed";
337 mad_decode_field(data, IB_PORT_VL_ARBITRATION_LOW_CAP_F, &lowcap);
338 mad_decode_field(data, IB_PORT_VL_ARBITRATION_HIGH_CAP_F,&highcap);
340 printf("# VLArbitration tables: %s port %d LowCap %d HighCap %d\n",
341 portid2str(dest), portnum, lowcap, highcap);
344 ret = vlarb_dump_table(dest, portnum, "Low", 1, lowcap);
346 if (!ret && highcap > 0)
347 ret = vlarb_dump_table(dest, portnum, "High", 3, highcap);
353 guid_info(ib_portid_t *dest, char **argv, int argc)
355 uint8_t data[IB_SMP_DATA_SIZE];
361 /* Get the guid capacity */
362 if (!smp_query(data, dest, IB_ATTR_PORT_INFO, 0, 0))
363 return "port info failed";
364 mad_decode_field(data, IB_PORT_GUID_CAP_F, &n);
366 for (i = 0; i < (n + 7) / 8; i++) {
368 if (!smp_query(data, dest, IB_ATTR_GUID_INFO, mod, 0))
369 return "guid info query failed";
370 if (i + 1 == (n + 7) / 8)
371 k = ((n + 1 - i * 8) / 2) * 2;
374 p = (uint64_t *) data;
375 for (j = 0; j < k; j += 2, p += 2) {
376 printf("%4u: 0x%016"PRIx64" 0x%016"PRIx64"\n",
378 ntohll(p[0]), ntohll(p[1]));
381 printf("%d guids capacity for this port\n", n);
389 const match_rec_t *r;
390 for (r = match_tbl; r->name; r++)
391 if (!strcmp(r->name, name))
400 const match_rec_t *r;
402 if (!(basename = strrchr(argv0, '/')))
407 fprintf(stderr, "Usage: %s [-d(ebug) -e(rr_show) -v(erbose) -D(irect) -G(uid) -s smlid -V(ersion) -C ca_name -P ca_port "
408 "-t(imeout) timeout_ms --node-name-map node-name-map] <op> <dest dr_path|lid|guid> [op params]\n",
410 fprintf(stderr, "\tsupported ops:\n");
411 for (r = match_tbl ; r->name ; r++) {
412 fprintf(stderr, "\t\t%s <addr>%s\n", r->name,
413 r->opt_portnum ? " [<portnum>]" : "");
415 fprintf(stderr, "\n\texamples:\n");
416 fprintf(stderr, "\t\t%s portinfo 3 1\t\t\t\t# portinfo by lid, with port modifier\n", basename);
417 fprintf(stderr, "\t\t%s -G switchinfo 0x2C9000100D051 1\t# switchinfo by guid\n", basename);
418 fprintf(stderr, "\t\t%s -D nodeinfo 0\t\t\t\t# nodeinfo by direct route\n", basename);
419 fprintf(stderr, "\t\t%s -c nodeinfo 6 0,12\t\t\t# nodeinfo by combined route\n", basename);
424 main(int argc, char **argv)
426 int mgmt_classes[3] = {IB_SMI_CLASS, IB_SMI_DIRECT_CLASS, IB_SA_CLASS};
427 ib_portid_t portid = {0};
428 ib_portid_t *sm_id = 0, sm_portid = {0};
430 int timeout = 0, udebug = 0;
436 static char const str_opts[] = "C:P:t:s:devDcGVhu";
437 static const struct option long_opts[] = {
440 { "debug", 0, 0, 'd'},
441 { "err_show", 0, 0, 'e'},
442 { "verbose", 0, 0, 'v'},
443 { "Direct", 0, 0, 'D'},
444 { "combined", 0, 0, 'c'},
445 { "Guid", 0, 0, 'G'},
446 { "smlid", 1, 0, 's'},
447 { "timeout", 1, 0, 't'},
448 { "node-name-map", 1, 0, 1},
449 { "Version", 0, 0, 'V'},
450 { "help", 0, 0, 'h'},
451 { "usage", 0, 0, 'u'},
458 int ch = getopt_long(argc, argv, str_opts, long_opts, NULL);
463 node_name_map_file = strdup(optarg);
467 madrpc_show_errors(1);
472 madrpc_show_errors(1);
475 dest_type = IB_DEST_DRPATH;
478 dest_type = IB_DEST_DRSLID;
481 dest_type = IB_DEST_GUID;
487 ca_port = strtoul(optarg, 0, 0);
490 if (ib_resolve_portid_str(&sm_portid, optarg, IB_DEST_LID, 0) < 0)
491 IBERROR("can't resolve SM destination port %s", optarg);
495 timeout = strtoul(optarg, 0, 0);
496 madrpc_set_timeout(timeout);
502 fprintf(stderr, "%s %s\n", argv0, get_build_version() );
515 if (!(fn = match_op(argv[0])))
516 IBERROR("operation '%s' not supported", argv[0]);
518 madrpc_init(ca, ca_port, mgmt_classes, 3);
519 node_name_map = open_node_name_map(node_name_map_file);
521 if (dest_type != IB_DEST_DRSLID) {
522 if (ib_resolve_portid_str(&portid, argv[1], dest_type, sm_id) < 0)
523 IBERROR("can't resolve destination port %s", argv[1]);
524 if ((err = fn(&portid, argv+2, argc-2)))
525 IBERROR("operation %s: %s", argv[0], err);
529 memset(concat, 0, 64);
530 snprintf(concat, sizeof(concat), "%s %s", argv[1], argv[2]);
531 if (ib_resolve_portid_str(&portid, concat, dest_type, sm_id) < 0)
532 IBERROR("can't resolve destination port %s", concat);
533 if ((err = fn(&portid, argv+3, argc-3)))
534 IBERROR("operation %s: %s", argv[0], err);
536 close_node_name_map(node_name_map);