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>
45 #include <infiniband/verbs.h>
46 #include <infiniband/driver.h>
47 #include <infiniband/arch.h>
51 static int null_gid(union ibv_gid *gid)
53 return !(gid->raw[8] | gid->raw[9] | gid->raw[10] | gid->raw[11] |
54 gid->raw[12] | gid->raw[13] | gid->raw[14] | gid->raw[15]);
57 static const char *guid_str(uint64_t node_guid, char *str)
59 node_guid = ntohll(node_guid);
60 sprintf(str, "%04x:%04x:%04x:%04x",
61 (unsigned) (node_guid >> 48) & 0xffff,
62 (unsigned) (node_guid >> 32) & 0xffff,
63 (unsigned) (node_guid >> 16) & 0xffff,
64 (unsigned) (node_guid >> 0) & 0xffff);
68 static const char *transport_str(enum ibv_transport_type transport)
71 case IBV_TRANSPORT_IB: return "InfiniBand";
72 case IBV_TRANSPORT_IWARP: return "iWARP";
73 default: return "invalid transport";
77 static const char *port_state_str(enum ibv_port_state pstate)
80 case IBV_PORT_DOWN: return "PORT_DOWN";
81 case IBV_PORT_INIT: return "PORT_INIT";
82 case IBV_PORT_ARMED: return "PORT_ARMED";
83 case IBV_PORT_ACTIVE: return "PORT_ACTIVE";
84 default: return "invalid state";
88 static const char *port_phy_state_str(uint8_t phys_state)
91 case 1: return "SLEEP";
92 case 2: return "POLLING";
93 case 3: return "DISABLED";
94 case 4: return "PORT_CONFIGURATION TRAINNING";
95 case 5: return "LINK_UP";
96 case 6: return "LINK_ERROR_RECOVERY";
97 case 7: return "PHY TEST";
98 default: return "invalid physical state";
102 static const char *atomic_cap_str(enum ibv_atomic_cap atom_cap)
105 case IBV_ATOMIC_NONE: return "ATOMIC_NONE";
106 case IBV_ATOMIC_HCA: return "ATOMIC_HCA";
107 case IBV_ATOMIC_GLOB: return "ATOMIC_GLOB";
108 default: return "invalid atomic capability";
112 static const char *mtu_str(enum ibv_mtu max_mtu)
115 case IBV_MTU_256: return "256";
116 case IBV_MTU_512: return "512";
117 case IBV_MTU_1024: return "1024";
118 case IBV_MTU_2048: return "2048";
119 case IBV_MTU_4096: return "4096";
120 default: return "invalid MTU";
124 static const char *width_str(uint8_t width)
131 default: return "invalid width";
135 static const char *speed_str(uint8_t speed)
138 case 1: return "2.5 Gbps";
139 case 2: return "5.0 Gbps";
140 case 4: return "10.0 Gbps";
141 default: return "invalid speed";
145 static const char *vl_str(uint8_t vl_num)
153 default: return "invalid value";
157 static int print_all_port_gids(struct ibv_context *ctx, uint8_t port_num, int tbl_len)
163 for (i = 0; i < tbl_len; i++) {
164 rc = ibv_query_gid(ctx, port_num, i, &gid);
166 fprintf(stderr, "Failed to query gid to port %d, index %d\n",
171 printf("\t\t\tGID[%3d]:\t\t%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x\n",
173 gid.raw[ 0], gid.raw[ 1],
174 gid.raw[ 2], gid.raw[ 3],
175 gid.raw[ 4], gid.raw[ 5],
176 gid.raw[ 6], gid.raw[ 7],
177 gid.raw[ 8], gid.raw[ 9],
178 gid.raw[10], gid.raw[11],
179 gid.raw[12], gid.raw[13],
180 gid.raw[14], gid.raw[15]);
185 static const char *link_layer_str(uint8_t link_layer)
187 switch (link_layer) {
188 case IBV_LINK_LAYER_UNSPECIFIED:
189 case IBV_LINK_LAYER_INFINIBAND:
191 case IBV_LINK_LAYER_ETHERNET:
198 static int print_hca_cap(struct ibv_device *ib_dev, uint8_t ib_port)
200 struct ibv_context *ctx;
201 struct ibv_device_attr device_attr;
202 struct ibv_port_attr port_attr;
207 ctx = ibv_open_device(ib_dev);
209 fprintf(stderr, "Failed to open device\n");
213 if (ibv_query_device(ctx, &device_attr)) {
214 fprintf(stderr, "Failed to query device props");
219 printf("hca_id:\t%s\n", ibv_get_device_name(ib_dev));
220 printf("\ttransport:\t\t\t%s (%d)\n",
221 transport_str(ib_dev->transport_type), ib_dev->transport_type);
222 if (strlen(device_attr.fw_ver))
223 printf("\tfw_ver:\t\t\t\t%s\n", device_attr.fw_ver);
224 printf("\tnode_guid:\t\t\t%s\n", guid_str(device_attr.node_guid, buf));
225 printf("\tsys_image_guid:\t\t\t%s\n", guid_str(device_attr.sys_image_guid, buf));
226 printf("\tvendor_id:\t\t\t0x%04x\n", device_attr.vendor_id);
227 printf("\tvendor_part_id:\t\t\t%d\n", device_attr.vendor_part_id);
228 printf("\thw_ver:\t\t\t\t0x%X\n", device_attr.hw_ver);
230 if (ibv_read_sysfs_file(ib_dev->ibdev_path, "board_id", buf, sizeof buf) > 0)
231 printf("\tboard_id:\t\t\t%s\n", buf);
233 printf("\tphys_port_cnt:\t\t\t%d\n", device_attr.phys_port_cnt);
236 printf("\tmax_mr_size:\t\t\t0x%llx\n",
237 (unsigned long long) device_attr.max_mr_size);
238 printf("\tpage_size_cap:\t\t\t0x%llx\n",
239 (unsigned long long) device_attr.page_size_cap);
240 printf("\tmax_qp:\t\t\t\t%d\n", device_attr.max_qp);
241 printf("\tmax_qp_wr:\t\t\t%d\n", device_attr.max_qp_wr);
242 printf("\tdevice_cap_flags:\t\t0x%08x\n", device_attr.device_cap_flags);
243 printf("\tmax_sge:\t\t\t%d\n", device_attr.max_sge);
244 printf("\tmax_sge_rd:\t\t\t%d\n", device_attr.max_sge_rd);
245 printf("\tmax_cq:\t\t\t\t%d\n", device_attr.max_cq);
246 printf("\tmax_cqe:\t\t\t%d\n", device_attr.max_cqe);
247 printf("\tmax_mr:\t\t\t\t%d\n", device_attr.max_mr);
248 printf("\tmax_pd:\t\t\t\t%d\n", device_attr.max_pd);
249 printf("\tmax_qp_rd_atom:\t\t\t%d\n", device_attr.max_qp_rd_atom);
250 printf("\tmax_ee_rd_atom:\t\t\t%d\n", device_attr.max_ee_rd_atom);
251 printf("\tmax_res_rd_atom:\t\t%d\n", device_attr.max_res_rd_atom);
252 printf("\tmax_qp_init_rd_atom:\t\t%d\n", device_attr.max_qp_init_rd_atom);
253 printf("\tmax_ee_init_rd_atom:\t\t%d\n", device_attr.max_ee_init_rd_atom);
254 printf("\tatomic_cap:\t\t\t%s (%d)\n",
255 atomic_cap_str(device_attr.atomic_cap), device_attr.atomic_cap);
256 printf("\tmax_ee:\t\t\t\t%d\n", device_attr.max_ee);
257 printf("\tmax_rdd:\t\t\t%d\n", device_attr.max_rdd);
258 printf("\tmax_mw:\t\t\t\t%d\n", device_attr.max_mw);
259 printf("\tmax_raw_ipv6_qp:\t\t%d\n", device_attr.max_raw_ipv6_qp);
260 printf("\tmax_raw_ethy_qp:\t\t%d\n", device_attr.max_raw_ethy_qp);
261 printf("\tmax_mcast_grp:\t\t\t%d\n", device_attr.max_mcast_grp);
262 printf("\tmax_mcast_qp_attach:\t\t%d\n", device_attr.max_mcast_qp_attach);
263 printf("\tmax_total_mcast_qp_attach:\t%d\n",
264 device_attr.max_total_mcast_qp_attach);
265 printf("\tmax_ah:\t\t\t\t%d\n", device_attr.max_ah);
266 printf("\tmax_fmr:\t\t\t%d\n", device_attr.max_fmr);
267 if (device_attr.max_fmr)
268 printf("\tmax_map_per_fmr:\t\t%d\n", device_attr.max_map_per_fmr);
269 printf("\tmax_srq:\t\t\t%d\n", device_attr.max_srq);
270 if (device_attr.max_srq) {
271 printf("\tmax_srq_wr:\t\t\t%d\n", device_attr.max_srq_wr);
272 printf("\tmax_srq_sge:\t\t\t%d\n", device_attr.max_srq_sge);
274 printf("\tmax_pkeys:\t\t\t%d\n", device_attr.max_pkeys);
275 printf("\tlocal_ca_ack_delay:\t\t%d\n", device_attr.local_ca_ack_delay);
278 for (port = 1; port <= device_attr.phys_port_cnt; ++port) {
279 /* if in the command line the user didn't ask for info about this port */
280 if ((ib_port) && (port != ib_port))
283 rc = ibv_query_port(ctx, port, &port_attr);
285 fprintf(stderr, "Failed to query port %u props\n", port);
288 printf("\t\tport:\t%d\n", port);
289 printf("\t\t\tstate:\t\t\t%s (%d)\n",
290 port_state_str(port_attr.state), port_attr.state);
291 printf("\t\t\tmax_mtu:\t\t%s (%d)\n",
292 mtu_str(port_attr.max_mtu), port_attr.max_mtu);
293 printf("\t\t\tactive_mtu:\t\t%s (%d)\n",
294 mtu_str(port_attr.active_mtu), port_attr.active_mtu);
295 printf("\t\t\tsm_lid:\t\t\t%d\n", port_attr.sm_lid);
296 printf("\t\t\tport_lid:\t\t%d\n", port_attr.lid);
297 printf("\t\t\tport_lmc:\t\t0x%02x\n", port_attr.lmc);
298 printf("\t\t\tlink_layer:\t\t%s\n", link_layer_str(port_attr.link_layer));
301 printf("\t\t\tmax_msg_sz:\t\t0x%x\n", port_attr.max_msg_sz);
302 printf("\t\t\tport_cap_flags:\t\t0x%08x\n", port_attr.port_cap_flags);
303 printf("\t\t\tmax_vl_num:\t\t%s (%d)\n",
304 vl_str(port_attr.max_vl_num), port_attr.max_vl_num);
305 printf("\t\t\tbad_pkey_cntr:\t\t0x%x\n", port_attr.bad_pkey_cntr);
306 printf("\t\t\tqkey_viol_cntr:\t\t0x%x\n", port_attr.qkey_viol_cntr);
307 printf("\t\t\tsm_sl:\t\t\t%d\n", port_attr.sm_sl);
308 printf("\t\t\tpkey_tbl_len:\t\t%d\n", port_attr.pkey_tbl_len);
309 printf("\t\t\tgid_tbl_len:\t\t%d\n", port_attr.gid_tbl_len);
310 printf("\t\t\tsubnet_timeout:\t\t%d\n", port_attr.subnet_timeout);
311 printf("\t\t\tinit_type_reply:\t%d\n", port_attr.init_type_reply);
312 printf("\t\t\tactive_width:\t\t%sX (%d)\n",
313 width_str(port_attr.active_width), port_attr.active_width);
314 printf("\t\t\tactive_speed:\t\t%s (%d)\n",
315 speed_str(port_attr.active_speed), port_attr.active_speed);
316 printf("\t\t\tphys_state:\t\t%s (%d)\n",
317 port_phy_state_str(port_attr.phys_state), port_attr.phys_state);
319 if (print_all_port_gids(ctx, port, port_attr.gid_tbl_len))
326 if (ibv_close_device(ctx)) {
327 fprintf(stderr, "Failed to close device");
333 static void usage(const char *argv0)
335 printf("Usage: %s print the ca attributes\n", argv0);
337 printf("Options:\n");
338 printf(" -d, --ib-dev=<dev> use IB device <dev> (default first device found)\n");
339 printf(" -i, --ib-port=<port> use port <port> of IB device (default all ports)\n");
340 printf(" -l, --list print only the IB devices names\n");
341 printf(" -v, --verbose print all the attributes of the IB device(s)\n");
344 int main(int argc, char *argv[])
346 char *ib_devname = NULL;
348 struct ibv_device **dev_list, **orig_dev_list;
352 /* parse command line options */
355 static struct option long_options[] = {
356 { .name = "ib-dev", .has_arg = 1, .val = 'd' },
357 { .name = "ib-port", .has_arg = 1, .val = 'i' },
358 { .name = "list", .has_arg = 0, .val = 'l' },
359 { .name = "verbose", .has_arg = 0, .val = 'v' },
363 c = getopt_long(argc, argv, "d:i:lv", long_options, NULL);
369 ib_devname = strdup(optarg);
373 ib_port = strtol(optarg, NULL, 0);
385 dev_list = orig_dev_list = ibv_get_device_list(&num_of_hcas);
387 perror("Failed to get IB devices list");
391 printf("%d HCA%s found:\n", num_of_hcas,
392 num_of_hcas != 1 ? "s" : "");
395 printf("\t%s\n", ibv_get_device_name(*dev_list));
401 ibv_free_device_list(orig_dev_list);
411 dev_list = orig_dev_list = ibv_get_device_list(NULL);
413 perror("Failed to get IB devices list");
419 if (!strcmp(ibv_get_device_name(*dev_list), ib_devname))
425 fprintf(stderr, "IB device '%s' wasn't found\n", ib_devname);
429 ret |= print_hca_cap(*dev_list, ib_port);
432 fprintf(stderr, "No IB devices found\n");
437 ret |= print_hca_cap(*dev_list, ib_port);
445 ibv_free_device_list(orig_dev_list);