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 */
45 #include <infiniband/umad.h>
46 #include <infiniband/mad.h>
48 #include "ibdiag_common.h"
50 static uint8_t sminfo[1024] = { 0 };
52 struct ibmad_port *srcport;
54 int strdata, xdata = 1, bindata;
72 #define STATESTR(s) (((unsigned)(s)) < SMINFO_STATE_LAST ? statestr[s] : "???")
75 static int prio, state = SMINFO_STANDBY;
77 static int process_opt(void *context, int ch, char *optarg)
81 act = strtoul(optarg, 0, 0);
84 state = strtoul(optarg, 0, 0);
87 prio = strtoul(optarg, 0, 0);
95 int main(int argc, char **argv)
98 { IB_SMI_CLASS, IB_SMI_DIRECT_CLASS, IB_SA_CLASS };
100 ib_portid_t portid = { 0 };
102 uint64_t guid = 0, key = 0;
104 const struct ibdiag_opt opts[] = {
105 {"state", 's', 1, "<0-3>", "set SM state"},
106 {"priority", 'p', 1, "<0-15>", "set SM priority"},
107 {"activity", 'a', 1, NULL, "set activity count"},
110 char usage_args[] = "<sm_lid|sm_dr_path> [modifier]";
112 ibdiag_process_opts(argc, argv, NULL, "sK", opts, process_opt,
121 srcport = mad_rpc_open_port(ibd_ca, ibd_ca_port, mgmt_classes, 3);
123 IBEXIT("Failed to open '%s' port '%d'", ibd_ca, ibd_ca_port);
125 smp_mkey_set(srcport, ibd_mkey);
128 if (resolve_portid_str(ibd_ca, ibd_ca_port, &portid, argv[0],
129 ibd_dest_type, 0, srcport) < 0)
130 IBEXIT("can't resolve destination port %s", argv[0]);
132 if (resolve_sm_portid(ibd_ca, ibd_ca_port, &portid) < 0)
133 IBEXIT("can't resolve sm port %s", argv[0]);
136 mad_encode_field(sminfo, IB_SMINFO_GUID_F, &guid);
137 mad_encode_field(sminfo, IB_SMINFO_ACT_F, &act);
138 mad_encode_field(sminfo, IB_SMINFO_KEY_F, &key);
139 mad_encode_field(sminfo, IB_SMINFO_PRIO_F, &prio);
140 mad_encode_field(sminfo, IB_SMINFO_STATE_F, &state);
143 if (!(p = smp_set_via(sminfo, &portid, IB_ATTR_SMINFO, mod,
144 ibd_timeout, srcport)))
146 } else if (!(p = smp_query_via(sminfo, &portid, IB_ATTR_SMINFO, 0,
147 ibd_timeout, srcport)))
150 mad_decode_field(sminfo, IB_SMINFO_GUID_F, &guid);
151 mad_decode_field(sminfo, IB_SMINFO_ACT_F, &act);
152 mad_decode_field(sminfo, IB_SMINFO_KEY_F, &key);
153 mad_decode_field(sminfo, IB_SMINFO_PRIO_F, &prio);
154 mad_decode_field(sminfo, IB_SMINFO_STATE_F, &state);
156 printf("sminfo: sm lid %d sm guid 0x%" PRIx64
157 ", activity count %u priority %d state %d %s\n", portid.lid,
158 guid, act, prio, state, STATESTR(state));
160 mad_rpc_close_port(srcport);