2 * Copyright (c) 2005 Cisco Systems. All rights reserved.
3 * Copyright (c) 2005 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
36 #endif /* HAVE_CONFIG_H */
43 #include <netinet/in.h>
47 #include <infiniband/verbs.h>
48 #include <infiniband/driver.h>
49 #include <infiniband/arch.h>
53 static int null_gid(union ibv_gid *gid)
55 return !(gid->raw[8] | gid->raw[9] | gid->raw[10] | gid->raw[11] |
56 gid->raw[12] | gid->raw[13] | gid->raw[14] | gid->raw[15]);
59 static const char *guid_str(uint64_t node_guid, char *str)
61 node_guid = ntohll(node_guid);
62 sprintf(str, "%04x:%04x:%04x:%04x",
63 (unsigned) (node_guid >> 48) & 0xffff,
64 (unsigned) (node_guid >> 32) & 0xffff,
65 (unsigned) (node_guid >> 16) & 0xffff,
66 (unsigned) (node_guid >> 0) & 0xffff);
70 static const char *transport_str(enum ibv_transport_type transport)
73 case IBV_TRANSPORT_IB: return "InfiniBand";
74 case IBV_TRANSPORT_IWARP: return "iWARP";
75 default: return "invalid transport";
79 static const char *port_state_str(enum ibv_port_state pstate)
82 case IBV_PORT_DOWN: return "PORT_DOWN";
83 case IBV_PORT_INIT: return "PORT_INIT";
84 case IBV_PORT_ARMED: return "PORT_ARMED";
85 case IBV_PORT_ACTIVE: return "PORT_ACTIVE";
86 default: return "invalid state";
90 static const char *port_phy_state_str(uint8_t phys_state)
93 case 1: return "SLEEP";
94 case 2: return "POLLING";
95 case 3: return "DISABLED";
96 case 4: return "PORT_CONFIGURATION TRAINNING";
97 case 5: return "LINK_UP";
98 case 6: return "LINK_ERROR_RECOVERY";
99 case 7: return "PHY TEST";
100 default: return "invalid physical state";
104 static const char *atomic_cap_str(enum ibv_atomic_cap atom_cap)
107 case IBV_ATOMIC_NONE: return "ATOMIC_NONE";
108 case IBV_ATOMIC_HCA: return "ATOMIC_HCA";
109 case IBV_ATOMIC_GLOB: return "ATOMIC_GLOB";
110 default: return "invalid atomic capability";
114 static const char *mtu_str(enum ibv_mtu max_mtu)
117 case IBV_MTU_256: return "256";
118 case IBV_MTU_512: return "512";
119 case IBV_MTU_1024: return "1024";
120 case IBV_MTU_2048: return "2048";
121 case IBV_MTU_4096: return "4096";
122 default: return "invalid MTU";
126 static const char *width_str(uint8_t width)
133 default: return "invalid width";
137 static const char *speed_str(uint8_t speed)
140 case 1: return "2.5 Gbps";
141 case 2: return "5.0 Gbps";
142 case 4: return "10.0 Gbps";
143 default: return "invalid speed";
147 static const char *vl_str(uint8_t vl_num)
155 default: return "invalid value";
159 static int print_all_port_gids(struct ibv_context *ctx, uint8_t port_num, int tbl_len)
165 for (i = 0; i < tbl_len; i++) {
166 rc = ibv_query_gid(ctx, port_num, i, &gid);
168 fprintf(stderr, "Failed to query gid to port %d, index %d\n",
173 printf("\t\t\tGID[%3d]:\t\t%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x\n",
175 gid.raw[ 0], gid.raw[ 1],
176 gid.raw[ 2], gid.raw[ 3],
177 gid.raw[ 4], gid.raw[ 5],
178 gid.raw[ 6], gid.raw[ 7],
179 gid.raw[ 8], gid.raw[ 9],
180 gid.raw[10], gid.raw[11],
181 gid.raw[12], gid.raw[13],
182 gid.raw[14], gid.raw[15]);
187 static const char *link_layer_str(uint8_t link_layer)
189 switch (link_layer) {
190 case IBV_LINK_LAYER_UNSPECIFIED:
191 case IBV_LINK_LAYER_INFINIBAND:
193 case IBV_LINK_LAYER_ETHERNET:
200 static int print_hca_cap(struct ibv_device *ib_dev, uint8_t ib_port)
202 struct ibv_context *ctx;
203 struct ibv_device_attr device_attr;
204 struct ibv_port_attr port_attr;
209 ctx = ibv_open_device(ib_dev);
211 fprintf(stderr, "Failed to open device\n");
215 if (ibv_query_device(ctx, &device_attr)) {
216 fprintf(stderr, "Failed to query device props");
221 printf("hca_id:\t%s\n", ibv_get_device_name(ib_dev));
222 printf("\ttransport:\t\t\t%s (%d)\n",
223 transport_str(ib_dev->transport_type), ib_dev->transport_type);
224 if (strlen(device_attr.fw_ver))
225 printf("\tfw_ver:\t\t\t\t%s\n", device_attr.fw_ver);
226 printf("\tnode_guid:\t\t\t%s\n", guid_str(device_attr.node_guid, buf));
227 printf("\tsys_image_guid:\t\t\t%s\n", guid_str(device_attr.sys_image_guid, buf));
228 printf("\tvendor_id:\t\t\t0x%04x\n", device_attr.vendor_id);
229 printf("\tvendor_part_id:\t\t\t%d\n", device_attr.vendor_part_id);
230 printf("\thw_ver:\t\t\t\t0x%X\n", device_attr.hw_ver);
232 if (ibv_read_sysfs_file(ib_dev->ibdev_path, "board_id", buf, sizeof buf) > 0)
233 printf("\tboard_id:\t\t\t%s\n", buf);
235 printf("\tphys_port_cnt:\t\t\t%d\n", device_attr.phys_port_cnt);
238 printf("\tmax_mr_size:\t\t\t0x%llx\n",
239 (unsigned long long) device_attr.max_mr_size);
240 printf("\tpage_size_cap:\t\t\t0x%llx\n",
241 (unsigned long long) device_attr.page_size_cap);
242 printf("\tmax_qp:\t\t\t\t%d\n", device_attr.max_qp);
243 printf("\tmax_qp_wr:\t\t\t%d\n", device_attr.max_qp_wr);
244 printf("\tdevice_cap_flags:\t\t0x%08x\n", device_attr.device_cap_flags);
245 printf("\tmax_sge:\t\t\t%d\n", device_attr.max_sge);
246 printf("\tmax_sge_rd:\t\t\t%d\n", device_attr.max_sge_rd);
247 printf("\tmax_cq:\t\t\t\t%d\n", device_attr.max_cq);
248 printf("\tmax_cqe:\t\t\t%d\n", device_attr.max_cqe);
249 printf("\tmax_mr:\t\t\t\t%d\n", device_attr.max_mr);
250 printf("\tmax_pd:\t\t\t\t%d\n", device_attr.max_pd);
251 printf("\tmax_qp_rd_atom:\t\t\t%d\n", device_attr.max_qp_rd_atom);
252 printf("\tmax_ee_rd_atom:\t\t\t%d\n", device_attr.max_ee_rd_atom);
253 printf("\tmax_res_rd_atom:\t\t%d\n", device_attr.max_res_rd_atom);
254 printf("\tmax_qp_init_rd_atom:\t\t%d\n", device_attr.max_qp_init_rd_atom);
255 printf("\tmax_ee_init_rd_atom:\t\t%d\n", device_attr.max_ee_init_rd_atom);
256 printf("\tatomic_cap:\t\t\t%s (%d)\n",
257 atomic_cap_str(device_attr.atomic_cap), device_attr.atomic_cap);
258 printf("\tmax_ee:\t\t\t\t%d\n", device_attr.max_ee);
259 printf("\tmax_rdd:\t\t\t%d\n", device_attr.max_rdd);
260 printf("\tmax_mw:\t\t\t\t%d\n", device_attr.max_mw);
261 printf("\tmax_raw_ipv6_qp:\t\t%d\n", device_attr.max_raw_ipv6_qp);
262 printf("\tmax_raw_ethy_qp:\t\t%d\n", device_attr.max_raw_ethy_qp);
263 printf("\tmax_mcast_grp:\t\t\t%d\n", device_attr.max_mcast_grp);
264 printf("\tmax_mcast_qp_attach:\t\t%d\n", device_attr.max_mcast_qp_attach);
265 printf("\tmax_total_mcast_qp_attach:\t%d\n",
266 device_attr.max_total_mcast_qp_attach);
267 printf("\tmax_ah:\t\t\t\t%d\n", device_attr.max_ah);
268 printf("\tmax_fmr:\t\t\t%d\n", device_attr.max_fmr);
269 if (device_attr.max_fmr)
270 printf("\tmax_map_per_fmr:\t\t%d\n", device_attr.max_map_per_fmr);
271 printf("\tmax_srq:\t\t\t%d\n", device_attr.max_srq);
272 if (device_attr.max_srq) {
273 printf("\tmax_srq_wr:\t\t\t%d\n", device_attr.max_srq_wr);
274 printf("\tmax_srq_sge:\t\t\t%d\n", device_attr.max_srq_sge);
276 printf("\tmax_pkeys:\t\t\t%d\n", device_attr.max_pkeys);
277 printf("\tlocal_ca_ack_delay:\t\t%d\n", device_attr.local_ca_ack_delay);
280 for (port = 1; port <= device_attr.phys_port_cnt; ++port) {
281 /* if in the command line the user didn't ask for info about this port */
282 if ((ib_port) && (port != ib_port))
285 rc = ibv_query_port(ctx, port, &port_attr);
287 fprintf(stderr, "Failed to query port %u props\n", port);
290 printf("\t\tport:\t%d\n", port);
291 printf("\t\t\tstate:\t\t\t%s (%d)\n",
292 port_state_str(port_attr.state), port_attr.state);
293 printf("\t\t\tmax_mtu:\t\t%s (%d)\n",
294 mtu_str(port_attr.max_mtu), port_attr.max_mtu);
295 printf("\t\t\tactive_mtu:\t\t%s (%d)\n",
296 mtu_str(port_attr.active_mtu), port_attr.active_mtu);
297 printf("\t\t\tsm_lid:\t\t\t%d\n", port_attr.sm_lid);
298 printf("\t\t\tport_lid:\t\t%d\n", port_attr.lid);
299 printf("\t\t\tport_lmc:\t\t0x%02x\n", port_attr.lmc);
300 printf("\t\t\tlink_layer:\t\t%s\n", link_layer_str(port_attr.link_layer));
303 printf("\t\t\tmax_msg_sz:\t\t0x%x\n", port_attr.max_msg_sz);
304 printf("\t\t\tport_cap_flags:\t\t0x%08x\n", port_attr.port_cap_flags);
305 printf("\t\t\tmax_vl_num:\t\t%s (%d)\n",
306 vl_str(port_attr.max_vl_num), port_attr.max_vl_num);
307 printf("\t\t\tbad_pkey_cntr:\t\t0x%x\n", port_attr.bad_pkey_cntr);
308 printf("\t\t\tqkey_viol_cntr:\t\t0x%x\n", port_attr.qkey_viol_cntr);
309 printf("\t\t\tsm_sl:\t\t\t%d\n", port_attr.sm_sl);
310 printf("\t\t\tpkey_tbl_len:\t\t%d\n", port_attr.pkey_tbl_len);
311 printf("\t\t\tgid_tbl_len:\t\t%d\n", port_attr.gid_tbl_len);
312 printf("\t\t\tsubnet_timeout:\t\t%d\n", port_attr.subnet_timeout);
313 printf("\t\t\tinit_type_reply:\t%d\n", port_attr.init_type_reply);
314 printf("\t\t\tactive_width:\t\t%sX (%d)\n",
315 width_str(port_attr.active_width), port_attr.active_width);
316 printf("\t\t\tactive_speed:\t\t%s (%d)\n",
317 speed_str(port_attr.active_speed), port_attr.active_speed);
318 printf("\t\t\tphys_state:\t\t%s (%d)\n",
319 port_phy_state_str(port_attr.phys_state), port_attr.phys_state);
321 if (print_all_port_gids(ctx, port, port_attr.gid_tbl_len))
328 if (ibv_close_device(ctx)) {
329 fprintf(stderr, "Failed to close device");
335 static void usage(const char *argv0)
337 printf("Usage: %s print the ca attributes\n", argv0);
339 printf("Options:\n");
340 printf(" -d, --ib-dev=<dev> use IB device <dev> (default first device found)\n");
341 printf(" -i, --ib-port=<port> use port <port> of IB device (default all ports)\n");
342 printf(" -l, --list print only the IB devices names\n");
343 printf(" -v, --verbose print all the attributes of the IB device(s)\n");
346 int main(int argc, char *argv[])
348 char *ib_devname = NULL;
350 struct ibv_device **dev_list, **orig_dev_list;
354 /* parse command line options */
357 static struct option long_options[] = {
358 { .name = "ib-dev", .has_arg = 1, .val = 'd' },
359 { .name = "ib-port", .has_arg = 1, .val = 'i' },
360 { .name = "list", .has_arg = 0, .val = 'l' },
361 { .name = "verbose", .has_arg = 0, .val = 'v' },
365 c = getopt_long(argc, argv, "d:i:lv", long_options, NULL);
371 ib_devname = strdup(optarg);
375 ib_port = strtol(optarg, NULL, 0);
387 dev_list = orig_dev_list = ibv_get_device_list(&num_of_hcas);
389 perror("Failed to get IB devices list");
393 printf("%d HCA%s found:\n", num_of_hcas,
394 num_of_hcas != 1 ? "s" : "");
397 printf("\t%s\n", ibv_get_device_name(*dev_list));
403 ibv_free_device_list(orig_dev_list);
413 dev_list = orig_dev_list = ibv_get_device_list(NULL);
415 perror("Failed to get IB devices list");
421 if (!strcmp(ibv_get_device_name(*dev_list), ib_devname))
427 fprintf(stderr, "IB device '%s' wasn't found\n", ib_devname);
431 ret |= print_hca_cap(*dev_list, ib_port);
434 fprintf(stderr, "No IB devices found\n");
439 ret |= print_hca_cap(*dev_list, ib_port);
447 ibv_free_device_list(orig_dev_list);