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
38 #endif /* HAVE_CONFIG_H */
47 #include <sys/types.h>
50 #include <sys/ioctl.h>
58 #include <netinet/in.h>
60 #include <infiniband/common.h>
61 #include <infiniband/umad.h>
62 #include <infiniband/mad.h>
64 #include <ibdiag_common.h>
68 char *argv0 = "ibstat";
70 static char *node_type_str[] = {
79 ca_dump(umad_ca_t *ca)
83 printf("%s '%s'\n", ((uint)ca->node_type <= IB_NODE_MAX ? node_type_str[ca->node_type] : "???"), ca->ca_name);
84 printf("\t%s type: %s\n", ((uint)ca->node_type <= IB_NODE_MAX ? node_type_str[ca->node_type] : "???"),ca->ca_type);
85 printf("\tNumber of ports: %d\n", ca->numports);
86 printf("\tFirmware version: %s\n", ca->fw_ver);
87 printf("\tHardware version: %s\n", ca->hw_ver);
88 printf("\tNode GUID: 0x%016llx\n", (long long unsigned)ntohll(ca->node_guid));
89 printf("\tSystem image GUID: 0x%016llx\n", (long long unsigned)ntohll(ca->system_guid));
92 static char *port_state_str[] = {
100 static char *port_phy_state_str[] = {
105 "PortConfigurationTraining",
112 port_dump(umad_port_t *port, int alone)
125 printf("%sPort %d:\n", hdrpre, port->portnum);
126 printf("%sState: %s\n", pre, (uint)port->state <= 4 ? port_state_str[port->state] : "???");
127 printf("%sPhysical state: %s\n", pre, (uint)port->state <= 7 ? port_phy_state_str[port->phys_state] : "???");
128 printf("%sRate: %d\n", pre, port->rate);
129 printf("%sBase lid: %d\n", pre, port->base_lid);
130 printf("%sLMC: %d\n", pre, port->lmc);
131 printf("%sSM lid: %d\n", pre, port->sm_lid);
132 printf("%sCapability mask: 0x%08x\n", pre, (unsigned)ntohl(port->capmask));
133 printf("%sPort GUID: 0x%016llx\n", pre, (long long unsigned)ntohll(port->port_guid));
138 ca_stat(char *ca_name, int portnum, int no_ports)
143 if ((r = umad_get_ca(ca_name, &ca)) < 0)
149 if (!no_ports && portnum >= 0) {
150 if (portnum > ca.numports || !ca.ports[portnum]) {
151 IBWARN("%s: '%s' has no port number %d - max (%d)",
152 ((uint)ca.node_type <= IB_NODE_MAX ? node_type_str[ca.node_type] : "???"),
153 ca_name, portnum, ca.numports);
156 printf("%s: '%s'\n", ((uint)ca.node_type <= IB_NODE_MAX ? node_type_str[ca.node_type] : "???"), ca.ca_name);
157 port_dump(ca.ports[portnum], 1);
161 /* print ca header */
167 for (portnum = 0; portnum <= ca.numports; portnum++)
168 port_dump(ca.ports[portnum], 0);
174 ports_list(char names[][UMAD_CA_NAME_LEN], int n)
179 for (i = 0, found = 0; i < n && found < 64; i++) {
180 if ((ports = umad_get_ca_portguids(names[i], guids + found, 64 - found)) < 0)
185 for (i = 0; i < found; i++)
187 printf("0x%016llx\n", (long long unsigned)ntohll(guids[i]));
194 fprintf(stderr, "Usage: %s [-d(ebug) -l(ist_of_cas) -s(hort) -p(ort_list) -V(ersion)] <ca_name> [portnum]\n", argv0);
195 fprintf(stderr, "\tExamples:\n");
196 fprintf(stderr, "\t\t%s -l # list all IB devices\n", argv0);
197 fprintf(stderr, "\t\t%s mthca0 2 # stat port 2 of 'mthca0'\n", argv0);
202 main(int argc, char *argv[])
204 char names[UMAD_MAX_DEVICES][UMAD_CA_NAME_LEN];
206 int list_only = 0, short_format = 0, list_ports = 0;
209 static char const str_opts[] = "dlspVhu";
210 static const struct option long_opts[] = {
211 { "debug", 0, 0, 'd'},
212 { "list_of_cas", 0, 0, 'l'},
213 { "short", 0, 0, 's'},
214 { "port_list", 0, 0, 'p'},
215 { "Version", 0, 0, 'V'},
216 { "help", 0, 0, 'h'},
217 { "usage", 0, 0, 'u'},
224 int ch = getopt_long(argc, argv, str_opts, long_opts, NULL);
241 fprintf(stderr, "%s %s\n", argv0, get_build_version() );
252 dev_port = strtol(argv[1], 0, 0);
255 IBPANIC("can't init UMAD library");
257 if ((n = umad_get_cas_names(names, UMAD_MAX_DEVICES)) < 0)
258 IBPANIC("can't list IB device names");
261 for (i = 0; i < n; i++)
262 if (!strncmp(names[i], argv[0], sizeof names[i]))
265 IBPANIC("'%s' IB device can't be found", argv[0]);
267 strncpy(names[i], argv[0], sizeof names[i]);
272 if (ports_list(names, n) < 0)
273 IBPANIC("can't list ports");
277 if (!list_only && argc) {
278 if (ca_stat(argv[0], dev_port, short_format) < 0)
279 IBPANIC("stat of IB device '%s' failed", argv[0]);
283 for (i = 0; i < n; i++) {
285 printf("%s\n", names[i]);
287 if (ca_stat(names[i], -1, short_format) < 0)
288 IBPANIC("stat of IB device '%s' failed", names[i]);