1aa0a1e58SJeff Roberson /*
2aa0a1e58SJeff Roberson * Copyright (c) 2005 Cisco Systems. All rights reserved.
3aa0a1e58SJeff Roberson * Copyright (c) 2005 Mellanox Technologies Ltd. All rights reserved.
4aa0a1e58SJeff Roberson *
5aa0a1e58SJeff Roberson * This software is available to you under a choice of one of two
6aa0a1e58SJeff Roberson * licenses. You may choose to be licensed under the terms of the GNU
7aa0a1e58SJeff Roberson * General Public License (GPL) Version 2, available from the file
8aa0a1e58SJeff Roberson * COPYING in the main directory of this source tree, or the
9aa0a1e58SJeff Roberson * OpenIB.org BSD license below:
10aa0a1e58SJeff Roberson *
11aa0a1e58SJeff Roberson * Redistribution and use in source and binary forms, with or
12aa0a1e58SJeff Roberson * without modification, are permitted provided that the following
13aa0a1e58SJeff Roberson * conditions are met:
14aa0a1e58SJeff Roberson *
15aa0a1e58SJeff Roberson * - Redistributions of source code must retain the above
16aa0a1e58SJeff Roberson * copyright notice, this list of conditions and the following
17aa0a1e58SJeff Roberson * disclaimer.
18aa0a1e58SJeff Roberson *
19aa0a1e58SJeff Roberson * - Redistributions in binary form must reproduce the above
20aa0a1e58SJeff Roberson * copyright notice, this list of conditions and the following
21aa0a1e58SJeff Roberson * disclaimer in the documentation and/or other materials
22aa0a1e58SJeff Roberson * provided with the distribution.
23aa0a1e58SJeff Roberson *
24aa0a1e58SJeff Roberson * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25aa0a1e58SJeff Roberson * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26aa0a1e58SJeff Roberson * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27aa0a1e58SJeff Roberson * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28aa0a1e58SJeff Roberson * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29aa0a1e58SJeff Roberson * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30aa0a1e58SJeff Roberson * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31aa0a1e58SJeff Roberson * SOFTWARE.
32aa0a1e58SJeff Roberson */
33aa0a1e58SJeff Roberson
34aa0a1e58SJeff Roberson #include <config.h>
35aa0a1e58SJeff Roberson
36aa0a1e58SJeff Roberson #include <stdio.h>
37aa0a1e58SJeff Roberson #include <stdlib.h>
38aa0a1e58SJeff Roberson #include <unistd.h>
39aa0a1e58SJeff Roberson #include <string.h>
40aa0a1e58SJeff Roberson #include <getopt.h>
41d6b92ffaSHans Petter Selasky #include <infiniband/endian.h>
42d6b92ffaSHans Petter Selasky #include <inttypes.h>
43aa0a1e58SJeff Roberson
44aa0a1e58SJeff Roberson #include <infiniband/verbs.h>
45aa0a1e58SJeff Roberson #include <infiniband/driver.h>
46aa0a1e58SJeff Roberson
47aa0a1e58SJeff Roberson static int verbose;
48aa0a1e58SJeff Roberson
null_gid(union ibv_gid * gid)49aa0a1e58SJeff Roberson static int null_gid(union ibv_gid *gid)
50aa0a1e58SJeff Roberson {
51aa0a1e58SJeff Roberson return !(gid->raw[8] | gid->raw[9] | gid->raw[10] | gid->raw[11] |
52aa0a1e58SJeff Roberson gid->raw[12] | gid->raw[13] | gid->raw[14] | gid->raw[15]);
53aa0a1e58SJeff Roberson }
54aa0a1e58SJeff Roberson
guid_str(__be64 _node_guid,char * str)55d6b92ffaSHans Petter Selasky static const char *guid_str(__be64 _node_guid, char *str)
56aa0a1e58SJeff Roberson {
57d6b92ffaSHans Petter Selasky uint64_t node_guid = be64toh(_node_guid);
58aa0a1e58SJeff Roberson sprintf(str, "%04x:%04x:%04x:%04x",
59aa0a1e58SJeff Roberson (unsigned) (node_guid >> 48) & 0xffff,
60aa0a1e58SJeff Roberson (unsigned) (node_guid >> 32) & 0xffff,
61aa0a1e58SJeff Roberson (unsigned) (node_guid >> 16) & 0xffff,
62aa0a1e58SJeff Roberson (unsigned) (node_guid >> 0) & 0xffff);
63aa0a1e58SJeff Roberson return str;
64aa0a1e58SJeff Roberson }
65aa0a1e58SJeff Roberson
transport_str(enum ibv_transport_type transport)66aa0a1e58SJeff Roberson static const char *transport_str(enum ibv_transport_type transport)
67aa0a1e58SJeff Roberson {
68aa0a1e58SJeff Roberson switch (transport) {
69aa0a1e58SJeff Roberson case IBV_TRANSPORT_IB: return "InfiniBand";
70aa0a1e58SJeff Roberson case IBV_TRANSPORT_IWARP: return "iWARP";
71d6b92ffaSHans Petter Selasky case IBV_TRANSPORT_USNIC: return "usNIC";
72d6b92ffaSHans Petter Selasky case IBV_TRANSPORT_USNIC_UDP: return "usNIC UDP";
73aa0a1e58SJeff Roberson default: return "invalid transport";
74aa0a1e58SJeff Roberson }
75aa0a1e58SJeff Roberson }
76aa0a1e58SJeff Roberson
port_state_str(enum ibv_port_state pstate)77aa0a1e58SJeff Roberson static const char *port_state_str(enum ibv_port_state pstate)
78aa0a1e58SJeff Roberson {
79aa0a1e58SJeff Roberson switch (pstate) {
80aa0a1e58SJeff Roberson case IBV_PORT_DOWN: return "PORT_DOWN";
81aa0a1e58SJeff Roberson case IBV_PORT_INIT: return "PORT_INIT";
82aa0a1e58SJeff Roberson case IBV_PORT_ARMED: return "PORT_ARMED";
83aa0a1e58SJeff Roberson case IBV_PORT_ACTIVE: return "PORT_ACTIVE";
84aa0a1e58SJeff Roberson default: return "invalid state";
85aa0a1e58SJeff Roberson }
86aa0a1e58SJeff Roberson }
87aa0a1e58SJeff Roberson
port_phy_state_str(uint8_t phys_state)88aa0a1e58SJeff Roberson static const char *port_phy_state_str(uint8_t phys_state)
89aa0a1e58SJeff Roberson {
90aa0a1e58SJeff Roberson switch (phys_state) {
91aa0a1e58SJeff Roberson case 1: return "SLEEP";
92aa0a1e58SJeff Roberson case 2: return "POLLING";
93aa0a1e58SJeff Roberson case 3: return "DISABLED";
94aa0a1e58SJeff Roberson case 4: return "PORT_CONFIGURATION TRAINNING";
95aa0a1e58SJeff Roberson case 5: return "LINK_UP";
96aa0a1e58SJeff Roberson case 6: return "LINK_ERROR_RECOVERY";
97aa0a1e58SJeff Roberson case 7: return "PHY TEST";
98aa0a1e58SJeff Roberson default: return "invalid physical state";
99aa0a1e58SJeff Roberson }
100aa0a1e58SJeff Roberson }
101aa0a1e58SJeff Roberson
atomic_cap_str(enum ibv_atomic_cap atom_cap)102aa0a1e58SJeff Roberson static const char *atomic_cap_str(enum ibv_atomic_cap atom_cap)
103aa0a1e58SJeff Roberson {
104aa0a1e58SJeff Roberson switch (atom_cap) {
105aa0a1e58SJeff Roberson case IBV_ATOMIC_NONE: return "ATOMIC_NONE";
106aa0a1e58SJeff Roberson case IBV_ATOMIC_HCA: return "ATOMIC_HCA";
107aa0a1e58SJeff Roberson case IBV_ATOMIC_GLOB: return "ATOMIC_GLOB";
108aa0a1e58SJeff Roberson default: return "invalid atomic capability";
109aa0a1e58SJeff Roberson }
110aa0a1e58SJeff Roberson }
111aa0a1e58SJeff Roberson
mtu_str(enum ibv_mtu max_mtu)112aa0a1e58SJeff Roberson static const char *mtu_str(enum ibv_mtu max_mtu)
113aa0a1e58SJeff Roberson {
114aa0a1e58SJeff Roberson switch (max_mtu) {
115aa0a1e58SJeff Roberson case IBV_MTU_256: return "256";
116aa0a1e58SJeff Roberson case IBV_MTU_512: return "512";
117aa0a1e58SJeff Roberson case IBV_MTU_1024: return "1024";
118aa0a1e58SJeff Roberson case IBV_MTU_2048: return "2048";
119aa0a1e58SJeff Roberson case IBV_MTU_4096: return "4096";
120aa0a1e58SJeff Roberson default: return "invalid MTU";
121aa0a1e58SJeff Roberson }
122aa0a1e58SJeff Roberson }
123aa0a1e58SJeff Roberson
width_str(uint8_t width)124aa0a1e58SJeff Roberson static const char *width_str(uint8_t width)
125aa0a1e58SJeff Roberson {
126aa0a1e58SJeff Roberson switch (width) {
127aa0a1e58SJeff Roberson case 1: return "1";
128aa0a1e58SJeff Roberson case 2: return "4";
129aa0a1e58SJeff Roberson case 4: return "8";
130aa0a1e58SJeff Roberson case 8: return "12";
131daceb336SHans Petter Selasky case 16: return "2";
132aa0a1e58SJeff Roberson default: return "invalid width";
133aa0a1e58SJeff Roberson }
134aa0a1e58SJeff Roberson }
135aa0a1e58SJeff Roberson
speed_str(uint8_t speed)136aa0a1e58SJeff Roberson static const char *speed_str(uint8_t speed)
137aa0a1e58SJeff Roberson {
138aa0a1e58SJeff Roberson switch (speed) {
139aa0a1e58SJeff Roberson case 1: return "2.5 Gbps";
140aa0a1e58SJeff Roberson case 2: return "5.0 Gbps";
141d6b92ffaSHans Petter Selasky
142d6b92ffaSHans Petter Selasky case 4: /* fall through */
143d6b92ffaSHans Petter Selasky case 8: return "10.0 Gbps";
144d6b92ffaSHans Petter Selasky
145d6b92ffaSHans Petter Selasky case 16: return "14.0 Gbps";
146d6b92ffaSHans Petter Selasky case 32: return "25.0 Gbps";
147daceb336SHans Petter Selasky case 64: return "50.0 Gbps";
148*59634232SSlava Shwartsman case 128: return "100.0 Gbps";
149aa0a1e58SJeff Roberson default: return "invalid speed";
150aa0a1e58SJeff Roberson }
151aa0a1e58SJeff Roberson }
152aa0a1e58SJeff Roberson
vl_str(uint8_t vl_num)153aa0a1e58SJeff Roberson static const char *vl_str(uint8_t vl_num)
154aa0a1e58SJeff Roberson {
155aa0a1e58SJeff Roberson switch (vl_num) {
156aa0a1e58SJeff Roberson case 1: return "1";
157aa0a1e58SJeff Roberson case 2: return "2";
158aa0a1e58SJeff Roberson case 3: return "4";
159aa0a1e58SJeff Roberson case 4: return "8";
160aa0a1e58SJeff Roberson case 5: return "15";
161aa0a1e58SJeff Roberson default: return "invalid value";
162aa0a1e58SJeff Roberson }
163aa0a1e58SJeff Roberson }
164aa0a1e58SJeff Roberson
print_all_port_gids(struct ibv_context * ctx,uint8_t port_num,int tbl_len)165aa0a1e58SJeff Roberson static int print_all_port_gids(struct ibv_context *ctx, uint8_t port_num, int tbl_len)
166aa0a1e58SJeff Roberson {
167aa0a1e58SJeff Roberson union ibv_gid gid;
168aa0a1e58SJeff Roberson int rc = 0;
169aa0a1e58SJeff Roberson int i;
170aa0a1e58SJeff Roberson
171aa0a1e58SJeff Roberson for (i = 0; i < tbl_len; i++) {
172aa0a1e58SJeff Roberson rc = ibv_query_gid(ctx, port_num, i, &gid);
173aa0a1e58SJeff Roberson if (rc) {
174aa0a1e58SJeff Roberson fprintf(stderr, "Failed to query gid to port %d, index %d\n",
175aa0a1e58SJeff Roberson port_num, i);
176aa0a1e58SJeff Roberson return rc;
177aa0a1e58SJeff Roberson }
178aa0a1e58SJeff Roberson if (!null_gid(&gid))
179aa0a1e58SJeff Roberson printf("\t\t\tGID[%3d]:\t\t%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x\n",
180aa0a1e58SJeff Roberson i,
181aa0a1e58SJeff Roberson gid.raw[ 0], gid.raw[ 1],
182aa0a1e58SJeff Roberson gid.raw[ 2], gid.raw[ 3],
183aa0a1e58SJeff Roberson gid.raw[ 4], gid.raw[ 5],
184aa0a1e58SJeff Roberson gid.raw[ 6], gid.raw[ 7],
185aa0a1e58SJeff Roberson gid.raw[ 8], gid.raw[ 9],
186aa0a1e58SJeff Roberson gid.raw[10], gid.raw[11],
187aa0a1e58SJeff Roberson gid.raw[12], gid.raw[13],
188aa0a1e58SJeff Roberson gid.raw[14], gid.raw[15]);
189aa0a1e58SJeff Roberson }
190aa0a1e58SJeff Roberson return rc;
191aa0a1e58SJeff Roberson }
192aa0a1e58SJeff Roberson
link_layer_str(uint8_t link_layer)193aa0a1e58SJeff Roberson static const char *link_layer_str(uint8_t link_layer)
194aa0a1e58SJeff Roberson {
195aa0a1e58SJeff Roberson switch (link_layer) {
196aa0a1e58SJeff Roberson case IBV_LINK_LAYER_UNSPECIFIED:
197aa0a1e58SJeff Roberson case IBV_LINK_LAYER_INFINIBAND:
198d6b92ffaSHans Petter Selasky return "InfiniBand";
199aa0a1e58SJeff Roberson case IBV_LINK_LAYER_ETHERNET:
200aa0a1e58SJeff Roberson return "Ethernet";
201aa0a1e58SJeff Roberson default:
202aa0a1e58SJeff Roberson return "Unknown";
203aa0a1e58SJeff Roberson }
204aa0a1e58SJeff Roberson }
205aa0a1e58SJeff Roberson
print_device_cap_flags(uint32_t dev_cap_flags)206d6b92ffaSHans Petter Selasky static void print_device_cap_flags(uint32_t dev_cap_flags)
207d6b92ffaSHans Petter Selasky {
208d6b92ffaSHans Petter Selasky uint32_t unknown_flags = ~(IBV_DEVICE_RESIZE_MAX_WR |
209d6b92ffaSHans Petter Selasky IBV_DEVICE_BAD_PKEY_CNTR |
210d6b92ffaSHans Petter Selasky IBV_DEVICE_BAD_QKEY_CNTR |
211d6b92ffaSHans Petter Selasky IBV_DEVICE_RAW_MULTI |
212d6b92ffaSHans Petter Selasky IBV_DEVICE_AUTO_PATH_MIG |
213d6b92ffaSHans Petter Selasky IBV_DEVICE_CHANGE_PHY_PORT |
214d6b92ffaSHans Petter Selasky IBV_DEVICE_UD_AV_PORT_ENFORCE |
215d6b92ffaSHans Petter Selasky IBV_DEVICE_CURR_QP_STATE_MOD |
216d6b92ffaSHans Petter Selasky IBV_DEVICE_SHUTDOWN_PORT |
217d6b92ffaSHans Petter Selasky IBV_DEVICE_INIT_TYPE |
218d6b92ffaSHans Petter Selasky IBV_DEVICE_PORT_ACTIVE_EVENT |
219d6b92ffaSHans Petter Selasky IBV_DEVICE_SYS_IMAGE_GUID |
220d6b92ffaSHans Petter Selasky IBV_DEVICE_RC_RNR_NAK_GEN |
221d6b92ffaSHans Petter Selasky IBV_DEVICE_SRQ_RESIZE |
222d6b92ffaSHans Petter Selasky IBV_DEVICE_N_NOTIFY_CQ |
223d6b92ffaSHans Petter Selasky IBV_DEVICE_MEM_WINDOW |
224d6b92ffaSHans Petter Selasky IBV_DEVICE_UD_IP_CSUM |
225d6b92ffaSHans Petter Selasky IBV_DEVICE_XRC |
226d6b92ffaSHans Petter Selasky IBV_DEVICE_MEM_MGT_EXTENSIONS |
227d6b92ffaSHans Petter Selasky IBV_DEVICE_MEM_WINDOW_TYPE_2A |
228d6b92ffaSHans Petter Selasky IBV_DEVICE_MEM_WINDOW_TYPE_2B |
229d6b92ffaSHans Petter Selasky IBV_DEVICE_RC_IP_CSUM |
230d6b92ffaSHans Petter Selasky IBV_DEVICE_RAW_IP_CSUM |
231d6b92ffaSHans Petter Selasky IBV_DEVICE_MANAGED_FLOW_STEERING);
232d6b92ffaSHans Petter Selasky
233d6b92ffaSHans Petter Selasky if (dev_cap_flags & IBV_DEVICE_RESIZE_MAX_WR)
234d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tRESIZE_MAX_WR\n");
235d6b92ffaSHans Petter Selasky if (dev_cap_flags & IBV_DEVICE_BAD_PKEY_CNTR)
236d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tBAD_PKEY_CNTR\n");
237d6b92ffaSHans Petter Selasky if (dev_cap_flags & IBV_DEVICE_BAD_QKEY_CNTR)
238d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tBAD_QKEY_CNTR\n");
239d6b92ffaSHans Petter Selasky if (dev_cap_flags & IBV_DEVICE_RAW_MULTI)
240d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tRAW_MULTI\n");
241d6b92ffaSHans Petter Selasky if (dev_cap_flags & IBV_DEVICE_AUTO_PATH_MIG)
242d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tAUTO_PATH_MIG\n");
243d6b92ffaSHans Petter Selasky if (dev_cap_flags & IBV_DEVICE_CHANGE_PHY_PORT)
244d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tCHANGE_PHY_PORT\n");
245d6b92ffaSHans Petter Selasky if (dev_cap_flags & IBV_DEVICE_UD_AV_PORT_ENFORCE)
246d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tUD_AV_PORT_ENFORCE\n");
247d6b92ffaSHans Petter Selasky if (dev_cap_flags & IBV_DEVICE_CURR_QP_STATE_MOD)
248d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tCURR_QP_STATE_MOD\n");
249d6b92ffaSHans Petter Selasky if (dev_cap_flags & IBV_DEVICE_SHUTDOWN_PORT)
250d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tSHUTDOWN_PORT\n");
251d6b92ffaSHans Petter Selasky if (dev_cap_flags & IBV_DEVICE_INIT_TYPE)
252d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tINIT_TYPE\n");
253d6b92ffaSHans Petter Selasky if (dev_cap_flags & IBV_DEVICE_PORT_ACTIVE_EVENT)
254d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tPORT_ACTIVE_EVENT\n");
255d6b92ffaSHans Petter Selasky if (dev_cap_flags & IBV_DEVICE_SYS_IMAGE_GUID)
256d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tSYS_IMAGE_GUID\n");
257d6b92ffaSHans Petter Selasky if (dev_cap_flags & IBV_DEVICE_RC_RNR_NAK_GEN)
258d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tRC_RNR_NAK_GEN\n");
259d6b92ffaSHans Petter Selasky if (dev_cap_flags & IBV_DEVICE_SRQ_RESIZE)
260d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tSRQ_RESIZE\n");
261d6b92ffaSHans Petter Selasky if (dev_cap_flags & IBV_DEVICE_N_NOTIFY_CQ)
262d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tN_NOTIFY_CQ\n");
263d6b92ffaSHans Petter Selasky if (dev_cap_flags & IBV_DEVICE_MEM_WINDOW)
264d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tMEM_WINDOW\n");
265d6b92ffaSHans Petter Selasky if (dev_cap_flags & IBV_DEVICE_UD_IP_CSUM)
266d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tUD_IP_CSUM\n");
267d6b92ffaSHans Petter Selasky if (dev_cap_flags & IBV_DEVICE_XRC)
268d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tXRC\n");
269d6b92ffaSHans Petter Selasky if (dev_cap_flags & IBV_DEVICE_MEM_MGT_EXTENSIONS)
270d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tMEM_MGT_EXTENSIONS\n");
271d6b92ffaSHans Petter Selasky if (dev_cap_flags & IBV_DEVICE_MEM_WINDOW_TYPE_2A)
272d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tMEM_WINDOW_TYPE_2A\n");
273d6b92ffaSHans Petter Selasky if (dev_cap_flags & IBV_DEVICE_MEM_WINDOW_TYPE_2B)
274d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tMEM_WINDOW_TYPE_2B\n");
275d6b92ffaSHans Petter Selasky if (dev_cap_flags & IBV_DEVICE_RC_IP_CSUM)
276d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tRC_IP_CSUM\n");
277d6b92ffaSHans Petter Selasky if (dev_cap_flags & IBV_DEVICE_RAW_IP_CSUM)
278d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tRAW_IP_CSUM\n");
279d6b92ffaSHans Petter Selasky if (dev_cap_flags & IBV_DEVICE_MANAGED_FLOW_STEERING)
280d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tMANAGED_FLOW_STEERING\n");
281d6b92ffaSHans Petter Selasky if (dev_cap_flags & unknown_flags)
282d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tUnknown flags: 0x%" PRIX32 "\n",
283d6b92ffaSHans Petter Selasky dev_cap_flags & unknown_flags);
284d6b92ffaSHans Petter Selasky }
285d6b92ffaSHans Petter Selasky
print_odp_trans_caps(uint32_t trans)286d6b92ffaSHans Petter Selasky static void print_odp_trans_caps(uint32_t trans)
287d6b92ffaSHans Petter Selasky {
288d6b92ffaSHans Petter Selasky uint32_t unknown_transport_caps = ~(IBV_ODP_SUPPORT_SEND |
289d6b92ffaSHans Petter Selasky IBV_ODP_SUPPORT_RECV |
290d6b92ffaSHans Petter Selasky IBV_ODP_SUPPORT_WRITE |
291d6b92ffaSHans Petter Selasky IBV_ODP_SUPPORT_READ |
292d6b92ffaSHans Petter Selasky IBV_ODP_SUPPORT_ATOMIC);
293d6b92ffaSHans Petter Selasky
294d6b92ffaSHans Petter Selasky if (!trans) {
295d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tNO SUPPORT\n");
296d6b92ffaSHans Petter Selasky } else {
297d6b92ffaSHans Petter Selasky if (trans & IBV_ODP_SUPPORT_SEND)
298d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tSUPPORT_SEND\n");
299d6b92ffaSHans Petter Selasky if (trans & IBV_ODP_SUPPORT_RECV)
300d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tSUPPORT_RECV\n");
301d6b92ffaSHans Petter Selasky if (trans & IBV_ODP_SUPPORT_WRITE)
302d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tSUPPORT_WRITE\n");
303d6b92ffaSHans Petter Selasky if (trans & IBV_ODP_SUPPORT_READ)
304d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tSUPPORT_READ\n");
305d6b92ffaSHans Petter Selasky if (trans & IBV_ODP_SUPPORT_ATOMIC)
306d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tSUPPORT_ATOMIC\n");
307d6b92ffaSHans Petter Selasky if (trans & unknown_transport_caps)
308d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tUnknown flags: 0x%" PRIX32 "\n",
309d6b92ffaSHans Petter Selasky trans & unknown_transport_caps);
310d6b92ffaSHans Petter Selasky }
311d6b92ffaSHans Petter Selasky }
312d6b92ffaSHans Petter Selasky
print_odp_caps(const struct ibv_odp_caps * caps)313d6b92ffaSHans Petter Selasky static void print_odp_caps(const struct ibv_odp_caps *caps)
314d6b92ffaSHans Petter Selasky {
315d6b92ffaSHans Petter Selasky uint64_t unknown_general_caps = ~(IBV_ODP_SUPPORT);
316d6b92ffaSHans Petter Selasky
317d6b92ffaSHans Petter Selasky /* general odp caps */
318d6b92ffaSHans Petter Selasky printf("\tgeneral_odp_caps:\n");
319d6b92ffaSHans Petter Selasky if (caps->general_caps & IBV_ODP_SUPPORT)
320d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tODP_SUPPORT\n");
321d6b92ffaSHans Petter Selasky if (caps->general_caps & unknown_general_caps)
322d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tUnknown flags: 0x%" PRIX64 "\n",
323d6b92ffaSHans Petter Selasky caps->general_caps & unknown_general_caps);
324d6b92ffaSHans Petter Selasky
325d6b92ffaSHans Petter Selasky /* RC transport */
326d6b92ffaSHans Petter Selasky printf("\trc_odp_caps:\n");
327d6b92ffaSHans Petter Selasky print_odp_trans_caps(caps->per_transport_caps.rc_odp_caps);
328d6b92ffaSHans Petter Selasky printf("\tuc_odp_caps:\n");
329d6b92ffaSHans Petter Selasky print_odp_trans_caps(caps->per_transport_caps.uc_odp_caps);
330d6b92ffaSHans Petter Selasky printf("\tud_odp_caps:\n");
331d6b92ffaSHans Petter Selasky print_odp_trans_caps(caps->per_transport_caps.ud_odp_caps);
332d6b92ffaSHans Petter Selasky }
333d6b92ffaSHans Petter Selasky
print_device_cap_flags_ex(uint64_t device_cap_flags_ex)334d6b92ffaSHans Petter Selasky static void print_device_cap_flags_ex(uint64_t device_cap_flags_ex)
335d6b92ffaSHans Petter Selasky {
336d6b92ffaSHans Petter Selasky uint64_t ex_flags = device_cap_flags_ex & 0xffffffff00000000ULL;
337d6b92ffaSHans Petter Selasky uint64_t unknown_flags = ~(IBV_DEVICE_RAW_SCATTER_FCS);
338d6b92ffaSHans Petter Selasky
339d6b92ffaSHans Petter Selasky if (ex_flags & IBV_DEVICE_RAW_SCATTER_FCS)
340d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tRAW_SCATTER_FCS\n");
341d6b92ffaSHans Petter Selasky if (ex_flags & unknown_flags)
342d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tUnknown flags: 0x%" PRIX64 "\n",
343d6b92ffaSHans Petter Selasky ex_flags & unknown_flags);
344d6b92ffaSHans Petter Selasky }
345d6b92ffaSHans Petter Selasky
print_tso_caps(const struct ibv_tso_caps * caps)346d6b92ffaSHans Petter Selasky static void print_tso_caps(const struct ibv_tso_caps *caps)
347d6b92ffaSHans Petter Selasky {
348d6b92ffaSHans Petter Selasky uint32_t unknown_general_caps = ~(1 << IBV_QPT_RAW_PACKET |
349d6b92ffaSHans Petter Selasky 1 << IBV_QPT_UD);
350d6b92ffaSHans Petter Selasky printf("\ttso_caps:\n");
351d6b92ffaSHans Petter Selasky printf("\tmax_tso:\t\t\t%d\n", caps->max_tso);
352d6b92ffaSHans Petter Selasky
353d6b92ffaSHans Petter Selasky if (caps->max_tso) {
354d6b92ffaSHans Petter Selasky printf("\tsupported_qp:\n");
355d6b92ffaSHans Petter Selasky if (ibv_is_qpt_supported(caps->supported_qpts, IBV_QPT_RAW_PACKET))
356d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tSUPPORT_RAW_PACKET\n");
357d6b92ffaSHans Petter Selasky if (ibv_is_qpt_supported(caps->supported_qpts, IBV_QPT_UD))
358d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tSUPPORT_UD\n");
359d6b92ffaSHans Petter Selasky if (caps->supported_qpts & unknown_general_caps)
360d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tUnknown flags: 0x%" PRIX32 "\n",
361d6b92ffaSHans Petter Selasky caps->supported_qpts & unknown_general_caps);
362d6b92ffaSHans Petter Selasky }
363d6b92ffaSHans Petter Selasky }
364d6b92ffaSHans Petter Selasky
print_rss_caps(const struct ibv_rss_caps * caps)365d6b92ffaSHans Petter Selasky static void print_rss_caps(const struct ibv_rss_caps *caps)
366d6b92ffaSHans Petter Selasky {
367d6b92ffaSHans Petter Selasky uint32_t unknown_general_caps = ~(1 << IBV_QPT_RAW_PACKET |
368d6b92ffaSHans Petter Selasky 1 << IBV_QPT_UD);
369d6b92ffaSHans Petter Selasky printf("\trss_caps:\n");
370d6b92ffaSHans Petter Selasky printf("\t\tmax_rwq_indirection_tables:\t\t\t%u\n", caps->max_rwq_indirection_tables);
371d6b92ffaSHans Petter Selasky printf("\t\tmax_rwq_indirection_table_size:\t\t\t%u\n", caps->max_rwq_indirection_table_size);
372d6b92ffaSHans Petter Selasky printf("\t\trx_hash_function:\t\t\t\t0x%x\n", caps->rx_hash_function);
373d6b92ffaSHans Petter Selasky printf("\t\trx_hash_fields_mask:\t\t\t\t0x%" PRIX64 "\n", caps->rx_hash_fields_mask);
374d6b92ffaSHans Petter Selasky
375d6b92ffaSHans Petter Selasky if (caps->supported_qpts) {
376d6b92ffaSHans Petter Selasky printf("\t\tsupported_qp:\n");
377d6b92ffaSHans Petter Selasky if (ibv_is_qpt_supported(caps->supported_qpts, IBV_QPT_RAW_PACKET))
378d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tSUPPORT_RAW_PACKET\n");
379d6b92ffaSHans Petter Selasky if (ibv_is_qpt_supported(caps->supported_qpts, IBV_QPT_UD))
380d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tSUPPORT_UD\n");
381d6b92ffaSHans Petter Selasky if (caps->supported_qpts & unknown_general_caps)
382d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tUnknown flags: 0x%" PRIX32 "\n",
383d6b92ffaSHans Petter Selasky caps->supported_qpts & unknown_general_caps);
384d6b92ffaSHans Petter Selasky }
385d6b92ffaSHans Petter Selasky }
386d6b92ffaSHans Petter Selasky
print_packet_pacing_caps(const struct ibv_packet_pacing_caps * caps)387d6b92ffaSHans Petter Selasky static void print_packet_pacing_caps(const struct ibv_packet_pacing_caps *caps)
388d6b92ffaSHans Petter Selasky {
389d6b92ffaSHans Petter Selasky uint32_t unknown_general_caps = ~(1 << IBV_QPT_RAW_PACKET |
390d6b92ffaSHans Petter Selasky 1 << IBV_QPT_UD);
391d6b92ffaSHans Petter Selasky printf("\tpacket_pacing_caps:\n");
392d6b92ffaSHans Petter Selasky printf("\t\tqp_rate_limit_min:\t%ukbps\n", caps->qp_rate_limit_min);
393d6b92ffaSHans Petter Selasky printf("\t\tqp_rate_limit_max:\t%ukbps\n", caps->qp_rate_limit_max);
394d6b92ffaSHans Petter Selasky
395d6b92ffaSHans Petter Selasky if (caps->qp_rate_limit_max) {
396d6b92ffaSHans Petter Selasky printf("\t\tsupported_qp:\n");
397d6b92ffaSHans Petter Selasky if (ibv_is_qpt_supported(caps->supported_qpts, IBV_QPT_RAW_PACKET))
398d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tSUPPORT_RAW_PACKET\n");
399d6b92ffaSHans Petter Selasky if (ibv_is_qpt_supported(caps->supported_qpts, IBV_QPT_UD))
400d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tSUPPORT_UD\n");
401d6b92ffaSHans Petter Selasky if (caps->supported_qpts & unknown_general_caps)
402d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tUnknown flags: 0x%" PRIX32 "\n",
403d6b92ffaSHans Petter Selasky caps->supported_qpts & unknown_general_caps);
404d6b92ffaSHans Petter Selasky }
405d6b92ffaSHans Petter Selasky }
406d6b92ffaSHans Petter Selasky
print_raw_packet_caps(uint32_t raw_packet_caps)407d6b92ffaSHans Petter Selasky static void print_raw_packet_caps(uint32_t raw_packet_caps)
408d6b92ffaSHans Petter Selasky {
409d6b92ffaSHans Petter Selasky printf("\traw packet caps:\n");
410d6b92ffaSHans Petter Selasky if (raw_packet_caps & IBV_RAW_PACKET_CAP_CVLAN_STRIPPING)
411d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tC-VLAN stripping offload\n");
412d6b92ffaSHans Petter Selasky if (raw_packet_caps & IBV_RAW_PACKET_CAP_SCATTER_FCS)
413d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tScatter FCS offload\n");
414d6b92ffaSHans Petter Selasky if (raw_packet_caps & IBV_RAW_PACKET_CAP_IP_CSUM)
415d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tIP csum offload\n");
416d6b92ffaSHans Petter Selasky }
417d6b92ffaSHans Petter Selasky
print_hca_cap(struct ibv_device * ib_dev,uint8_t ib_port)418aa0a1e58SJeff Roberson static int print_hca_cap(struct ibv_device *ib_dev, uint8_t ib_port)
419aa0a1e58SJeff Roberson {
420aa0a1e58SJeff Roberson struct ibv_context *ctx;
421d6b92ffaSHans Petter Selasky struct ibv_device_attr_ex device_attr;
422aa0a1e58SJeff Roberson struct ibv_port_attr port_attr;
423aa0a1e58SJeff Roberson int rc = 0;
424aa0a1e58SJeff Roberson uint8_t port;
425aa0a1e58SJeff Roberson char buf[256];
426aa0a1e58SJeff Roberson
427aa0a1e58SJeff Roberson ctx = ibv_open_device(ib_dev);
428aa0a1e58SJeff Roberson if (!ctx) {
429aa0a1e58SJeff Roberson fprintf(stderr, "Failed to open device\n");
430aa0a1e58SJeff Roberson rc = 1;
431aa0a1e58SJeff Roberson goto cleanup;
432aa0a1e58SJeff Roberson }
433d6b92ffaSHans Petter Selasky if (ibv_query_device_ex(ctx, NULL, &device_attr)) {
434d6b92ffaSHans Petter Selasky fprintf(stderr, "Failed to query device props\n");
435aa0a1e58SJeff Roberson rc = 2;
436aa0a1e58SJeff Roberson goto cleanup;
437aa0a1e58SJeff Roberson }
438d6b92ffaSHans Petter Selasky if (ib_port && ib_port > device_attr.orig_attr.phys_port_cnt) {
439d6b92ffaSHans Petter Selasky fprintf(stderr, "Invalid port requested for device\n");
440d6b92ffaSHans Petter Selasky /* rc = 3 is taken by failure to clean up */
441d6b92ffaSHans Petter Selasky rc = 4;
442d6b92ffaSHans Petter Selasky goto cleanup;
443d6b92ffaSHans Petter Selasky }
444aa0a1e58SJeff Roberson
445aa0a1e58SJeff Roberson printf("hca_id:\t%s\n", ibv_get_device_name(ib_dev));
446aa0a1e58SJeff Roberson printf("\ttransport:\t\t\t%s (%d)\n",
447aa0a1e58SJeff Roberson transport_str(ib_dev->transport_type), ib_dev->transport_type);
448d6b92ffaSHans Petter Selasky if (strlen(device_attr.orig_attr.fw_ver))
449d6b92ffaSHans Petter Selasky printf("\tfw_ver:\t\t\t\t%s\n", device_attr.orig_attr.fw_ver);
450d6b92ffaSHans Petter Selasky printf("\tnode_guid:\t\t\t%s\n", guid_str(device_attr.orig_attr.node_guid, buf));
451d6b92ffaSHans Petter Selasky printf("\tsys_image_guid:\t\t\t%s\n", guid_str(device_attr.orig_attr.sys_image_guid, buf));
452d6b92ffaSHans Petter Selasky printf("\tvendor_id:\t\t\t0x%04x\n", device_attr.orig_attr.vendor_id);
453d6b92ffaSHans Petter Selasky printf("\tvendor_part_id:\t\t\t%d\n", device_attr.orig_attr.vendor_part_id);
454d6b92ffaSHans Petter Selasky printf("\thw_ver:\t\t\t\t0x%X\n", device_attr.orig_attr.hw_ver);
455aa0a1e58SJeff Roberson
456aa0a1e58SJeff Roberson if (ibv_read_sysfs_file(ib_dev->ibdev_path, "board_id", buf, sizeof buf) > 0)
457aa0a1e58SJeff Roberson printf("\tboard_id:\t\t\t%s\n", buf);
458aa0a1e58SJeff Roberson
459d6b92ffaSHans Petter Selasky printf("\tphys_port_cnt:\t\t\t%d\n", device_attr.orig_attr.phys_port_cnt);
460aa0a1e58SJeff Roberson
461aa0a1e58SJeff Roberson if (verbose) {
462aa0a1e58SJeff Roberson printf("\tmax_mr_size:\t\t\t0x%llx\n",
463d6b92ffaSHans Petter Selasky (unsigned long long) device_attr.orig_attr.max_mr_size);
464aa0a1e58SJeff Roberson printf("\tpage_size_cap:\t\t\t0x%llx\n",
465d6b92ffaSHans Petter Selasky (unsigned long long) device_attr.orig_attr.page_size_cap);
466d6b92ffaSHans Petter Selasky printf("\tmax_qp:\t\t\t\t%d\n", device_attr.orig_attr.max_qp);
467d6b92ffaSHans Petter Selasky printf("\tmax_qp_wr:\t\t\t%d\n", device_attr.orig_attr.max_qp_wr);
468d6b92ffaSHans Petter Selasky printf("\tdevice_cap_flags:\t\t0x%08x\n", device_attr.orig_attr.device_cap_flags);
469d6b92ffaSHans Petter Selasky print_device_cap_flags(device_attr.orig_attr.device_cap_flags);
470d6b92ffaSHans Petter Selasky printf("\tmax_sge:\t\t\t%d\n", device_attr.orig_attr.max_sge);
471d6b92ffaSHans Petter Selasky printf("\tmax_sge_rd:\t\t\t%d\n", device_attr.orig_attr.max_sge_rd);
472d6b92ffaSHans Petter Selasky printf("\tmax_cq:\t\t\t\t%d\n", device_attr.orig_attr.max_cq);
473d6b92ffaSHans Petter Selasky printf("\tmax_cqe:\t\t\t%d\n", device_attr.orig_attr.max_cqe);
474d6b92ffaSHans Petter Selasky printf("\tmax_mr:\t\t\t\t%d\n", device_attr.orig_attr.max_mr);
475d6b92ffaSHans Petter Selasky printf("\tmax_pd:\t\t\t\t%d\n", device_attr.orig_attr.max_pd);
476d6b92ffaSHans Petter Selasky printf("\tmax_qp_rd_atom:\t\t\t%d\n", device_attr.orig_attr.max_qp_rd_atom);
477d6b92ffaSHans Petter Selasky printf("\tmax_ee_rd_atom:\t\t\t%d\n", device_attr.orig_attr.max_ee_rd_atom);
478d6b92ffaSHans Petter Selasky printf("\tmax_res_rd_atom:\t\t%d\n", device_attr.orig_attr.max_res_rd_atom);
479d6b92ffaSHans Petter Selasky printf("\tmax_qp_init_rd_atom:\t\t%d\n", device_attr.orig_attr.max_qp_init_rd_atom);
480d6b92ffaSHans Petter Selasky printf("\tmax_ee_init_rd_atom:\t\t%d\n", device_attr.orig_attr.max_ee_init_rd_atom);
481aa0a1e58SJeff Roberson printf("\tatomic_cap:\t\t\t%s (%d)\n",
482d6b92ffaSHans Petter Selasky atomic_cap_str(device_attr.orig_attr.atomic_cap), device_attr.orig_attr.atomic_cap);
483d6b92ffaSHans Petter Selasky printf("\tmax_ee:\t\t\t\t%d\n", device_attr.orig_attr.max_ee);
484d6b92ffaSHans Petter Selasky printf("\tmax_rdd:\t\t\t%d\n", device_attr.orig_attr.max_rdd);
485d6b92ffaSHans Petter Selasky printf("\tmax_mw:\t\t\t\t%d\n", device_attr.orig_attr.max_mw);
486d6b92ffaSHans Petter Selasky printf("\tmax_raw_ipv6_qp:\t\t%d\n", device_attr.orig_attr.max_raw_ipv6_qp);
487d6b92ffaSHans Petter Selasky printf("\tmax_raw_ethy_qp:\t\t%d\n", device_attr.orig_attr.max_raw_ethy_qp);
488d6b92ffaSHans Petter Selasky printf("\tmax_mcast_grp:\t\t\t%d\n", device_attr.orig_attr.max_mcast_grp);
489d6b92ffaSHans Petter Selasky printf("\tmax_mcast_qp_attach:\t\t%d\n", device_attr.orig_attr.max_mcast_qp_attach);
490aa0a1e58SJeff Roberson printf("\tmax_total_mcast_qp_attach:\t%d\n",
491d6b92ffaSHans Petter Selasky device_attr.orig_attr.max_total_mcast_qp_attach);
492d6b92ffaSHans Petter Selasky printf("\tmax_ah:\t\t\t\t%d\n", device_attr.orig_attr.max_ah);
493d6b92ffaSHans Petter Selasky printf("\tmax_fmr:\t\t\t%d\n", device_attr.orig_attr.max_fmr);
494d6b92ffaSHans Petter Selasky if (device_attr.orig_attr.max_fmr)
495d6b92ffaSHans Petter Selasky printf("\tmax_map_per_fmr:\t\t%d\n", device_attr.orig_attr.max_map_per_fmr);
496d6b92ffaSHans Petter Selasky printf("\tmax_srq:\t\t\t%d\n", device_attr.orig_attr.max_srq);
497d6b92ffaSHans Petter Selasky if (device_attr.orig_attr.max_srq) {
498d6b92ffaSHans Petter Selasky printf("\tmax_srq_wr:\t\t\t%d\n", device_attr.orig_attr.max_srq_wr);
499d6b92ffaSHans Petter Selasky printf("\tmax_srq_sge:\t\t\t%d\n", device_attr.orig_attr.max_srq_sge);
500aa0a1e58SJeff Roberson }
501d6b92ffaSHans Petter Selasky printf("\tmax_pkeys:\t\t\t%d\n", device_attr.orig_attr.max_pkeys);
502d6b92ffaSHans Petter Selasky printf("\tlocal_ca_ack_delay:\t\t%d\n", device_attr.orig_attr.local_ca_ack_delay);
503d6b92ffaSHans Petter Selasky
504d6b92ffaSHans Petter Selasky print_odp_caps(&device_attr.odp_caps);
505d6b92ffaSHans Petter Selasky if (device_attr.completion_timestamp_mask)
506d6b92ffaSHans Petter Selasky printf("\tcompletion timestamp_mask:\t\t\t0x%016" PRIx64 "\n",
507d6b92ffaSHans Petter Selasky device_attr.completion_timestamp_mask);
508d6b92ffaSHans Petter Selasky else
509d6b92ffaSHans Petter Selasky printf("\tcompletion_timestamp_mask not supported\n");
510d6b92ffaSHans Petter Selasky
511d6b92ffaSHans Petter Selasky if (device_attr.hca_core_clock)
512d6b92ffaSHans Petter Selasky printf("\thca_core_clock:\t\t\t%" PRIu64 "kHZ\n", device_attr.hca_core_clock);
513d6b92ffaSHans Petter Selasky else
514d6b92ffaSHans Petter Selasky printf("\tcore clock not supported\n");
515d6b92ffaSHans Petter Selasky
516d6b92ffaSHans Petter Selasky if (device_attr.raw_packet_caps)
517d6b92ffaSHans Petter Selasky print_raw_packet_caps(device_attr.raw_packet_caps);
518d6b92ffaSHans Petter Selasky
519d6b92ffaSHans Petter Selasky printf("\tdevice_cap_flags_ex:\t\t0x%" PRIX64 "\n", device_attr.device_cap_flags_ex);
520d6b92ffaSHans Petter Selasky print_device_cap_flags_ex(device_attr.device_cap_flags_ex);
521d6b92ffaSHans Petter Selasky print_tso_caps(&device_attr.tso_caps);
522d6b92ffaSHans Petter Selasky print_rss_caps(&device_attr.rss_caps);
523d6b92ffaSHans Petter Selasky printf("\tmax_wq_type_rq:\t\t\t%u\n", device_attr.max_wq_type_rq);
524d6b92ffaSHans Petter Selasky print_packet_pacing_caps(&device_attr.packet_pacing_caps);
525aa0a1e58SJeff Roberson }
526aa0a1e58SJeff Roberson
527d6b92ffaSHans Petter Selasky for (port = 1; port <= device_attr.orig_attr.phys_port_cnt; ++port) {
528aa0a1e58SJeff Roberson /* if in the command line the user didn't ask for info about this port */
529aa0a1e58SJeff Roberson if ((ib_port) && (port != ib_port))
530aa0a1e58SJeff Roberson continue;
531aa0a1e58SJeff Roberson
532aa0a1e58SJeff Roberson rc = ibv_query_port(ctx, port, &port_attr);
533aa0a1e58SJeff Roberson if (rc) {
534aa0a1e58SJeff Roberson fprintf(stderr, "Failed to query port %u props\n", port);
535aa0a1e58SJeff Roberson goto cleanup;
536aa0a1e58SJeff Roberson }
537aa0a1e58SJeff Roberson printf("\t\tport:\t%d\n", port);
538aa0a1e58SJeff Roberson printf("\t\t\tstate:\t\t\t%s (%d)\n",
539aa0a1e58SJeff Roberson port_state_str(port_attr.state), port_attr.state);
540aa0a1e58SJeff Roberson printf("\t\t\tmax_mtu:\t\t%s (%d)\n",
541aa0a1e58SJeff Roberson mtu_str(port_attr.max_mtu), port_attr.max_mtu);
542aa0a1e58SJeff Roberson printf("\t\t\tactive_mtu:\t\t%s (%d)\n",
543aa0a1e58SJeff Roberson mtu_str(port_attr.active_mtu), port_attr.active_mtu);
544aa0a1e58SJeff Roberson printf("\t\t\tsm_lid:\t\t\t%d\n", port_attr.sm_lid);
545aa0a1e58SJeff Roberson printf("\t\t\tport_lid:\t\t%d\n", port_attr.lid);
546aa0a1e58SJeff Roberson printf("\t\t\tport_lmc:\t\t0x%02x\n", port_attr.lmc);
547d6b92ffaSHans Petter Selasky printf("\t\t\tlink_layer:\t\t%s\n",
548d6b92ffaSHans Petter Selasky link_layer_str(port_attr.link_layer));
549aa0a1e58SJeff Roberson
550aa0a1e58SJeff Roberson if (verbose) {
551aa0a1e58SJeff Roberson printf("\t\t\tmax_msg_sz:\t\t0x%x\n", port_attr.max_msg_sz);
552aa0a1e58SJeff Roberson printf("\t\t\tport_cap_flags:\t\t0x%08x\n", port_attr.port_cap_flags);
553aa0a1e58SJeff Roberson printf("\t\t\tmax_vl_num:\t\t%s (%d)\n",
554aa0a1e58SJeff Roberson vl_str(port_attr.max_vl_num), port_attr.max_vl_num);
555aa0a1e58SJeff Roberson printf("\t\t\tbad_pkey_cntr:\t\t0x%x\n", port_attr.bad_pkey_cntr);
556aa0a1e58SJeff Roberson printf("\t\t\tqkey_viol_cntr:\t\t0x%x\n", port_attr.qkey_viol_cntr);
557aa0a1e58SJeff Roberson printf("\t\t\tsm_sl:\t\t\t%d\n", port_attr.sm_sl);
558aa0a1e58SJeff Roberson printf("\t\t\tpkey_tbl_len:\t\t%d\n", port_attr.pkey_tbl_len);
559aa0a1e58SJeff Roberson printf("\t\t\tgid_tbl_len:\t\t%d\n", port_attr.gid_tbl_len);
560aa0a1e58SJeff Roberson printf("\t\t\tsubnet_timeout:\t\t%d\n", port_attr.subnet_timeout);
561aa0a1e58SJeff Roberson printf("\t\t\tinit_type_reply:\t%d\n", port_attr.init_type_reply);
562aa0a1e58SJeff Roberson printf("\t\t\tactive_width:\t\t%sX (%d)\n",
563aa0a1e58SJeff Roberson width_str(port_attr.active_width), port_attr.active_width);
564aa0a1e58SJeff Roberson printf("\t\t\tactive_speed:\t\t%s (%d)\n",
565aa0a1e58SJeff Roberson speed_str(port_attr.active_speed), port_attr.active_speed);
566d6b92ffaSHans Petter Selasky if (ib_dev->transport_type == IBV_TRANSPORT_IB)
567aa0a1e58SJeff Roberson printf("\t\t\tphys_state:\t\t%s (%d)\n",
568aa0a1e58SJeff Roberson port_phy_state_str(port_attr.phys_state), port_attr.phys_state);
569aa0a1e58SJeff Roberson
570aa0a1e58SJeff Roberson if (print_all_port_gids(ctx, port, port_attr.gid_tbl_len))
571aa0a1e58SJeff Roberson goto cleanup;
572aa0a1e58SJeff Roberson }
573aa0a1e58SJeff Roberson printf("\n");
574aa0a1e58SJeff Roberson }
575aa0a1e58SJeff Roberson cleanup:
576aa0a1e58SJeff Roberson if (ctx)
577aa0a1e58SJeff Roberson if (ibv_close_device(ctx)) {
578aa0a1e58SJeff Roberson fprintf(stderr, "Failed to close device");
579aa0a1e58SJeff Roberson rc = 3;
580aa0a1e58SJeff Roberson }
581aa0a1e58SJeff Roberson return rc;
582aa0a1e58SJeff Roberson }
583aa0a1e58SJeff Roberson
usage(const char * argv0)584aa0a1e58SJeff Roberson static void usage(const char *argv0)
585aa0a1e58SJeff Roberson {
586aa0a1e58SJeff Roberson printf("Usage: %s print the ca attributes\n", argv0);
587aa0a1e58SJeff Roberson printf("\n");
588aa0a1e58SJeff Roberson printf("Options:\n");
589aa0a1e58SJeff Roberson printf(" -d, --ib-dev=<dev> use IB device <dev> (default first device found)\n");
590aa0a1e58SJeff Roberson printf(" -i, --ib-port=<port> use port <port> of IB device (default all ports)\n");
591aa0a1e58SJeff Roberson printf(" -l, --list print only the IB devices names\n");
592aa0a1e58SJeff Roberson printf(" -v, --verbose print all the attributes of the IB device(s)\n");
593aa0a1e58SJeff Roberson }
594aa0a1e58SJeff Roberson
main(int argc,char * argv[])595aa0a1e58SJeff Roberson int main(int argc, char *argv[])
596aa0a1e58SJeff Roberson {
597aa0a1e58SJeff Roberson char *ib_devname = NULL;
598aa0a1e58SJeff Roberson int ret = 0;
599aa0a1e58SJeff Roberson struct ibv_device **dev_list, **orig_dev_list;
600aa0a1e58SJeff Roberson int num_of_hcas;
601aa0a1e58SJeff Roberson int ib_port = 0;
602aa0a1e58SJeff Roberson
603aa0a1e58SJeff Roberson /* parse command line options */
604aa0a1e58SJeff Roberson while (1) {
605aa0a1e58SJeff Roberson int c;
606aa0a1e58SJeff Roberson static struct option long_options[] = {
607aa0a1e58SJeff Roberson { .name = "ib-dev", .has_arg = 1, .val = 'd' },
608aa0a1e58SJeff Roberson { .name = "ib-port", .has_arg = 1, .val = 'i' },
609aa0a1e58SJeff Roberson { .name = "list", .has_arg = 0, .val = 'l' },
610aa0a1e58SJeff Roberson { .name = "verbose", .has_arg = 0, .val = 'v' },
611d6b92ffaSHans Petter Selasky { }
612aa0a1e58SJeff Roberson };
613aa0a1e58SJeff Roberson
614aa0a1e58SJeff Roberson c = getopt_long(argc, argv, "d:i:lv", long_options, NULL);
615aa0a1e58SJeff Roberson if (c == -1)
616aa0a1e58SJeff Roberson break;
617aa0a1e58SJeff Roberson
618aa0a1e58SJeff Roberson switch (c) {
619aa0a1e58SJeff Roberson case 'd':
620aa0a1e58SJeff Roberson ib_devname = strdup(optarg);
621aa0a1e58SJeff Roberson break;
622aa0a1e58SJeff Roberson
623aa0a1e58SJeff Roberson case 'i':
624aa0a1e58SJeff Roberson ib_port = strtol(optarg, NULL, 0);
625d6b92ffaSHans Petter Selasky if (ib_port <= 0) {
626aa0a1e58SJeff Roberson usage(argv[0]);
627aa0a1e58SJeff Roberson return 1;
628aa0a1e58SJeff Roberson }
629aa0a1e58SJeff Roberson break;
630aa0a1e58SJeff Roberson
631aa0a1e58SJeff Roberson case 'v':
632aa0a1e58SJeff Roberson verbose = 1;
633aa0a1e58SJeff Roberson break;
634aa0a1e58SJeff Roberson
635aa0a1e58SJeff Roberson case 'l':
636aa0a1e58SJeff Roberson dev_list = orig_dev_list = ibv_get_device_list(&num_of_hcas);
637aa0a1e58SJeff Roberson if (!dev_list) {
638aa0a1e58SJeff Roberson perror("Failed to get IB devices list");
639aa0a1e58SJeff Roberson return -1;
640aa0a1e58SJeff Roberson }
641aa0a1e58SJeff Roberson
642aa0a1e58SJeff Roberson printf("%d HCA%s found:\n", num_of_hcas,
643aa0a1e58SJeff Roberson num_of_hcas != 1 ? "s" : "");
644aa0a1e58SJeff Roberson
645aa0a1e58SJeff Roberson while (*dev_list) {
646aa0a1e58SJeff Roberson printf("\t%s\n", ibv_get_device_name(*dev_list));
647aa0a1e58SJeff Roberson ++dev_list;
648aa0a1e58SJeff Roberson }
649aa0a1e58SJeff Roberson
650aa0a1e58SJeff Roberson printf("\n");
651aa0a1e58SJeff Roberson
652aa0a1e58SJeff Roberson ibv_free_device_list(orig_dev_list);
653aa0a1e58SJeff Roberson
654aa0a1e58SJeff Roberson return 0;
655aa0a1e58SJeff Roberson
656aa0a1e58SJeff Roberson default:
657aa0a1e58SJeff Roberson usage(argv[0]);
658aa0a1e58SJeff Roberson return -1;
659aa0a1e58SJeff Roberson }
660aa0a1e58SJeff Roberson }
661aa0a1e58SJeff Roberson
662aa0a1e58SJeff Roberson dev_list = orig_dev_list = ibv_get_device_list(NULL);
663aa0a1e58SJeff Roberson if (!dev_list) {
664aa0a1e58SJeff Roberson perror("Failed to get IB devices list");
665aa0a1e58SJeff Roberson return -1;
666aa0a1e58SJeff Roberson }
667aa0a1e58SJeff Roberson
668aa0a1e58SJeff Roberson if (ib_devname) {
669aa0a1e58SJeff Roberson while (*dev_list) {
670aa0a1e58SJeff Roberson if (!strcmp(ibv_get_device_name(*dev_list), ib_devname))
671aa0a1e58SJeff Roberson break;
672aa0a1e58SJeff Roberson ++dev_list;
673aa0a1e58SJeff Roberson }
674aa0a1e58SJeff Roberson
675aa0a1e58SJeff Roberson if (!*dev_list) {
676aa0a1e58SJeff Roberson fprintf(stderr, "IB device '%s' wasn't found\n", ib_devname);
677aa0a1e58SJeff Roberson return -1;
678aa0a1e58SJeff Roberson }
679aa0a1e58SJeff Roberson
680aa0a1e58SJeff Roberson ret |= print_hca_cap(*dev_list, ib_port);
681aa0a1e58SJeff Roberson } else {
682aa0a1e58SJeff Roberson if (!*dev_list) {
683aa0a1e58SJeff Roberson fprintf(stderr, "No IB devices found\n");
684aa0a1e58SJeff Roberson return -1;
685aa0a1e58SJeff Roberson }
686aa0a1e58SJeff Roberson
687aa0a1e58SJeff Roberson while (*dev_list) {
688aa0a1e58SJeff Roberson ret |= print_hca_cap(*dev_list, ib_port);
689aa0a1e58SJeff Roberson ++dev_list;
690aa0a1e58SJeff Roberson }
691aa0a1e58SJeff Roberson }
692aa0a1e58SJeff Roberson
693aa0a1e58SJeff Roberson if (ib_devname)
694aa0a1e58SJeff Roberson free(ib_devname);
695aa0a1e58SJeff Roberson
696aa0a1e58SJeff Roberson ibv_free_device_list(orig_dev_list);
697aa0a1e58SJeff Roberson
698aa0a1e58SJeff Roberson return ret;
699aa0a1e58SJeff Roberson }
700