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