1219820Sjeff/* 2219820Sjeff * Copyright (c) 2005 Cisco Systems. All rights reserved. 3219820Sjeff * Copyright (c) 2005 Mellanox Technologies Ltd. All rights reserved. 4219820Sjeff * 5219820Sjeff * This software is available to you under a choice of one of two 6219820Sjeff * licenses. You may choose to be licensed under the terms of the GNU 7219820Sjeff * General Public License (GPL) Version 2, available from the file 8219820Sjeff * COPYING in the main directory of this source tree, or the 9219820Sjeff * OpenIB.org BSD license below: 10219820Sjeff * 11219820Sjeff * Redistribution and use in source and binary forms, with or 12219820Sjeff * without modification, are permitted provided that the following 13219820Sjeff * conditions are met: 14219820Sjeff * 15219820Sjeff * - Redistributions of source code must retain the above 16219820Sjeff * copyright notice, this list of conditions and the following 17219820Sjeff * disclaimer. 18219820Sjeff * 19219820Sjeff * - Redistributions in binary form must reproduce the above 20219820Sjeff * copyright notice, this list of conditions and the following 21219820Sjeff * disclaimer in the documentation and/or other materials 22219820Sjeff * provided with the distribution. 23219820Sjeff * 24219820Sjeff * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 25219820Sjeff * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 26219820Sjeff * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 27219820Sjeff * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 28219820Sjeff * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 29219820Sjeff * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 30219820Sjeff * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 31219820Sjeff * SOFTWARE. 32219820Sjeff */ 33219820Sjeff 34219820Sjeff#if HAVE_CONFIG_H 35219820Sjeff# include <config.h> 36219820Sjeff#endif /* HAVE_CONFIG_H */ 37219820Sjeff 38219820Sjeff#include <stdio.h> 39219820Sjeff#include <stdlib.h> 40219820Sjeff#include <unistd.h> 41219820Sjeff#include <string.h> 42219820Sjeff#include <getopt.h> 43219820Sjeff#include <netinet/in.h> 44219820Sjeff#include <endian.h> 45219820Sjeff#include <byteswap.h> 46219820Sjeff 47219820Sjeff#include <infiniband/verbs.h> 48219820Sjeff#include <infiniband/driver.h> 49219820Sjeff#include <infiniband/arch.h> 50219820Sjeff 51219820Sjeffstatic int verbose; 52219820Sjeff 53219820Sjeffstatic int null_gid(union ibv_gid *gid) 54219820Sjeff{ 55219820Sjeff return !(gid->raw[8] | gid->raw[9] | gid->raw[10] | gid->raw[11] | 56219820Sjeff gid->raw[12] | gid->raw[13] | gid->raw[14] | gid->raw[15]); 57219820Sjeff} 58219820Sjeff 59219820Sjeffstatic const char *guid_str(uint64_t node_guid, char *str) 60219820Sjeff{ 61219820Sjeff node_guid = ntohll(node_guid); 62219820Sjeff sprintf(str, "%04x:%04x:%04x:%04x", 63219820Sjeff (unsigned) (node_guid >> 48) & 0xffff, 64219820Sjeff (unsigned) (node_guid >> 32) & 0xffff, 65219820Sjeff (unsigned) (node_guid >> 16) & 0xffff, 66219820Sjeff (unsigned) (node_guid >> 0) & 0xffff); 67219820Sjeff return str; 68219820Sjeff} 69219820Sjeff 70219820Sjeffstatic const char *transport_str(enum ibv_transport_type transport) 71219820Sjeff{ 72219820Sjeff switch (transport) { 73219820Sjeff case IBV_TRANSPORT_IB: return "InfiniBand"; 74219820Sjeff case IBV_TRANSPORT_IWARP: return "iWARP"; 75219820Sjeff default: return "invalid transport"; 76219820Sjeff } 77219820Sjeff} 78219820Sjeff 79219820Sjeffstatic const char *port_state_str(enum ibv_port_state pstate) 80219820Sjeff{ 81219820Sjeff switch (pstate) { 82219820Sjeff case IBV_PORT_DOWN: return "PORT_DOWN"; 83219820Sjeff case IBV_PORT_INIT: return "PORT_INIT"; 84219820Sjeff case IBV_PORT_ARMED: return "PORT_ARMED"; 85219820Sjeff case IBV_PORT_ACTIVE: return "PORT_ACTIVE"; 86219820Sjeff default: return "invalid state"; 87219820Sjeff } 88219820Sjeff} 89219820Sjeff 90219820Sjeffstatic const char *port_phy_state_str(uint8_t phys_state) 91219820Sjeff{ 92219820Sjeff switch (phys_state) { 93219820Sjeff case 1: return "SLEEP"; 94219820Sjeff case 2: return "POLLING"; 95219820Sjeff case 3: return "DISABLED"; 96219820Sjeff case 4: return "PORT_CONFIGURATION TRAINNING"; 97219820Sjeff case 5: return "LINK_UP"; 98219820Sjeff case 6: return "LINK_ERROR_RECOVERY"; 99219820Sjeff case 7: return "PHY TEST"; 100219820Sjeff default: return "invalid physical state"; 101219820Sjeff } 102219820Sjeff} 103219820Sjeff 104219820Sjeffstatic const char *atomic_cap_str(enum ibv_atomic_cap atom_cap) 105219820Sjeff{ 106219820Sjeff switch (atom_cap) { 107219820Sjeff case IBV_ATOMIC_NONE: return "ATOMIC_NONE"; 108219820Sjeff case IBV_ATOMIC_HCA: return "ATOMIC_HCA"; 109219820Sjeff case IBV_ATOMIC_GLOB: return "ATOMIC_GLOB"; 110219820Sjeff default: return "invalid atomic capability"; 111219820Sjeff } 112219820Sjeff} 113219820Sjeff 114219820Sjeffstatic const char *mtu_str(enum ibv_mtu max_mtu) 115219820Sjeff{ 116219820Sjeff switch (max_mtu) { 117219820Sjeff case IBV_MTU_256: return "256"; 118219820Sjeff case IBV_MTU_512: return "512"; 119219820Sjeff case IBV_MTU_1024: return "1024"; 120219820Sjeff case IBV_MTU_2048: return "2048"; 121219820Sjeff case IBV_MTU_4096: return "4096"; 122219820Sjeff default: return "invalid MTU"; 123219820Sjeff } 124219820Sjeff} 125219820Sjeff 126219820Sjeffstatic const char *width_str(uint8_t width) 127219820Sjeff{ 128219820Sjeff switch (width) { 129219820Sjeff case 1: return "1"; 130219820Sjeff case 2: return "4"; 131219820Sjeff case 4: return "8"; 132219820Sjeff case 8: return "12"; 133219820Sjeff default: return "invalid width"; 134219820Sjeff } 135219820Sjeff} 136219820Sjeff 137219820Sjeffstatic const char *speed_str(uint8_t speed) 138219820Sjeff{ 139219820Sjeff switch (speed) { 140219820Sjeff case 1: return "2.5 Gbps"; 141219820Sjeff case 2: return "5.0 Gbps"; 142219820Sjeff case 4: return "10.0 Gbps"; 143219820Sjeff default: return "invalid speed"; 144219820Sjeff } 145219820Sjeff} 146219820Sjeff 147219820Sjeffstatic const char *vl_str(uint8_t vl_num) 148219820Sjeff{ 149219820Sjeff switch (vl_num) { 150219820Sjeff case 1: return "1"; 151219820Sjeff case 2: return "2"; 152219820Sjeff case 3: return "4"; 153219820Sjeff case 4: return "8"; 154219820Sjeff case 5: return "15"; 155219820Sjeff default: return "invalid value"; 156219820Sjeff } 157219820Sjeff} 158219820Sjeff 159219820Sjeffstatic int print_all_port_gids(struct ibv_context *ctx, uint8_t port_num, int tbl_len) 160219820Sjeff{ 161219820Sjeff union ibv_gid gid; 162219820Sjeff int rc = 0; 163219820Sjeff int i; 164219820Sjeff 165219820Sjeff for (i = 0; i < tbl_len; i++) { 166219820Sjeff rc = ibv_query_gid(ctx, port_num, i, &gid); 167219820Sjeff if (rc) { 168219820Sjeff fprintf(stderr, "Failed to query gid to port %d, index %d\n", 169219820Sjeff port_num, i); 170219820Sjeff return rc; 171219820Sjeff } 172219820Sjeff if (!null_gid(&gid)) 173219820Sjeff printf("\t\t\tGID[%3d]:\t\t%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x\n", 174219820Sjeff i, 175219820Sjeff gid.raw[ 0], gid.raw[ 1], 176219820Sjeff gid.raw[ 2], gid.raw[ 3], 177219820Sjeff gid.raw[ 4], gid.raw[ 5], 178219820Sjeff gid.raw[ 6], gid.raw[ 7], 179219820Sjeff gid.raw[ 8], gid.raw[ 9], 180219820Sjeff gid.raw[10], gid.raw[11], 181219820Sjeff gid.raw[12], gid.raw[13], 182219820Sjeff gid.raw[14], gid.raw[15]); 183219820Sjeff } 184219820Sjeff return rc; 185219820Sjeff} 186219820Sjeff 187219820Sjeffstatic const char *link_layer_str(uint8_t link_layer) 188219820Sjeff{ 189219820Sjeff switch (link_layer) { 190219820Sjeff case IBV_LINK_LAYER_UNSPECIFIED: 191219820Sjeff case IBV_LINK_LAYER_INFINIBAND: 192219820Sjeff return "IB"; 193219820Sjeff case IBV_LINK_LAYER_ETHERNET: 194219820Sjeff return "Ethernet"; 195219820Sjeff default: 196219820Sjeff return "Unknown"; 197219820Sjeff } 198219820Sjeff} 199219820Sjeff 200219820Sjeffstatic int print_hca_cap(struct ibv_device *ib_dev, uint8_t ib_port) 201219820Sjeff{ 202219820Sjeff struct ibv_context *ctx; 203219820Sjeff struct ibv_device_attr device_attr; 204219820Sjeff struct ibv_port_attr port_attr; 205219820Sjeff int rc = 0; 206219820Sjeff uint8_t port; 207219820Sjeff char buf[256]; 208219820Sjeff 209219820Sjeff ctx = ibv_open_device(ib_dev); 210219820Sjeff if (!ctx) { 211219820Sjeff fprintf(stderr, "Failed to open device\n"); 212219820Sjeff rc = 1; 213219820Sjeff goto cleanup; 214219820Sjeff } 215219820Sjeff if (ibv_query_device(ctx, &device_attr)) { 216219820Sjeff fprintf(stderr, "Failed to query device props"); 217219820Sjeff rc = 2; 218219820Sjeff goto cleanup; 219219820Sjeff } 220219820Sjeff 221219820Sjeff printf("hca_id:\t%s\n", ibv_get_device_name(ib_dev)); 222219820Sjeff printf("\ttransport:\t\t\t%s (%d)\n", 223219820Sjeff transport_str(ib_dev->transport_type), ib_dev->transport_type); 224219820Sjeff if (strlen(device_attr.fw_ver)) 225219820Sjeff printf("\tfw_ver:\t\t\t\t%s\n", device_attr.fw_ver); 226219820Sjeff printf("\tnode_guid:\t\t\t%s\n", guid_str(device_attr.node_guid, buf)); 227219820Sjeff printf("\tsys_image_guid:\t\t\t%s\n", guid_str(device_attr.sys_image_guid, buf)); 228219820Sjeff printf("\tvendor_id:\t\t\t0x%04x\n", device_attr.vendor_id); 229219820Sjeff printf("\tvendor_part_id:\t\t\t%d\n", device_attr.vendor_part_id); 230219820Sjeff printf("\thw_ver:\t\t\t\t0x%X\n", device_attr.hw_ver); 231219820Sjeff 232219820Sjeff if (ibv_read_sysfs_file(ib_dev->ibdev_path, "board_id", buf, sizeof buf) > 0) 233219820Sjeff printf("\tboard_id:\t\t\t%s\n", buf); 234219820Sjeff 235219820Sjeff printf("\tphys_port_cnt:\t\t\t%d\n", device_attr.phys_port_cnt); 236219820Sjeff 237219820Sjeff if (verbose) { 238219820Sjeff printf("\tmax_mr_size:\t\t\t0x%llx\n", 239219820Sjeff (unsigned long long) device_attr.max_mr_size); 240219820Sjeff printf("\tpage_size_cap:\t\t\t0x%llx\n", 241219820Sjeff (unsigned long long) device_attr.page_size_cap); 242219820Sjeff printf("\tmax_qp:\t\t\t\t%d\n", device_attr.max_qp); 243219820Sjeff printf("\tmax_qp_wr:\t\t\t%d\n", device_attr.max_qp_wr); 244219820Sjeff printf("\tdevice_cap_flags:\t\t0x%08x\n", device_attr.device_cap_flags); 245219820Sjeff printf("\tmax_sge:\t\t\t%d\n", device_attr.max_sge); 246219820Sjeff printf("\tmax_sge_rd:\t\t\t%d\n", device_attr.max_sge_rd); 247219820Sjeff printf("\tmax_cq:\t\t\t\t%d\n", device_attr.max_cq); 248219820Sjeff printf("\tmax_cqe:\t\t\t%d\n", device_attr.max_cqe); 249219820Sjeff printf("\tmax_mr:\t\t\t\t%d\n", device_attr.max_mr); 250219820Sjeff printf("\tmax_pd:\t\t\t\t%d\n", device_attr.max_pd); 251219820Sjeff printf("\tmax_qp_rd_atom:\t\t\t%d\n", device_attr.max_qp_rd_atom); 252219820Sjeff printf("\tmax_ee_rd_atom:\t\t\t%d\n", device_attr.max_ee_rd_atom); 253219820Sjeff printf("\tmax_res_rd_atom:\t\t%d\n", device_attr.max_res_rd_atom); 254219820Sjeff printf("\tmax_qp_init_rd_atom:\t\t%d\n", device_attr.max_qp_init_rd_atom); 255219820Sjeff printf("\tmax_ee_init_rd_atom:\t\t%d\n", device_attr.max_ee_init_rd_atom); 256219820Sjeff printf("\tatomic_cap:\t\t\t%s (%d)\n", 257219820Sjeff atomic_cap_str(device_attr.atomic_cap), device_attr.atomic_cap); 258219820Sjeff printf("\tmax_ee:\t\t\t\t%d\n", device_attr.max_ee); 259219820Sjeff printf("\tmax_rdd:\t\t\t%d\n", device_attr.max_rdd); 260219820Sjeff printf("\tmax_mw:\t\t\t\t%d\n", device_attr.max_mw); 261219820Sjeff printf("\tmax_raw_ipv6_qp:\t\t%d\n", device_attr.max_raw_ipv6_qp); 262219820Sjeff printf("\tmax_raw_ethy_qp:\t\t%d\n", device_attr.max_raw_ethy_qp); 263219820Sjeff printf("\tmax_mcast_grp:\t\t\t%d\n", device_attr.max_mcast_grp); 264219820Sjeff printf("\tmax_mcast_qp_attach:\t\t%d\n", device_attr.max_mcast_qp_attach); 265219820Sjeff printf("\tmax_total_mcast_qp_attach:\t%d\n", 266219820Sjeff device_attr.max_total_mcast_qp_attach); 267219820Sjeff printf("\tmax_ah:\t\t\t\t%d\n", device_attr.max_ah); 268219820Sjeff printf("\tmax_fmr:\t\t\t%d\n", device_attr.max_fmr); 269219820Sjeff if (device_attr.max_fmr) 270219820Sjeff printf("\tmax_map_per_fmr:\t\t%d\n", device_attr.max_map_per_fmr); 271219820Sjeff printf("\tmax_srq:\t\t\t%d\n", device_attr.max_srq); 272219820Sjeff if (device_attr.max_srq) { 273219820Sjeff printf("\tmax_srq_wr:\t\t\t%d\n", device_attr.max_srq_wr); 274219820Sjeff printf("\tmax_srq_sge:\t\t\t%d\n", device_attr.max_srq_sge); 275219820Sjeff } 276219820Sjeff printf("\tmax_pkeys:\t\t\t%d\n", device_attr.max_pkeys); 277219820Sjeff printf("\tlocal_ca_ack_delay:\t\t%d\n", device_attr.local_ca_ack_delay); 278219820Sjeff } 279219820Sjeff 280219820Sjeff for (port = 1; port <= device_attr.phys_port_cnt; ++port) { 281219820Sjeff /* if in the command line the user didn't ask for info about this port */ 282219820Sjeff if ((ib_port) && (port != ib_port)) 283219820Sjeff continue; 284219820Sjeff 285219820Sjeff rc = ibv_query_port(ctx, port, &port_attr); 286219820Sjeff if (rc) { 287219820Sjeff fprintf(stderr, "Failed to query port %u props\n", port); 288219820Sjeff goto cleanup; 289219820Sjeff } 290219820Sjeff printf("\t\tport:\t%d\n", port); 291219820Sjeff printf("\t\t\tstate:\t\t\t%s (%d)\n", 292219820Sjeff port_state_str(port_attr.state), port_attr.state); 293219820Sjeff printf("\t\t\tmax_mtu:\t\t%s (%d)\n", 294219820Sjeff mtu_str(port_attr.max_mtu), port_attr.max_mtu); 295219820Sjeff printf("\t\t\tactive_mtu:\t\t%s (%d)\n", 296219820Sjeff mtu_str(port_attr.active_mtu), port_attr.active_mtu); 297219820Sjeff printf("\t\t\tsm_lid:\t\t\t%d\n", port_attr.sm_lid); 298219820Sjeff printf("\t\t\tport_lid:\t\t%d\n", port_attr.lid); 299219820Sjeff printf("\t\t\tport_lmc:\t\t0x%02x\n", port_attr.lmc); 300219820Sjeff printf("\t\t\tlink_layer:\t\t%s\n", link_layer_str(port_attr.link_layer)); 301219820Sjeff 302219820Sjeff if (verbose) { 303219820Sjeff printf("\t\t\tmax_msg_sz:\t\t0x%x\n", port_attr.max_msg_sz); 304219820Sjeff printf("\t\t\tport_cap_flags:\t\t0x%08x\n", port_attr.port_cap_flags); 305219820Sjeff printf("\t\t\tmax_vl_num:\t\t%s (%d)\n", 306219820Sjeff vl_str(port_attr.max_vl_num), port_attr.max_vl_num); 307219820Sjeff printf("\t\t\tbad_pkey_cntr:\t\t0x%x\n", port_attr.bad_pkey_cntr); 308219820Sjeff printf("\t\t\tqkey_viol_cntr:\t\t0x%x\n", port_attr.qkey_viol_cntr); 309219820Sjeff printf("\t\t\tsm_sl:\t\t\t%d\n", port_attr.sm_sl); 310219820Sjeff printf("\t\t\tpkey_tbl_len:\t\t%d\n", port_attr.pkey_tbl_len); 311219820Sjeff printf("\t\t\tgid_tbl_len:\t\t%d\n", port_attr.gid_tbl_len); 312219820Sjeff printf("\t\t\tsubnet_timeout:\t\t%d\n", port_attr.subnet_timeout); 313219820Sjeff printf("\t\t\tinit_type_reply:\t%d\n", port_attr.init_type_reply); 314219820Sjeff printf("\t\t\tactive_width:\t\t%sX (%d)\n", 315219820Sjeff width_str(port_attr.active_width), port_attr.active_width); 316219820Sjeff printf("\t\t\tactive_speed:\t\t%s (%d)\n", 317219820Sjeff speed_str(port_attr.active_speed), port_attr.active_speed); 318219820Sjeff printf("\t\t\tphys_state:\t\t%s (%d)\n", 319219820Sjeff port_phy_state_str(port_attr.phys_state), port_attr.phys_state); 320219820Sjeff 321219820Sjeff if (print_all_port_gids(ctx, port, port_attr.gid_tbl_len)) 322219820Sjeff goto cleanup; 323219820Sjeff } 324219820Sjeff printf("\n"); 325219820Sjeff } 326219820Sjeffcleanup: 327219820Sjeff if (ctx) 328219820Sjeff if (ibv_close_device(ctx)) { 329219820Sjeff fprintf(stderr, "Failed to close device"); 330219820Sjeff rc = 3; 331219820Sjeff } 332219820Sjeff return rc; 333219820Sjeff} 334219820Sjeff 335219820Sjeffstatic void usage(const char *argv0) 336219820Sjeff{ 337219820Sjeff printf("Usage: %s print the ca attributes\n", argv0); 338219820Sjeff printf("\n"); 339219820Sjeff printf("Options:\n"); 340219820Sjeff printf(" -d, --ib-dev=<dev> use IB device <dev> (default first device found)\n"); 341219820Sjeff printf(" -i, --ib-port=<port> use port <port> of IB device (default all ports)\n"); 342219820Sjeff printf(" -l, --list print only the IB devices names\n"); 343219820Sjeff printf(" -v, --verbose print all the attributes of the IB device(s)\n"); 344219820Sjeff} 345219820Sjeff 346219820Sjeffint main(int argc, char *argv[]) 347219820Sjeff{ 348219820Sjeff char *ib_devname = NULL; 349219820Sjeff int ret = 0; 350219820Sjeff struct ibv_device **dev_list, **orig_dev_list; 351219820Sjeff int num_of_hcas; 352219820Sjeff int ib_port = 0; 353219820Sjeff 354219820Sjeff /* parse command line options */ 355219820Sjeff while (1) { 356219820Sjeff int c; 357219820Sjeff static struct option long_options[] = { 358219820Sjeff { .name = "ib-dev", .has_arg = 1, .val = 'd' }, 359219820Sjeff { .name = "ib-port", .has_arg = 1, .val = 'i' }, 360219820Sjeff { .name = "list", .has_arg = 0, .val = 'l' }, 361219820Sjeff { .name = "verbose", .has_arg = 0, .val = 'v' }, 362219820Sjeff { 0, 0, 0, 0} 363219820Sjeff }; 364219820Sjeff 365219820Sjeff c = getopt_long(argc, argv, "d:i:lv", long_options, NULL); 366219820Sjeff if (c == -1) 367219820Sjeff break; 368219820Sjeff 369219820Sjeff switch (c) { 370219820Sjeff case 'd': 371219820Sjeff ib_devname = strdup(optarg); 372219820Sjeff break; 373219820Sjeff 374219820Sjeff case 'i': 375219820Sjeff ib_port = strtol(optarg, NULL, 0); 376219820Sjeff if (ib_port < 0) { 377219820Sjeff usage(argv[0]); 378219820Sjeff return 1; 379219820Sjeff } 380219820Sjeff break; 381219820Sjeff 382219820Sjeff case 'v': 383219820Sjeff verbose = 1; 384219820Sjeff break; 385219820Sjeff 386219820Sjeff case 'l': 387219820Sjeff dev_list = orig_dev_list = ibv_get_device_list(&num_of_hcas); 388219820Sjeff if (!dev_list) { 389219820Sjeff perror("Failed to get IB devices list"); 390219820Sjeff return -1; 391219820Sjeff } 392219820Sjeff 393219820Sjeff printf("%d HCA%s found:\n", num_of_hcas, 394219820Sjeff num_of_hcas != 1 ? "s" : ""); 395219820Sjeff 396219820Sjeff while (*dev_list) { 397219820Sjeff printf("\t%s\n", ibv_get_device_name(*dev_list)); 398219820Sjeff ++dev_list; 399219820Sjeff } 400219820Sjeff 401219820Sjeff printf("\n"); 402219820Sjeff 403219820Sjeff ibv_free_device_list(orig_dev_list); 404219820Sjeff 405219820Sjeff return 0; 406219820Sjeff 407219820Sjeff default: 408219820Sjeff usage(argv[0]); 409219820Sjeff return -1; 410219820Sjeff } 411219820Sjeff } 412219820Sjeff 413219820Sjeff dev_list = orig_dev_list = ibv_get_device_list(NULL); 414219820Sjeff if (!dev_list) { 415219820Sjeff perror("Failed to get IB devices list"); 416219820Sjeff return -1; 417219820Sjeff } 418219820Sjeff 419219820Sjeff if (ib_devname) { 420219820Sjeff while (*dev_list) { 421219820Sjeff if (!strcmp(ibv_get_device_name(*dev_list), ib_devname)) 422219820Sjeff break; 423219820Sjeff ++dev_list; 424219820Sjeff } 425219820Sjeff 426219820Sjeff if (!*dev_list) { 427219820Sjeff fprintf(stderr, "IB device '%s' wasn't found\n", ib_devname); 428219820Sjeff return -1; 429219820Sjeff } 430219820Sjeff 431219820Sjeff ret |= print_hca_cap(*dev_list, ib_port); 432219820Sjeff } else { 433219820Sjeff if (!*dev_list) { 434219820Sjeff fprintf(stderr, "No IB devices found\n"); 435219820Sjeff return -1; 436219820Sjeff } 437219820Sjeff 438219820Sjeff while (*dev_list) { 439219820Sjeff ret |= print_hca_cap(*dev_list, ib_port); 440219820Sjeff ++dev_list; 441219820Sjeff } 442219820Sjeff } 443219820Sjeff 444219820Sjeff if (ib_devname) 445219820Sjeff free(ib_devname); 446219820Sjeff 447219820Sjeff ibv_free_device_list(orig_dev_list); 448219820Sjeff 449219820Sjeff return ret; 450219820Sjeff} 451