2 * Copyright (c) 2004-2009 Voltaire Inc. All rights reserved.
3 * Copyright (c) 2011 Mellanox Technologies LTD. All rights reserved.
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:
11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following
15 * - Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
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.
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
37 #endif /* HAVE_CONFIG_H */
44 #include <netinet/in.h>
46 #define __STDC_FORMAT_MACROS
49 #include <infiniband/umad.h>
50 #include <infiniband/mad.h>
51 #include <complib/cl_nodenamemap.h>
53 #include "ibdiag_common.h"
55 struct ibmad_port *srcport;
57 static op_fn_t node_desc, node_info, port_info, switch_info, pkey_table,
58 sl2vl_table, vlarb_table, guid_info, mlnx_ext_port_info, port_info_extended;
60 static const match_rec_t match_tbl[] = {
61 {"NodeInfo", "NI", node_info, 0, ""},
62 {"NodeDesc", "ND", node_desc, 0, ""},
63 {"PortInfo", "PI", port_info, 1, ""},
64 {"PortInfoExtended", "PIE", port_info_extended, 1, ""},
65 {"SwitchInfo", "SI", switch_info, 0, ""},
66 {"PKeyTable", "PKeys", pkey_table, 1, ""},
67 {"SL2VLTable", "SL2VL", sl2vl_table, 1, ""},
68 {"VLArbitration", "VLArb", vlarb_table, 1, ""},
69 {"GUIDInfo", "GI", guid_info, 0, ""},
70 {"MlnxExtPortInfo", "MEPI", mlnx_ext_port_info, 1, ""},
74 static char *node_name_map_file = NULL;
75 static nn_map_t *node_name_map = NULL;
76 static int extended_speeds = 0;
78 /*******************************************/
79 static char *node_desc(ib_portid_t * dest, char **argv, int argc)
83 char nd[IB_SMP_DATA_SIZE] = { 0 };
84 uint8_t data[IB_SMP_DATA_SIZE] = { 0 };
86 char *nodename = NULL;
88 if (!smp_query_via(data, dest, IB_ATTR_NODE_INFO, 0, 0, srcport))
89 return "node info query failed";
91 mad_decode_field(data, IB_NODE_TYPE_F, &node_type);
92 mad_decode_field(data, IB_NODE_GUID_F, &node_guid);
94 if (!smp_query_via(nd, dest, IB_ATTR_NODE_DESC, 0, 0, srcport))
95 return "node desc query failed";
97 nodename = remap_node_name(node_name_map, node_guid, nd);
101 memset(dots, '.', 32 - l);
108 printf("Node Description:%s%s\n", dots, nodename);
113 static char *node_info(ib_portid_t * dest, char **argv, int argc)
116 char data[IB_SMP_DATA_SIZE] = { 0 };
118 if (!smp_query_via(data, dest, IB_ATTR_NODE_INFO, 0, 0, srcport))
119 return "node info query failed";
121 mad_dump_nodeinfo(buf, sizeof buf, data, sizeof data);
123 printf("# Node info: %s\n%s", portid2str(dest), buf);
127 static char *port_info_extended(ib_portid_t * dest, char **argv, int argc)
130 uint8_t data[IB_SMP_DATA_SIZE] = { 0 };
134 portnum = strtol(argv[0], 0, 0);
136 if (!is_port_info_extended_supported(dest, portnum, srcport))
137 return "port info extended not supported";
139 if (!smp_query_via(data, dest, IB_ATTR_PORT_INFO_EXT, portnum, 0,
141 return "port info extended query failed";
143 mad_dump_portinfo_ext(buf, sizeof buf, data, sizeof data);
144 printf("# Port info Extended: %s port %d\n%s", portid2str(dest),
149 static char *port_info(ib_portid_t * dest, char **argv, int argc)
151 char data[IB_SMP_DATA_SIZE] = { 0 };
152 int portnum = 0, orig_portnum;
155 portnum = strtol(argv[0], 0, 0);
156 orig_portnum = portnum;
160 if (!smp_query_via(data, dest, IB_ATTR_PORT_INFO, portnum, 0, srcport))
161 return "port info query failed";
163 printf("# Port info: %s port %d\n", portid2str(dest), orig_portnum);
164 dump_portinfo(data, 0);
168 static char *mlnx_ext_port_info(ib_portid_t * dest, char **argv, int argc)
171 char data[IB_SMP_DATA_SIZE];
175 portnum = strtol(argv[0], 0, 0);
177 if (!smp_query_via(data, dest, IB_ATTR_MLNX_EXT_PORT_INFO, portnum, 0, srcport))
178 return "Mellanox ext port info query failed";
180 mad_dump_mlnx_ext_port_info(buf, sizeof buf, data, sizeof data);
182 printf("# MLNX ext Port info: %s port %d\n%s", portid2str(dest), portnum, buf);
186 static char *switch_info(ib_portid_t * dest, char **argv, int argc)
189 char data[IB_SMP_DATA_SIZE] = { 0 };
191 if (!smp_query_via(data, dest, IB_ATTR_SWITCH_INFO, 0, 0, srcport))
192 return "switch info query failed";
194 mad_dump_switchinfo(buf, sizeof buf, data, sizeof data);
196 printf("# Switch info: %s\n%s", portid2str(dest), buf);
200 static char *pkey_table(ib_portid_t * dest, char **argv, int argc)
202 uint8_t data[IB_SMP_DATA_SIZE] = { 0 };
210 portnum = strtol(argv[0], 0, 0);
212 /* Get the partition capacity */
213 if (!smp_query_via(data, dest, IB_ATTR_NODE_INFO, 0, 0, srcport))
214 return "node info query failed";
216 mad_decode_field(data, IB_NODE_TYPE_F, &t);
217 mad_decode_field(data, IB_NODE_NPORTS_F, &phy_ports);
218 if (portnum > phy_ports)
219 return "invalid port number";
221 if ((t == IB_NODE_SWITCH) && (portnum != 0)) {
222 if (!smp_query_via(data, dest, IB_ATTR_SWITCH_INFO, 0, 0,
224 return "switch info failed";
225 mad_decode_field(data, IB_SW_PARTITION_ENFORCE_CAP_F, &n);
227 mad_decode_field(data, IB_NODE_PARTITION_CAP_F, &n);
229 for (i = 0; i < (n + 31) / 32; i++) {
230 mod = i | (portnum << 16);
231 if (!smp_query_via(data, dest, IB_ATTR_PKEY_TBL, mod, 0,
233 return "pkey table query failed";
234 if (i + 1 == (n + 31) / 32)
235 k = ((n + 7 - i * 32) / 8) * 8;
238 p = (uint16_t *) data;
239 for (j = 0; j < k; j += 8, p += 8) {
241 ("%4u: 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x\n",
242 (i * 32) + j, ntohs(p[0]), ntohs(p[1]),
243 ntohs(p[2]), ntohs(p[3]), ntohs(p[4]), ntohs(p[5]),
244 ntohs(p[6]), ntohs(p[7]));
247 printf("%d pkeys capacity for this port\n", n);
252 static char *sl2vl_dump_table_entry(ib_portid_t * dest, int in, int out)
255 char data[IB_SMP_DATA_SIZE] = { 0 };
256 int portnum = (in << 8) | out;
258 if (!smp_query_via(data, dest, IB_ATTR_SLVL_TABLE, portnum, 0, srcport))
259 return "slvl query failed";
261 mad_dump_sltovl(buf, sizeof buf, data, sizeof data);
262 printf("ports: in %2d, out %2d: ", in, out);
267 static char *sl2vl_table(ib_portid_t * dest, char **argv, int argc)
269 uint8_t data[IB_SMP_DATA_SIZE] = { 0 };
270 int type, num_ports, portnum = 0;
275 portnum = strtol(argv[0], 0, 0);
277 if (!smp_query_via(data, dest, IB_ATTR_NODE_INFO, 0, 0, srcport))
278 return "node info query failed";
280 mad_decode_field(data, IB_NODE_TYPE_F, &type);
281 mad_decode_field(data, IB_NODE_NPORTS_F, &num_ports);
282 if (portnum > num_ports)
283 return "invalid port number";
285 printf("# SL2VL table: %s\n", portid2str(dest));
287 for (i = 0; i < 16; i++)
291 if (type != IB_NODE_SWITCH)
292 return sl2vl_dump_table_entry(dest, 0, 0);
294 for (i = 0; i <= num_ports; i++) {
295 ret = sl2vl_dump_table_entry(dest, i, portnum);
302 static char *vlarb_dump_table_entry(ib_portid_t * dest, int portnum, int offset,
306 char data[IB_SMP_DATA_SIZE] = { 0 };
308 if (!smp_query_via(data, dest, IB_ATTR_VL_ARBITRATION,
309 (offset << 16) | portnum, 0, srcport))
310 return "vl arb query failed";
311 mad_dump_vlarbitration(buf, sizeof(buf), data, cap * 2);
316 static char *vlarb_dump_table(ib_portid_t * dest, int portnum,
317 char *name, int offset, int cap)
321 printf("# %s priority VL Arbitration Table:", name);
322 ret = vlarb_dump_table_entry(dest, portnum, offset,
323 cap < 32 ? cap : 32);
324 if (!ret && cap > 32)
325 ret = vlarb_dump_table_entry(dest, portnum, offset + 1,
330 static char *vlarb_table(ib_portid_t * dest, char **argv, int argc)
332 uint8_t data[IB_SMP_DATA_SIZE] = { 0 };
334 int type, enhsp0, lowcap, highcap;
338 portnum = strtol(argv[0], 0, 0);
340 /* port number of 0 could mean SP0 or port MAD arrives on */
342 if (!smp_query_via(data, dest, IB_ATTR_NODE_INFO, 0, 0,
344 return "node info query failed";
346 mad_decode_field(data, IB_NODE_TYPE_F, &type);
347 if (type == IB_NODE_SWITCH) {
348 memset(data, 0, sizeof(data));
349 if (!smp_query_via(data, dest, IB_ATTR_SWITCH_INFO, 0,
351 return "switch info query failed";
352 mad_decode_field(data, IB_SW_ENHANCED_PORT0_F, &enhsp0);
355 ("# No VLArbitration tables (BSP0): %s port %d\n",
356 portid2str(dest), 0);
359 memset(data, 0, sizeof(data));
363 if (!smp_query_via(data, dest, IB_ATTR_PORT_INFO, portnum, 0, srcport))
364 return "port info query failed";
366 mad_decode_field(data, IB_PORT_VL_ARBITRATION_LOW_CAP_F, &lowcap);
367 mad_decode_field(data, IB_PORT_VL_ARBITRATION_HIGH_CAP_F, &highcap);
369 printf("# VLArbitration tables: %s port %d LowCap %d HighCap %d\n",
370 portid2str(dest), portnum, lowcap, highcap);
373 ret = vlarb_dump_table(dest, portnum, "Low", 1, lowcap);
375 if (!ret && highcap > 0)
376 ret = vlarb_dump_table(dest, portnum, "High", 3, highcap);
381 static char *guid_info(ib_portid_t * dest, char **argv, int argc)
383 uint8_t data[IB_SMP_DATA_SIZE] = { 0 };
389 /* Get the guid capacity */
390 if (!smp_query_via(data, dest, IB_ATTR_PORT_INFO, 0, 0, srcport))
391 return "port info failed";
392 mad_decode_field(data, IB_PORT_GUID_CAP_F, &n);
394 for (i = 0; i < (n + 7) / 8; i++) {
396 if (!smp_query_via(data, dest, IB_ATTR_GUID_INFO, mod, 0,
398 return "guid info query failed";
399 if (i + 1 == (n + 7) / 8)
400 k = ((n + 1 - i * 8) / 2) * 2;
403 p = (uint64_t *) data;
404 for (j = 0; j < k; j += 2, p += 2) {
405 printf("%4u: 0x%016" PRIx64 " 0x%016" PRIx64 "\n",
406 (i * 8) + j, ntohll(p[0]), ntohll(p[1]));
409 printf("%d guids capacity for this port\n", n);
414 static int process_opt(void *context, int ch, char *optarg)
418 node_name_map_file = strdup(optarg);
421 ibd_dest_type = IB_DEST_DRSLID;
432 int main(int argc, char **argv)
434 char usage_args[1024];
435 int mgmt_classes[3] =
436 { IB_SMI_CLASS, IB_SMI_DIRECT_CLASS, IB_SA_CLASS };
437 ib_portid_t portid = { 0 };
440 const match_rec_t *r;
443 const struct ibdiag_opt opts[] = {
444 {"combined", 'c', 0, NULL,
445 "use Combined route address argument"},
446 {"node-name-map", 1, 1, "<file>", "node name map file"},
447 {"extended", 'x', 0, NULL, "use extended speeds"},
450 const char *usage_examples[] = {
451 "portinfo 3 1\t\t\t\t# portinfo by lid, with port modifier",
452 "-G switchinfo 0x2C9000100D051 1\t# switchinfo by guid",
453 "-D nodeinfo 0\t\t\t\t# nodeinfo by direct route",
454 "-c nodeinfo 6 0,12\t\t\t# nodeinfo by combined route",
458 n = sprintf(usage_args, "<op> <dest dr_path|lid|guid> [op params]\n"
459 "\nSupported ops (and aliases, case insensitive):\n");
460 for (r = match_tbl; r->name; r++) {
461 n += snprintf(usage_args + n, sizeof(usage_args) - n,
462 " %s (%s) <addr>%s\n", r->name,
463 r->alias ? r->alias : "",
464 r->opt_portnum ? " [<portnum>]" : "");
465 if (n >= sizeof(usage_args))
469 ibdiag_process_opts(argc, argv, NULL, NULL, opts, process_opt,
470 usage_args, usage_examples);
478 if (!(fn = match_op(match_tbl, argv[0])))
479 IBEXIT("operation '%s' not supported", argv[0]);
481 srcport = mad_rpc_open_port(ibd_ca, ibd_ca_port, mgmt_classes, 3);
483 IBEXIT("Failed to open '%s' port '%d'", ibd_ca, ibd_ca_port);
485 smp_mkey_set(srcport, ibd_mkey);
487 node_name_map = open_node_name_map(node_name_map_file);
489 if (ibd_dest_type != IB_DEST_DRSLID) {
490 if (resolve_portid_str(ibd_ca, ibd_ca_port, &portid, argv[1],
491 ibd_dest_type, ibd_sm_id, srcport) < 0)
492 IBEXIT("can't resolve destination port %s", argv[1]);
493 if ((err = fn(&portid, argv + 2, argc - 2)))
494 IBEXIT("operation %s: %s", argv[0], err);
498 memset(concat, 0, 64);
499 snprintf(concat, sizeof(concat), "%s %s", argv[1], argv[2]);
500 if (resolve_portid_str(ibd_ca, ibd_ca_port, &portid, concat,
501 ibd_dest_type, ibd_sm_id, srcport) < 0)
502 IBEXIT("can't resolve destination port %s", concat);
503 if ((err = fn(&portid, argv + 3, argc - 3)))
504 IBEXIT("operation %s: %s", argv[0], err);
506 close_node_name_map(node_name_map);
507 mad_rpc_close_port(srcport);