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 */
43 #include <netinet/in.h>
45 #include <infiniband/common.h>
46 #include <infiniband/umad.h>
47 #include <infiniband/mad.h>
49 #include "ibdiag_common.h"
51 #define IS3_DEVICE_ID 47396
53 #define IB_MLX_VENDOR_CLASS 10
54 /* Vendor specific Attribute IDs */
55 #define IB_MLX_IS3_GENERAL_INFO 0x17
56 #define IB_MLX_IS3_CONFIG_SPACE_ACCESS 0x50
57 /* Config space addresses */
58 #define IB_MLX_IS3_PORT_XMIT_WAIT 0x10013C
60 char *argv0 = "vendstat";
81 uint32_t ini_file_version;
94 is3_hw_info_t hw_info;
95 is3_fw_info_t fw_info;
96 is3_sw_info_t sw_info;
107 is3_record_t record[18];
108 } is3_config_space_t;
115 if (!(basename = strrchr(argv0, '/')))
120 fprintf(stderr, "Usage: %s [-d(ebug) -N -w -G(uid) -C ca_name -P ca_port "
121 "-t(imeout) timeout_ms -V(ersion) -h(elp)] <lid|guid>\n",
123 fprintf(stderr, "\tExamples:\n");
124 fprintf(stderr, "\t\t%s -N 6\t\t# read IS3 general information\n", basename);
125 fprintf(stderr, "\t\t%s -w 6\t\t# read IS3 port xmit wait counters\n", basename);
130 main(int argc, char **argv)
132 int mgmt_classes[4] = {IB_SMI_CLASS, IB_SMI_DIRECT_CLASS, IB_SA_CLASS, IB_MLX_VENDOR_CLASS};
133 ib_portid_t *sm_id = 0, sm_portid = {0};
134 ib_portid_t portid = {0};
136 int dest_type = IB_DEST_LID;
137 int timeout = 0; /* use default */
143 ib_vendor_call_t call;
144 is3_general_info_t *gi;
145 is3_config_space_t *cs;
146 int general_info = 0;
150 static char const str_opts[] = "C:P:s:t:dNwGVhu";
151 static const struct option long_opts[] = {
156 { "debug", 0, 0, 'd'},
157 { "Guid", 0, 0, 'G'},
158 { "sm_portid", 1, 0, 's'},
159 { "timeout", 1, 0, 't'},
160 { "Version", 0, 0, 'V'},
161 { "help", 0, 0, 'h'},
162 { "usage", 0, 0, 'u'},
169 int ch = getopt_long(argc, argv, str_opts, long_opts, NULL);
177 ca_port = strtoul(optarg, 0, 0);
187 madrpc_show_errors(1);
192 dest_type = IB_DEST_GUID;
195 if (ib_resolve_portid_str(&sm_portid, optarg, IB_DEST_LID, 0) < 0)
196 IBERROR("can't resolve SM destination port %s", optarg);
200 timeout = strtoul(optarg, 0, 0);
201 madrpc_set_timeout(timeout);
204 fprintf(stderr, "%s %s\n", argv0, get_build_version() );
215 port = strtoul(argv[1], 0, 0);
217 madrpc_init(ca, ca_port, mgmt_classes, 4);
220 if (ib_resolve_portid_str(&portid, argv[0], dest_type, sm_id) < 0)
221 IBERROR("can't resolve destination port %s", argv[0]);
223 if (ib_resolve_self(&portid, &port, 0) < 0)
224 IBERROR("can't resolve self port %s", argv[0]);
227 /* Only General Info and Port Xmit Wait Counters */
228 /* queries are currently supported */
229 if (!general_info && !xmit_wait)
230 IBERROR("at least one of -N and -w must be specified");
232 /* These are Mellanox specific vendor MADs */
233 /* but vendors change the VendorId so how know for sure ? */
234 /* Would need a list of these and it might not be complete */
235 /* so for right now, punt on this */
237 memset(&call, 0, sizeof(call));
238 call.mgmt_class = IB_MLX_VENDOR_CLASS;
239 call.method = IB_MAD_METHOD_GET;
240 call.timeout = timeout;
242 memset(&buf, 0, sizeof(buf));
243 /* vendor ClassPortInfo is required attribute if class supported */
244 call.attrid = CLASS_PORT_INFO;
245 if (!ib_vendor_call(&buf, &portid, &call))
246 IBERROR("classportinfo query");
248 memset(&buf, 0, sizeof(buf));
249 call.attrid = IB_MLX_IS3_GENERAL_INFO;
250 if (!ib_vendor_call(&buf, &portid, &call))
252 gi = (is3_general_info_t *)&buf;
255 /* dump IS3 general info here */
256 printf("hw_dev_rev: 0x%04x\n", ntohs(gi->hw_info.hw_revision));
257 printf("hw_dev_id: 0x%04x\n", ntohs(gi->hw_info.device_id));
258 printf("hw_uptime: 0x%08x\n", ntohl(gi->hw_info.uptime));
259 printf("fw_version: %02d.%02d.%02d\n",
260 gi->fw_info.major, gi->fw_info.minor, gi->fw_info.sub_minor);
261 printf("fw_build_id: 0x%04x\n", ntohl(gi->fw_info.build_id));
262 printf("fw_date: %02d/%02d/%04x\n",
263 gi->fw_info.month, gi->fw_info.day, ntohs(gi->fw_info.year));
264 printf("fw_psid: '%s'\n", gi->fw_info.psid);
265 printf("fw_ini_ver: %d\n", ntohl(gi->fw_info.ini_file_version));
266 printf("sw_version: %02d.%02d.%02d\n",
267 gi->sw_info.major, gi->sw_info.minor, gi->sw_info.sub_minor);
271 if (ntohs(gi->hw_info.device_id) != IS3_DEVICE_ID)
272 IBERROR("Unsupported device ID 0x%x", ntohs(gi->hw_info.device_id));
274 memset(&buf, 0, sizeof(buf));
275 call.attrid = IB_MLX_IS3_CONFIG_SPACE_ACCESS;
276 /* Limit of 18 accesses per MAD ? */
277 call.mod = 2 << 22 | 16 << 16; /* 16 records */
278 /* Set record addresses for each port */
279 cs = (is3_config_space_t *)&buf;
280 for (i = 0; i < 16; i++)
281 cs->record[i].address = htonl(IB_MLX_IS3_PORT_XMIT_WAIT + ((i + 1) << 12));
282 if (!ib_vendor_call(&buf, &portid, &call))
285 for (i = 0; i < 16; i++)
286 if (cs->record[i].data) /* PortXmitWait is 32 bit counter */
287 printf("Port %d: PortXmitWait 0x%x\n", i + 4, ntohl(cs->record[i].data)); /* port 4 is first port */
289 /* Last 8 ports is another query */
290 memset(&buf, 0, sizeof(buf));
291 call.attrid = IB_MLX_IS3_CONFIG_SPACE_ACCESS;
292 call.mod = 2 << 22 | 8 << 16; /* 8 records */
293 /* Set record addresses for each port */
294 cs = (is3_config_space_t *)&buf;
295 for (i = 0; i < 8; i++)
296 cs->record[i].address = htonl(IB_MLX_IS3_PORT_XMIT_WAIT + ((i + 17) << 12));
297 if (!ib_vendor_call(&buf, &portid, &call))
300 for (i = 0; i < 8; i++)
301 if (cs->record[i].data) /* PortXmitWait is 32 bit counter */
302 printf("Port %d: PortXmitWait 0x%x\n",
303 i < 4 ? i + 21 : i - 3,
304 ntohl(cs->record[i].data));