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 <infiniband/common.h>
46 #include <infiniband/umad.h>
47 #include <infiniband/mad.h>
49 #include "ibdiag_common.h"
51 static uint8_t sminfo[1024];
53 char *argv0 = "sminfo";
58 fprintf(stderr, "Usage: %s [-d(ebug) -e(rr_show) -s state -p prio -a activity -D(irect) -G(uid) -V(ersion) -C ca_name -P ca_port "
59 "-t(imeout) timeout_ms] <sm_lid|sm_dr_path> [modifier]\n",
64 int strdata, xdata=1, bindata;
75 [SMINFO_NOTACT] "SMINFO_NOTACT",
76 [SMINFO_DISCOVER] "SMINFO_DISCOVER",
77 [SMINFO_STANDBY] "SMINFO_STANDBY",
78 [SMINFO_MASTER] "SMINFO_MASTER",
81 #define STATESTR(s) (((unsigned)(s)) < SMINFO_STATE_LAST ? statestr[s] : "???")
84 main(int argc, char **argv)
86 int mgmt_classes[3] = {IB_SMI_CLASS, IB_SMI_DIRECT_CLASS, IB_SA_CLASS};
88 ib_portid_t portid = {0};
89 int timeout = 0; /* use default */
92 int prio = 0, state = SMINFO_STANDBY;
93 uint64_t guid = 0, key = 0;
95 int dest_type = IB_DEST_LID;
100 static char const str_opts[] = "C:P:t:s:p:a:deDGVhu";
101 static const struct option long_opts[] = {
104 { "debug", 0, 0, 'd'},
105 { "err_show", 0, 0, 'e'},
109 { "Direct", 0, 0, 'D'},
110 { "Guid", 0, 0, 'G'},
111 { "Version", 0, 0, 'V'},
112 { "timeout", 1, 0, 't'},
113 { "help", 0, 0, 'h'},
114 { "usage", 0, 0, 'u'},
121 int ch = getopt_long(argc, argv, str_opts, long_opts, NULL);
129 ca_port = strtoul(optarg, 0, 0);
133 madrpc_show_errors(1);
138 madrpc_show_errors(1);
141 dest_type = IB_DEST_DRPATH;
144 dest_type = IB_DEST_GUID;
147 timeout = strtoul(optarg, 0, 0);
148 madrpc_set_timeout(timeout);
151 act = strtoul(optarg, 0, 0);
154 state = strtoul(optarg, 0, 0);
157 prio = strtoul(optarg, 0, 0);
160 fprintf(stderr, "%s %s\n", argv0, get_build_version() );
173 madrpc_init(ca, ca_port, mgmt_classes, 3);
176 if (ib_resolve_portid_str(&portid, argv[0], dest_type, 0) < 0)
177 IBERROR("can't resolve destination port %s", argv[0]);
179 if (ib_resolve_smlid(&portid, timeout) < 0)
180 IBERROR("can't resolve sm port %s", argv[0]);
183 mad_encode_field(sminfo, IB_SMINFO_GUID_F, &guid);
184 mad_encode_field(sminfo, IB_SMINFO_ACT_F, &act);
185 mad_encode_field(sminfo, IB_SMINFO_KEY_F, &key);
186 mad_encode_field(sminfo, IB_SMINFO_PRIO_F, &prio);
187 mad_encode_field(sminfo, IB_SMINFO_STATE_F, &state);
190 if (!(p = smp_set(sminfo, &portid, IB_ATTR_SMINFO, mod, timeout)))
193 if (!(p = smp_query(sminfo, &portid, IB_ATTR_SMINFO, 0, timeout)))
196 mad_decode_field(sminfo, IB_SMINFO_GUID_F, &guid);
197 mad_decode_field(sminfo, IB_SMINFO_ACT_F, &act);
198 mad_decode_field(sminfo, IB_SMINFO_KEY_F, &key);
199 mad_decode_field(sminfo, IB_SMINFO_PRIO_F, &prio);
200 mad_decode_field(sminfo, IB_SMINFO_STATE_F, &state);
202 printf("sminfo: sm lid %d sm guid 0x%" PRIx64 ", activity count %u priority %d state %d %s\n",
203 portid.lid, guid, act, prio, state, STATESTR(state));