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";
131*daceb336SHans 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";
147*daceb336SHans Petter Selasky case 64: return "50.0 Gbps";
148aa0a1e58SJeff Roberson default: return "invalid speed";
149aa0a1e58SJeff Roberson }
150aa0a1e58SJeff Roberson }
151aa0a1e58SJeff Roberson
vl_str(uint8_t vl_num)152aa0a1e58SJeff Roberson static const char *vl_str(uint8_t vl_num)
153aa0a1e58SJeff Roberson {
154aa0a1e58SJeff Roberson switch (vl_num) {
155aa0a1e58SJeff Roberson case 1: return "1";
156aa0a1e58SJeff Roberson case 2: return "2";
157aa0a1e58SJeff Roberson case 3: return "4";
158aa0a1e58SJeff Roberson case 4: return "8";
159aa0a1e58SJeff Roberson case 5: return "15";
160aa0a1e58SJeff Roberson default: return "invalid value";
161aa0a1e58SJeff Roberson }
162aa0a1e58SJeff Roberson }
163aa0a1e58SJeff Roberson
print_all_port_gids(struct ibv_context * ctx,uint8_t port_num,int tbl_len)164aa0a1e58SJeff Roberson static int print_all_port_gids(struct ibv_context *ctx, uint8_t port_num, int tbl_len)
165aa0a1e58SJeff Roberson {
166aa0a1e58SJeff Roberson union ibv_gid gid;
167aa0a1e58SJeff Roberson int rc = 0;
168aa0a1e58SJeff Roberson int i;
169aa0a1e58SJeff Roberson
170aa0a1e58SJeff Roberson for (i = 0; i < tbl_len; i++) {
171aa0a1e58SJeff Roberson rc = ibv_query_gid(ctx, port_num, i, &gid);
172aa0a1e58SJeff Roberson if (rc) {
173aa0a1e58SJeff Roberson fprintf(stderr, "Failed to query gid to port %d, index %d\n",
174aa0a1e58SJeff Roberson port_num, i);
175aa0a1e58SJeff Roberson return rc;
176aa0a1e58SJeff Roberson }
177aa0a1e58SJeff Roberson if (!null_gid(&gid))
178aa0a1e58SJeff 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",
179aa0a1e58SJeff Roberson i,
180aa0a1e58SJeff Roberson gid.raw[ 0], gid.raw[ 1],
181aa0a1e58SJeff Roberson gid.raw[ 2], gid.raw[ 3],
182aa0a1e58SJeff Roberson gid.raw[ 4], gid.raw[ 5],
183aa0a1e58SJeff Roberson gid.raw[ 6], gid.raw[ 7],
184aa0a1e58SJeff Roberson gid.raw[ 8], gid.raw[ 9],
185aa0a1e58SJeff Roberson gid.raw[10], gid.raw[11],
186aa0a1e58SJeff Roberson gid.raw[12], gid.raw[13],
187aa0a1e58SJeff Roberson gid.raw[14], gid.raw[15]);
188aa0a1e58SJeff Roberson }
189aa0a1e58SJeff Roberson return rc;
190aa0a1e58SJeff Roberson }
191aa0a1e58SJeff Roberson
link_layer_str(uint8_t link_layer)192aa0a1e58SJeff Roberson static const char *link_layer_str(uint8_t link_layer)
193aa0a1e58SJeff Roberson {
194aa0a1e58SJeff Roberson switch (link_layer) {
195aa0a1e58SJeff Roberson case IBV_LINK_LAYER_UNSPECIFIED:
196aa0a1e58SJeff Roberson case IBV_LINK_LAYER_INFINIBAND:
197d6b92ffaSHans Petter Selasky return "InfiniBand";
198aa0a1e58SJeff Roberson case IBV_LINK_LAYER_ETHERNET:
199aa0a1e58SJeff Roberson return "Ethernet";
200aa0a1e58SJeff Roberson default:
201aa0a1e58SJeff Roberson return "Unknown";
202aa0a1e58SJeff Roberson }
203aa0a1e58SJeff Roberson }
204aa0a1e58SJeff Roberson
print_device_cap_flags(uint32_t dev_cap_flags)205d6b92ffaSHans Petter Selasky static void print_device_cap_flags(uint32_t dev_cap_flags)
206d6b92ffaSHans Petter Selasky {
207d6b92ffaSHans Petter Selasky uint32_t unknown_flags = ~(IBV_DEVICE_RESIZE_MAX_WR |
208d6b92ffaSHans Petter Selasky IBV_DEVICE_BAD_PKEY_CNTR |
209d6b92ffaSHans Petter Selasky IBV_DEVICE_BAD_QKEY_CNTR |
210d6b92ffaSHans Petter Selasky IBV_DEVICE_RAW_MULTI |
211d6b92ffaSHans Petter Selasky IBV_DEVICE_AUTO_PATH_MIG |
212d6b92ffaSHans Petter Selasky IBV_DEVICE_CHANGE_PHY_PORT |
213d6b92ffaSHans Petter Selasky IBV_DEVICE_UD_AV_PORT_ENFORCE |
214d6b92ffaSHans Petter Selasky IBV_DEVICE_CURR_QP_STATE_MOD |
215d6b92ffaSHans Petter Selasky IBV_DEVICE_SHUTDOWN_PORT |
216d6b92ffaSHans Petter Selasky IBV_DEVICE_INIT_TYPE |
217d6b92ffaSHans Petter Selasky IBV_DEVICE_PORT_ACTIVE_EVENT |
218d6b92ffaSHans Petter Selasky IBV_DEVICE_SYS_IMAGE_GUID |
219d6b92ffaSHans Petter Selasky IBV_DEVICE_RC_RNR_NAK_GEN |
220d6b92ffaSHans Petter Selasky IBV_DEVICE_SRQ_RESIZE |
221d6b92ffaSHans Petter Selasky IBV_DEVICE_N_NOTIFY_CQ |
222d6b92ffaSHans Petter Selasky IBV_DEVICE_MEM_WINDOW |
223d6b92ffaSHans Petter Selasky IBV_DEVICE_UD_IP_CSUM |
224d6b92ffaSHans Petter Selasky IBV_DEVICE_XRC |
225d6b92ffaSHans Petter Selasky IBV_DEVICE_MEM_MGT_EXTENSIONS |
226d6b92ffaSHans Petter Selasky IBV_DEVICE_MEM_WINDOW_TYPE_2A |
227d6b92ffaSHans Petter Selasky IBV_DEVICE_MEM_WINDOW_TYPE_2B |
228d6b92ffaSHans Petter Selasky IBV_DEVICE_RC_IP_CSUM |
229d6b92ffaSHans Petter Selasky IBV_DEVICE_RAW_IP_CSUM |
230d6b92ffaSHans Petter Selasky IBV_DEVICE_MANAGED_FLOW_STEERING);
231d6b92ffaSHans Petter Selasky
232d6b92ffaSHans Petter Selasky if (dev_cap_flags & IBV_DEVICE_RESIZE_MAX_WR)
233d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tRESIZE_MAX_WR\n");
234d6b92ffaSHans Petter Selasky if (dev_cap_flags & IBV_DEVICE_BAD_PKEY_CNTR)
235d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tBAD_PKEY_CNTR\n");
236d6b92ffaSHans Petter Selasky if (dev_cap_flags & IBV_DEVICE_BAD_QKEY_CNTR)
237d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tBAD_QKEY_CNTR\n");
238d6b92ffaSHans Petter Selasky if (dev_cap_flags & IBV_DEVICE_RAW_MULTI)
239d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tRAW_MULTI\n");
240d6b92ffaSHans Petter Selasky if (dev_cap_flags & IBV_DEVICE_AUTO_PATH_MIG)
241d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tAUTO_PATH_MIG\n");
242d6b92ffaSHans Petter Selasky if (dev_cap_flags & IBV_DEVICE_CHANGE_PHY_PORT)
243d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tCHANGE_PHY_PORT\n");
244d6b92ffaSHans Petter Selasky if (dev_cap_flags & IBV_DEVICE_UD_AV_PORT_ENFORCE)
245d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tUD_AV_PORT_ENFORCE\n");
246d6b92ffaSHans Petter Selasky if (dev_cap_flags & IBV_DEVICE_CURR_QP_STATE_MOD)
247d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tCURR_QP_STATE_MOD\n");
248d6b92ffaSHans Petter Selasky if (dev_cap_flags & IBV_DEVICE_SHUTDOWN_PORT)
249d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tSHUTDOWN_PORT\n");
250d6b92ffaSHans Petter Selasky if (dev_cap_flags & IBV_DEVICE_INIT_TYPE)
251d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tINIT_TYPE\n");
252d6b92ffaSHans Petter Selasky if (dev_cap_flags & IBV_DEVICE_PORT_ACTIVE_EVENT)
253d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tPORT_ACTIVE_EVENT\n");
254d6b92ffaSHans Petter Selasky if (dev_cap_flags & IBV_DEVICE_SYS_IMAGE_GUID)
255d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tSYS_IMAGE_GUID\n");
256d6b92ffaSHans Petter Selasky if (dev_cap_flags & IBV_DEVICE_RC_RNR_NAK_GEN)
257d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tRC_RNR_NAK_GEN\n");
258d6b92ffaSHans Petter Selasky if (dev_cap_flags & IBV_DEVICE_SRQ_RESIZE)
259d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tSRQ_RESIZE\n");
260d6b92ffaSHans Petter Selasky if (dev_cap_flags & IBV_DEVICE_N_NOTIFY_CQ)
261d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tN_NOTIFY_CQ\n");
262d6b92ffaSHans Petter Selasky if (dev_cap_flags & IBV_DEVICE_MEM_WINDOW)
263d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tMEM_WINDOW\n");
264d6b92ffaSHans Petter Selasky if (dev_cap_flags & IBV_DEVICE_UD_IP_CSUM)
265d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tUD_IP_CSUM\n");
266d6b92ffaSHans Petter Selasky if (dev_cap_flags & IBV_DEVICE_XRC)
267d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tXRC\n");
268d6b92ffaSHans Petter Selasky if (dev_cap_flags & IBV_DEVICE_MEM_MGT_EXTENSIONS)
269d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tMEM_MGT_EXTENSIONS\n");
270d6b92ffaSHans Petter Selasky if (dev_cap_flags & IBV_DEVICE_MEM_WINDOW_TYPE_2A)
271d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tMEM_WINDOW_TYPE_2A\n");
272d6b92ffaSHans Petter Selasky if (dev_cap_flags & IBV_DEVICE_MEM_WINDOW_TYPE_2B)
273d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tMEM_WINDOW_TYPE_2B\n");
274d6b92ffaSHans Petter Selasky if (dev_cap_flags & IBV_DEVICE_RC_IP_CSUM)
275d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tRC_IP_CSUM\n");
276d6b92ffaSHans Petter Selasky if (dev_cap_flags & IBV_DEVICE_RAW_IP_CSUM)
277d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tRAW_IP_CSUM\n");
278d6b92ffaSHans Petter Selasky if (dev_cap_flags & IBV_DEVICE_MANAGED_FLOW_STEERING)
279d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tMANAGED_FLOW_STEERING\n");
280d6b92ffaSHans Petter Selasky if (dev_cap_flags & unknown_flags)
281d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tUnknown flags: 0x%" PRIX32 "\n",
282d6b92ffaSHans Petter Selasky dev_cap_flags & unknown_flags);
283d6b92ffaSHans Petter Selasky }
284d6b92ffaSHans Petter Selasky
print_odp_trans_caps(uint32_t trans)285d6b92ffaSHans Petter Selasky static void print_odp_trans_caps(uint32_t trans)
286d6b92ffaSHans Petter Selasky {
287d6b92ffaSHans Petter Selasky uint32_t unknown_transport_caps = ~(IBV_ODP_SUPPORT_SEND |
288d6b92ffaSHans Petter Selasky IBV_ODP_SUPPORT_RECV |
289d6b92ffaSHans Petter Selasky IBV_ODP_SUPPORT_WRITE |
290d6b92ffaSHans Petter Selasky IBV_ODP_SUPPORT_READ |
291d6b92ffaSHans Petter Selasky IBV_ODP_SUPPORT_ATOMIC);
292d6b92ffaSHans Petter Selasky
293d6b92ffaSHans Petter Selasky if (!trans) {
294d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tNO SUPPORT\n");
295d6b92ffaSHans Petter Selasky } else {
296d6b92ffaSHans Petter Selasky if (trans & IBV_ODP_SUPPORT_SEND)
297d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tSUPPORT_SEND\n");
298d6b92ffaSHans Petter Selasky if (trans & IBV_ODP_SUPPORT_RECV)
299d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tSUPPORT_RECV\n");
300d6b92ffaSHans Petter Selasky if (trans & IBV_ODP_SUPPORT_WRITE)
301d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tSUPPORT_WRITE\n");
302d6b92ffaSHans Petter Selasky if (trans & IBV_ODP_SUPPORT_READ)
303d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tSUPPORT_READ\n");
304d6b92ffaSHans Petter Selasky if (trans & IBV_ODP_SUPPORT_ATOMIC)
305d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tSUPPORT_ATOMIC\n");
306d6b92ffaSHans Petter Selasky if (trans & unknown_transport_caps)
307d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tUnknown flags: 0x%" PRIX32 "\n",
308d6b92ffaSHans Petter Selasky trans & unknown_transport_caps);
309d6b92ffaSHans Petter Selasky }
310d6b92ffaSHans Petter Selasky }
311d6b92ffaSHans Petter Selasky
print_odp_caps(const struct ibv_odp_caps * caps)312d6b92ffaSHans Petter Selasky static void print_odp_caps(const struct ibv_odp_caps *caps)
313d6b92ffaSHans Petter Selasky {
314d6b92ffaSHans Petter Selasky uint64_t unknown_general_caps = ~(IBV_ODP_SUPPORT);
315d6b92ffaSHans Petter Selasky
316d6b92ffaSHans Petter Selasky /* general odp caps */
317d6b92ffaSHans Petter Selasky printf("\tgeneral_odp_caps:\n");
318d6b92ffaSHans Petter Selasky if (caps->general_caps & IBV_ODP_SUPPORT)
319d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tODP_SUPPORT\n");
320d6b92ffaSHans Petter Selasky if (caps->general_caps & unknown_general_caps)
321d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tUnknown flags: 0x%" PRIX64 "\n",
322d6b92ffaSHans Petter Selasky caps->general_caps & unknown_general_caps);
323d6b92ffaSHans Petter Selasky
324d6b92ffaSHans Petter Selasky /* RC transport */
325d6b92ffaSHans Petter Selasky printf("\trc_odp_caps:\n");
326d6b92ffaSHans Petter Selasky print_odp_trans_caps(caps->per_transport_caps.rc_odp_caps);
327d6b92ffaSHans Petter Selasky printf("\tuc_odp_caps:\n");
328d6b92ffaSHans Petter Selasky print_odp_trans_caps(caps->per_transport_caps.uc_odp_caps);
329d6b92ffaSHans Petter Selasky printf("\tud_odp_caps:\n");
330d6b92ffaSHans Petter Selasky print_odp_trans_caps(caps->per_transport_caps.ud_odp_caps);
331d6b92ffaSHans Petter Selasky }
332d6b92ffaSHans Petter Selasky
print_device_cap_flags_ex(uint64_t device_cap_flags_ex)333d6b92ffaSHans Petter Selasky static void print_device_cap_flags_ex(uint64_t device_cap_flags_ex)
334d6b92ffaSHans Petter Selasky {
335d6b92ffaSHans Petter Selasky uint64_t ex_flags = device_cap_flags_ex & 0xffffffff00000000ULL;
336d6b92ffaSHans Petter Selasky uint64_t unknown_flags = ~(IBV_DEVICE_RAW_SCATTER_FCS);
337d6b92ffaSHans Petter Selasky
338d6b92ffaSHans Petter Selasky if (ex_flags & IBV_DEVICE_RAW_SCATTER_FCS)
339d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tRAW_SCATTER_FCS\n");
340d6b92ffaSHans Petter Selasky if (ex_flags & unknown_flags)
341d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tUnknown flags: 0x%" PRIX64 "\n",
342d6b92ffaSHans Petter Selasky ex_flags & unknown_flags);
343d6b92ffaSHans Petter Selasky }
344d6b92ffaSHans Petter Selasky
print_tso_caps(const struct ibv_tso_caps * caps)345d6b92ffaSHans Petter Selasky static void print_tso_caps(const struct ibv_tso_caps *caps)
346d6b92ffaSHans Petter Selasky {
347d6b92ffaSHans Petter Selasky uint32_t unknown_general_caps = ~(1 << IBV_QPT_RAW_PACKET |
348d6b92ffaSHans Petter Selasky 1 << IBV_QPT_UD);
349d6b92ffaSHans Petter Selasky printf("\ttso_caps:\n");
350d6b92ffaSHans Petter Selasky printf("\tmax_tso:\t\t\t%d\n", caps->max_tso);
351d6b92ffaSHans Petter Selasky
352d6b92ffaSHans Petter Selasky if (caps->max_tso) {
353d6b92ffaSHans Petter Selasky printf("\tsupported_qp:\n");
354d6b92ffaSHans Petter Selasky if (ibv_is_qpt_supported(caps->supported_qpts, IBV_QPT_RAW_PACKET))
355d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tSUPPORT_RAW_PACKET\n");
356d6b92ffaSHans Petter Selasky if (ibv_is_qpt_supported(caps->supported_qpts, IBV_QPT_UD))
357d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tSUPPORT_UD\n");
358d6b92ffaSHans Petter Selasky if (caps->supported_qpts & unknown_general_caps)
359d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tUnknown flags: 0x%" PRIX32 "\n",
360d6b92ffaSHans Petter Selasky caps->supported_qpts & unknown_general_caps);
361d6b92ffaSHans Petter Selasky }
362d6b92ffaSHans Petter Selasky }
363d6b92ffaSHans Petter Selasky
print_rss_caps(const struct ibv_rss_caps * caps)364d6b92ffaSHans Petter Selasky static void print_rss_caps(const struct ibv_rss_caps *caps)
365d6b92ffaSHans Petter Selasky {
366d6b92ffaSHans Petter Selasky uint32_t unknown_general_caps = ~(1 << IBV_QPT_RAW_PACKET |
367d6b92ffaSHans Petter Selasky 1 << IBV_QPT_UD);
368d6b92ffaSHans Petter Selasky printf("\trss_caps:\n");
369d6b92ffaSHans Petter Selasky printf("\t\tmax_rwq_indirection_tables:\t\t\t%u\n", caps->max_rwq_indirection_tables);
370d6b92ffaSHans Petter Selasky printf("\t\tmax_rwq_indirection_table_size:\t\t\t%u\n", caps->max_rwq_indirection_table_size);
371d6b92ffaSHans Petter Selasky printf("\t\trx_hash_function:\t\t\t\t0x%x\n", caps->rx_hash_function);
372d6b92ffaSHans Petter Selasky printf("\t\trx_hash_fields_mask:\t\t\t\t0x%" PRIX64 "\n", caps->rx_hash_fields_mask);
373d6b92ffaSHans Petter Selasky
374d6b92ffaSHans Petter Selasky if (caps->supported_qpts) {
375d6b92ffaSHans Petter Selasky printf("\t\tsupported_qp:\n");
376d6b92ffaSHans Petter Selasky if (ibv_is_qpt_supported(caps->supported_qpts, IBV_QPT_RAW_PACKET))
377d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tSUPPORT_RAW_PACKET\n");
378d6b92ffaSHans Petter Selasky if (ibv_is_qpt_supported(caps->supported_qpts, IBV_QPT_UD))
379d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tSUPPORT_UD\n");
380d6b92ffaSHans Petter Selasky if (caps->supported_qpts & unknown_general_caps)
381d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tUnknown flags: 0x%" PRIX32 "\n",
382d6b92ffaSHans Petter Selasky caps->supported_qpts & unknown_general_caps);
383d6b92ffaSHans Petter Selasky }
384d6b92ffaSHans Petter Selasky }
385d6b92ffaSHans Petter Selasky
print_packet_pacing_caps(const struct ibv_packet_pacing_caps * caps)386d6b92ffaSHans Petter Selasky static void print_packet_pacing_caps(const struct ibv_packet_pacing_caps *caps)
387d6b92ffaSHans Petter Selasky {
388d6b92ffaSHans Petter Selasky uint32_t unknown_general_caps = ~(1 << IBV_QPT_RAW_PACKET |
389d6b92ffaSHans Petter Selasky 1 << IBV_QPT_UD);
390d6b92ffaSHans Petter Selasky printf("\tpacket_pacing_caps:\n");
391d6b92ffaSHans Petter Selasky printf("\t\tqp_rate_limit_min:\t%ukbps\n", caps->qp_rate_limit_min);
392d6b92ffaSHans Petter Selasky printf("\t\tqp_rate_limit_max:\t%ukbps\n", caps->qp_rate_limit_max);
393d6b92ffaSHans Petter Selasky
394d6b92ffaSHans Petter Selasky if (caps->qp_rate_limit_max) {
395d6b92ffaSHans Petter Selasky printf("\t\tsupported_qp:\n");
396d6b92ffaSHans Petter Selasky if (ibv_is_qpt_supported(caps->supported_qpts, IBV_QPT_RAW_PACKET))
397d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tSUPPORT_RAW_PACKET\n");
398d6b92ffaSHans Petter Selasky if (ibv_is_qpt_supported(caps->supported_qpts, IBV_QPT_UD))
399d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tSUPPORT_UD\n");
400d6b92ffaSHans Petter Selasky if (caps->supported_qpts & unknown_general_caps)
401d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tUnknown flags: 0x%" PRIX32 "\n",
402d6b92ffaSHans Petter Selasky caps->supported_qpts & unknown_general_caps);
403d6b92ffaSHans Petter Selasky }
404d6b92ffaSHans Petter Selasky }
405d6b92ffaSHans Petter Selasky
print_raw_packet_caps(uint32_t raw_packet_caps)406d6b92ffaSHans Petter Selasky static void print_raw_packet_caps(uint32_t raw_packet_caps)
407d6b92ffaSHans Petter Selasky {
408d6b92ffaSHans Petter Selasky printf("\traw packet caps:\n");
409d6b92ffaSHans Petter Selasky if (raw_packet_caps & IBV_RAW_PACKET_CAP_CVLAN_STRIPPING)
410d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tC-VLAN stripping offload\n");
411d6b92ffaSHans Petter Selasky if (raw_packet_caps & IBV_RAW_PACKET_CAP_SCATTER_FCS)
412d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tScatter FCS offload\n");
413d6b92ffaSHans Petter Selasky if (raw_packet_caps & IBV_RAW_PACKET_CAP_IP_CSUM)
414d6b92ffaSHans Petter Selasky printf("\t\t\t\t\tIP csum offload\n");
415d6b92ffaSHans Petter Selasky }
416d6b92ffaSHans Petter Selasky
print_hca_cap(struct ibv_device * ib_dev,uint8_t ib_port)417aa0a1e58SJeff Roberson static int print_hca_cap(struct ibv_device *ib_dev, uint8_t ib_port)
418aa0a1e58SJeff Roberson {
419aa0a1e58SJeff Roberson struct ibv_context *ctx;
420d6b92ffaSHans Petter Selasky struct ibv_device_attr_ex device_attr;
421aa0a1e58SJeff Roberson struct ibv_port_attr port_attr;
422aa0a1e58SJeff Roberson int rc = 0;
423aa0a1e58SJeff Roberson uint8_t port;
424aa0a1e58SJeff Roberson char buf[256];
425aa0a1e58SJeff Roberson
426aa0a1e58SJeff Roberson ctx = ibv_open_device(ib_dev);
427aa0a1e58SJeff Roberson if (!ctx) {
428aa0a1e58SJeff Roberson fprintf(stderr, "Failed to open device\n");
429aa0a1e58SJeff Roberson rc = 1;
430aa0a1e58SJeff Roberson goto cleanup;
431aa0a1e58SJeff Roberson }
432d6b92ffaSHans Petter Selasky if (ibv_query_device_ex(ctx, NULL, &device_attr)) {
433d6b92ffaSHans Petter Selasky fprintf(stderr, "Failed to query device props\n");
434aa0a1e58SJeff Roberson rc = 2;
435aa0a1e58SJeff Roberson goto cleanup;
436aa0a1e58SJeff Roberson }
437d6b92ffaSHans Petter Selasky if (ib_port && ib_port > device_attr.orig_attr.phys_port_cnt) {
438d6b92ffaSHans Petter Selasky fprintf(stderr, "Invalid port requested for device\n");
439d6b92ffaSHans Petter Selasky /* rc = 3 is taken by failure to clean up */
440d6b92ffaSHans Petter Selasky rc = 4;
441d6b92ffaSHans Petter Selasky goto cleanup;
442d6b92ffaSHans Petter Selasky }
443aa0a1e58SJeff Roberson
444aa0a1e58SJeff Roberson printf("hca_id:\t%s\n", ibv_get_device_name(ib_dev));
445aa0a1e58SJeff Roberson printf("\ttransport:\t\t\t%s (%d)\n",
446aa0a1e58SJeff Roberson transport_str(ib_dev->transport_type), ib_dev->transport_type);
447d6b92ffaSHans Petter Selasky if (strlen(device_attr.orig_attr.fw_ver))
448d6b92ffaSHans Petter Selasky printf("\tfw_ver:\t\t\t\t%s\n", device_attr.orig_attr.fw_ver);
449d6b92ffaSHans Petter Selasky printf("\tnode_guid:\t\t\t%s\n", guid_str(device_attr.orig_attr.node_guid, buf));
450d6b92ffaSHans Petter Selasky printf("\tsys_image_guid:\t\t\t%s\n", guid_str(device_attr.orig_attr.sys_image_guid, buf));
451d6b92ffaSHans Petter Selasky printf("\tvendor_id:\t\t\t0x%04x\n", device_attr.orig_attr.vendor_id);
452d6b92ffaSHans Petter Selasky printf("\tvendor_part_id:\t\t\t%d\n", device_attr.orig_attr.vendor_part_id);
453d6b92ffaSHans Petter Selasky printf("\thw_ver:\t\t\t\t0x%X\n", device_attr.orig_attr.hw_ver);
454aa0a1e58SJeff Roberson
455aa0a1e58SJeff Roberson if (ibv_read_sysfs_file(ib_dev->ibdev_path, "board_id", buf, sizeof buf) > 0)
456aa0a1e58SJeff Roberson printf("\tboard_id:\t\t\t%s\n", buf);
457aa0a1e58SJeff Roberson
458d6b92ffaSHans Petter Selasky printf("\tphys_port_cnt:\t\t\t%d\n", device_attr.orig_attr.phys_port_cnt);
459aa0a1e58SJeff Roberson
460aa0a1e58SJeff Roberson if (verbose) {
461aa0a1e58SJeff Roberson printf("\tmax_mr_size:\t\t\t0x%llx\n",
462d6b92ffaSHans Petter Selasky (unsigned long long) device_attr.orig_attr.max_mr_size);
463aa0a1e58SJeff Roberson printf("\tpage_size_cap:\t\t\t0x%llx\n",
464d6b92ffaSHans Petter Selasky (unsigned long long) device_attr.orig_attr.page_size_cap);
465d6b92ffaSHans Petter Selasky printf("\tmax_qp:\t\t\t\t%d\n", device_attr.orig_attr.max_qp);
466d6b92ffaSHans Petter Selasky printf("\tmax_qp_wr:\t\t\t%d\n", device_attr.orig_attr.max_qp_wr);
467d6b92ffaSHans Petter Selasky printf("\tdevice_cap_flags:\t\t0x%08x\n", device_attr.orig_attr.device_cap_flags);
468d6b92ffaSHans Petter Selasky print_device_cap_flags(device_attr.orig_attr.device_cap_flags);
469d6b92ffaSHans Petter Selasky printf("\tmax_sge:\t\t\t%d\n", device_attr.orig_attr.max_sge);
470d6b92ffaSHans Petter Selasky printf("\tmax_sge_rd:\t\t\t%d\n", device_attr.orig_attr.max_sge_rd);
471d6b92ffaSHans Petter Selasky printf("\tmax_cq:\t\t\t\t%d\n", device_attr.orig_attr.max_cq);
472d6b92ffaSHans Petter Selasky printf("\tmax_cqe:\t\t\t%d\n", device_attr.orig_attr.max_cqe);
473d6b92ffaSHans Petter Selasky printf("\tmax_mr:\t\t\t\t%d\n", device_attr.orig_attr.max_mr);
474d6b92ffaSHans Petter Selasky printf("\tmax_pd:\t\t\t\t%d\n", device_attr.orig_attr.max_pd);
475d6b92ffaSHans Petter Selasky printf("\tmax_qp_rd_atom:\t\t\t%d\n", device_attr.orig_attr.max_qp_rd_atom);
476d6b92ffaSHans Petter Selasky printf("\tmax_ee_rd_atom:\t\t\t%d\n", device_attr.orig_attr.max_ee_rd_atom);
477d6b92ffaSHans Petter Selasky printf("\tmax_res_rd_atom:\t\t%d\n", device_attr.orig_attr.max_res_rd_atom);
478d6b92ffaSHans Petter Selasky printf("\tmax_qp_init_rd_atom:\t\t%d\n", device_attr.orig_attr.max_qp_init_rd_atom);
479d6b92ffaSHans Petter Selasky printf("\tmax_ee_init_rd_atom:\t\t%d\n", device_attr.orig_attr.max_ee_init_rd_atom);
480aa0a1e58SJeff Roberson printf("\tatomic_cap:\t\t\t%s (%d)\n",
481d6b92ffaSHans Petter Selasky atomic_cap_str(device_attr.orig_attr.atomic_cap), device_attr.orig_attr.atomic_cap);
482d6b92ffaSHans Petter Selasky printf("\tmax_ee:\t\t\t\t%d\n", device_attr.orig_attr.max_ee);
483d6b92ffaSHans Petter Selasky printf("\tmax_rdd:\t\t\t%d\n", device_attr.orig_attr.max_rdd);
484d6b92ffaSHans Petter Selasky printf("\tmax_mw:\t\t\t\t%d\n", device_attr.orig_attr.max_mw);
485d6b92ffaSHans Petter Selasky printf("\tmax_raw_ipv6_qp:\t\t%d\n", device_attr.orig_attr.max_raw_ipv6_qp);
486d6b92ffaSHans Petter Selasky printf("\tmax_raw_ethy_qp:\t\t%d\n", device_attr.orig_attr.max_raw_ethy_qp);
487d6b92ffaSHans Petter Selasky printf("\tmax_mcast_grp:\t\t\t%d\n", device_attr.orig_attr.max_mcast_grp);
488d6b92ffaSHans Petter Selasky printf("\tmax_mcast_qp_attach:\t\t%d\n", device_attr.orig_attr.max_mcast_qp_attach);
489aa0a1e58SJeff Roberson printf("\tmax_total_mcast_qp_attach:\t%d\n",
490d6b92ffaSHans Petter Selasky device_attr.orig_attr.max_total_mcast_qp_attach);
491d6b92ffaSHans Petter Selasky printf("\tmax_ah:\t\t\t\t%d\n", device_attr.orig_attr.max_ah);
492d6b92ffaSHans Petter Selasky printf("\tmax_fmr:\t\t\t%d\n", device_attr.orig_attr.max_fmr);
493d6b92ffaSHans Petter Selasky if (device_attr.orig_attr.max_fmr)
494d6b92ffaSHans Petter Selasky printf("\tmax_map_per_fmr:\t\t%d\n", device_attr.orig_attr.max_map_per_fmr);
495d6b92ffaSHans Petter Selasky printf("\tmax_srq:\t\t\t%d\n", device_attr.orig_attr.max_srq);
496d6b92ffaSHans Petter Selasky if (device_attr.orig_attr.max_srq) {
497d6b92ffaSHans Petter Selasky printf("\tmax_srq_wr:\t\t\t%d\n", device_attr.orig_attr.max_srq_wr);
498d6b92ffaSHans Petter Selasky printf("\tmax_srq_sge:\t\t\t%d\n", device_attr.orig_attr.max_srq_sge);
499aa0a1e58SJeff Roberson }
500d6b92ffaSHans Petter Selasky printf("\tmax_pkeys:\t\t\t%d\n", device_attr.orig_attr.max_pkeys);
501d6b92ffaSHans Petter Selasky printf("\tlocal_ca_ack_delay:\t\t%d\n", device_attr.orig_attr.local_ca_ack_delay);
502d6b92ffaSHans Petter Selasky
503d6b92ffaSHans Petter Selasky print_odp_caps(&device_attr.odp_caps);
504d6b92ffaSHans Petter Selasky if (device_attr.completion_timestamp_mask)
505d6b92ffaSHans Petter Selasky printf("\tcompletion timestamp_mask:\t\t\t0x%016" PRIx64 "\n",
506d6b92ffaSHans Petter Selasky device_attr.completion_timestamp_mask);
507d6b92ffaSHans Petter Selasky else
508d6b92ffaSHans Petter Selasky printf("\tcompletion_timestamp_mask not supported\n");
509d6b92ffaSHans Petter Selasky
510d6b92ffaSHans Petter Selasky if (device_attr.hca_core_clock)
511d6b92ffaSHans Petter Selasky printf("\thca_core_clock:\t\t\t%" PRIu64 "kHZ\n", device_attr.hca_core_clock);
512d6b92ffaSHans Petter Selasky else
513d6b92ffaSHans Petter Selasky printf("\tcore clock not supported\n");
514d6b92ffaSHans Petter Selasky
515d6b92ffaSHans Petter Selasky if (device_attr.raw_packet_caps)
516d6b92ffaSHans Petter Selasky print_raw_packet_caps(device_attr.raw_packet_caps);
517d6b92ffaSHans Petter Selasky
518d6b92ffaSHans Petter Selasky printf("\tdevice_cap_flags_ex:\t\t0x%" PRIX64 "\n", device_attr.device_cap_flags_ex);
519d6b92ffaSHans Petter Selasky print_device_cap_flags_ex(device_attr.device_cap_flags_ex);
520d6b92ffaSHans Petter Selasky print_tso_caps(&device_attr.tso_caps);
521d6b92ffaSHans Petter Selasky print_rss_caps(&device_attr.rss_caps);
522d6b92ffaSHans Petter Selasky printf("\tmax_wq_type_rq:\t\t\t%u\n", device_attr.max_wq_type_rq);
523d6b92ffaSHans Petter Selasky print_packet_pacing_caps(&device_attr.packet_pacing_caps);
524aa0a1e58SJeff Roberson }
525aa0a1e58SJeff Roberson
526d6b92ffaSHans Petter Selasky for (port = 1; port <= device_attr.orig_attr.phys_port_cnt; ++port) {
527aa0a1e58SJeff Roberson /* if in the command line the user didn't ask for info about this port */
528aa0a1e58SJeff Roberson if ((ib_port) && (port != ib_port))
529aa0a1e58SJeff Roberson continue;
530aa0a1e58SJeff Roberson
531aa0a1e58SJeff Roberson rc = ibv_query_port(ctx, port, &port_attr);
532aa0a1e58SJeff Roberson if (rc) {
533aa0a1e58SJeff Roberson fprintf(stderr, "Failed to query port %u props\n", port);
534aa0a1e58SJeff Roberson goto cleanup;
535aa0a1e58SJeff Roberson }
536aa0a1e58SJeff Roberson printf("\t\tport:\t%d\n", port);
537aa0a1e58SJeff Roberson printf("\t\t\tstate:\t\t\t%s (%d)\n",
538aa0a1e58SJeff Roberson port_state_str(port_attr.state), port_attr.state);
539aa0a1e58SJeff Roberson printf("\t\t\tmax_mtu:\t\t%s (%d)\n",
540aa0a1e58SJeff Roberson mtu_str(port_attr.max_mtu), port_attr.max_mtu);
541aa0a1e58SJeff Roberson printf("\t\t\tactive_mtu:\t\t%s (%d)\n",
542aa0a1e58SJeff Roberson mtu_str(port_attr.active_mtu), port_attr.active_mtu);
543aa0a1e58SJeff Roberson printf("\t\t\tsm_lid:\t\t\t%d\n", port_attr.sm_lid);
544aa0a1e58SJeff Roberson printf("\t\t\tport_lid:\t\t%d\n", port_attr.lid);
545aa0a1e58SJeff Roberson printf("\t\t\tport_lmc:\t\t0x%02x\n", port_attr.lmc);
546d6b92ffaSHans Petter Selasky printf("\t\t\tlink_layer:\t\t%s\n",
547d6b92ffaSHans Petter Selasky link_layer_str(port_attr.link_layer));
548aa0a1e58SJeff Roberson
549aa0a1e58SJeff Roberson if (verbose) {
550aa0a1e58SJeff Roberson printf("\t\t\tmax_msg_sz:\t\t0x%x\n", port_attr.max_msg_sz);
551aa0a1e58SJeff Roberson printf("\t\t\tport_cap_flags:\t\t0x%08x\n", port_attr.port_cap_flags);
552aa0a1e58SJeff Roberson printf("\t\t\tmax_vl_num:\t\t%s (%d)\n",
553aa0a1e58SJeff Roberson vl_str(port_attr.max_vl_num), port_attr.max_vl_num);
554aa0a1e58SJeff Roberson printf("\t\t\tbad_pkey_cntr:\t\t0x%x\n", port_attr.bad_pkey_cntr);
555aa0a1e58SJeff Roberson printf("\t\t\tqkey_viol_cntr:\t\t0x%x\n", port_attr.qkey_viol_cntr);
556aa0a1e58SJeff Roberson printf("\t\t\tsm_sl:\t\t\t%d\n", port_attr.sm_sl);
557aa0a1e58SJeff Roberson printf("\t\t\tpkey_tbl_len:\t\t%d\n", port_attr.pkey_tbl_len);
558aa0a1e58SJeff Roberson printf("\t\t\tgid_tbl_len:\t\t%d\n", port_attr.gid_tbl_len);
559aa0a1e58SJeff Roberson printf("\t\t\tsubnet_timeout:\t\t%d\n", port_attr.subnet_timeout);
560aa0a1e58SJeff Roberson printf("\t\t\tinit_type_reply:\t%d\n", port_attr.init_type_reply);
561aa0a1e58SJeff Roberson printf("\t\t\tactive_width:\t\t%sX (%d)\n",
562aa0a1e58SJeff Roberson width_str(port_attr.active_width), port_attr.active_width);
563aa0a1e58SJeff Roberson printf("\t\t\tactive_speed:\t\t%s (%d)\n",
564aa0a1e58SJeff Roberson speed_str(port_attr.active_speed), port_attr.active_speed);
565d6b92ffaSHans Petter Selasky if (ib_dev->transport_type == IBV_TRANSPORT_IB)
566aa0a1e58SJeff Roberson printf("\t\t\tphys_state:\t\t%s (%d)\n",
567aa0a1e58SJeff Roberson port_phy_state_str(port_attr.phys_state), port_attr.phys_state);
568aa0a1e58SJeff Roberson
569aa0a1e58SJeff Roberson if (print_all_port_gids(ctx, port, port_attr.gid_tbl_len))
570aa0a1e58SJeff Roberson goto cleanup;
571aa0a1e58SJeff Roberson }
572aa0a1e58SJeff Roberson printf("\n");
573aa0a1e58SJeff Roberson }
574aa0a1e58SJeff Roberson cleanup:
575aa0a1e58SJeff Roberson if (ctx)
576aa0a1e58SJeff Roberson if (ibv_close_device(ctx)) {
577aa0a1e58SJeff Roberson fprintf(stderr, "Failed to close device");
578aa0a1e58SJeff Roberson rc = 3;
579aa0a1e58SJeff Roberson }
580aa0a1e58SJeff Roberson return rc;
581aa0a1e58SJeff Roberson }
582aa0a1e58SJeff Roberson
usage(const char * argv0)583aa0a1e58SJeff Roberson static void usage(const char *argv0)
584aa0a1e58SJeff Roberson {
585aa0a1e58SJeff Roberson printf("Usage: %s print the ca attributes\n", argv0);
586aa0a1e58SJeff Roberson printf("\n");
587aa0a1e58SJeff Roberson printf("Options:\n");
588aa0a1e58SJeff Roberson printf(" -d, --ib-dev=<dev> use IB device <dev> (default first device found)\n");
589aa0a1e58SJeff Roberson printf(" -i, --ib-port=<port> use port <port> of IB device (default all ports)\n");
590aa0a1e58SJeff Roberson printf(" -l, --list print only the IB devices names\n");
591aa0a1e58SJeff Roberson printf(" -v, --verbose print all the attributes of the IB device(s)\n");
592aa0a1e58SJeff Roberson }
593aa0a1e58SJeff Roberson
main(int argc,char * argv[])594aa0a1e58SJeff Roberson int main(int argc, char *argv[])
595aa0a1e58SJeff Roberson {
596aa0a1e58SJeff Roberson char *ib_devname = NULL;
597aa0a1e58SJeff Roberson int ret = 0;
598aa0a1e58SJeff Roberson struct ibv_device **dev_list, **orig_dev_list;
599aa0a1e58SJeff Roberson int num_of_hcas;
600aa0a1e58SJeff Roberson int ib_port = 0;
601aa0a1e58SJeff Roberson
602aa0a1e58SJeff Roberson /* parse command line options */
603aa0a1e58SJeff Roberson while (1) {
604aa0a1e58SJeff Roberson int c;
605aa0a1e58SJeff Roberson static struct option long_options[] = {
606aa0a1e58SJeff Roberson { .name = "ib-dev", .has_arg = 1, .val = 'd' },
607aa0a1e58SJeff Roberson { .name = "ib-port", .has_arg = 1, .val = 'i' },
608aa0a1e58SJeff Roberson { .name = "list", .has_arg = 0, .val = 'l' },
609aa0a1e58SJeff Roberson { .name = "verbose", .has_arg = 0, .val = 'v' },
610d6b92ffaSHans Petter Selasky { }
611aa0a1e58SJeff Roberson };
612aa0a1e58SJeff Roberson
613aa0a1e58SJeff Roberson c = getopt_long(argc, argv, "d:i:lv", long_options, NULL);
614aa0a1e58SJeff Roberson if (c == -1)
615aa0a1e58SJeff Roberson break;
616aa0a1e58SJeff Roberson
617aa0a1e58SJeff Roberson switch (c) {
618aa0a1e58SJeff Roberson case 'd':
619aa0a1e58SJeff Roberson ib_devname = strdup(optarg);
620aa0a1e58SJeff Roberson break;
621aa0a1e58SJeff Roberson
622aa0a1e58SJeff Roberson case 'i':
623aa0a1e58SJeff Roberson ib_port = strtol(optarg, NULL, 0);
624d6b92ffaSHans Petter Selasky if (ib_port <= 0) {
625aa0a1e58SJeff Roberson usage(argv[0]);
626aa0a1e58SJeff Roberson return 1;
627aa0a1e58SJeff Roberson }
628aa0a1e58SJeff Roberson break;
629aa0a1e58SJeff Roberson
630aa0a1e58SJeff Roberson case 'v':
631aa0a1e58SJeff Roberson verbose = 1;
632aa0a1e58SJeff Roberson break;
633aa0a1e58SJeff Roberson
634aa0a1e58SJeff Roberson case 'l':
635aa0a1e58SJeff Roberson dev_list = orig_dev_list = ibv_get_device_list(&num_of_hcas);
636aa0a1e58SJeff Roberson if (!dev_list) {
637aa0a1e58SJeff Roberson perror("Failed to get IB devices list");
638aa0a1e58SJeff Roberson return -1;
639aa0a1e58SJeff Roberson }
640aa0a1e58SJeff Roberson
641aa0a1e58SJeff Roberson printf("%d HCA%s found:\n", num_of_hcas,
642aa0a1e58SJeff Roberson num_of_hcas != 1 ? "s" : "");
643aa0a1e58SJeff Roberson
644aa0a1e58SJeff Roberson while (*dev_list) {
645aa0a1e58SJeff Roberson printf("\t%s\n", ibv_get_device_name(*dev_list));
646aa0a1e58SJeff Roberson ++dev_list;
647aa0a1e58SJeff Roberson }
648aa0a1e58SJeff Roberson
649aa0a1e58SJeff Roberson printf("\n");
650aa0a1e58SJeff Roberson
651aa0a1e58SJeff Roberson ibv_free_device_list(orig_dev_list);
652aa0a1e58SJeff Roberson
653aa0a1e58SJeff Roberson return 0;
654aa0a1e58SJeff Roberson
655aa0a1e58SJeff Roberson default:
656aa0a1e58SJeff Roberson usage(argv[0]);
657aa0a1e58SJeff Roberson return -1;
658aa0a1e58SJeff Roberson }
659aa0a1e58SJeff Roberson }
660aa0a1e58SJeff Roberson
661aa0a1e58SJeff Roberson dev_list = orig_dev_list = ibv_get_device_list(NULL);
662aa0a1e58SJeff Roberson if (!dev_list) {
663aa0a1e58SJeff Roberson perror("Failed to get IB devices list");
664aa0a1e58SJeff Roberson return -1;
665aa0a1e58SJeff Roberson }
666aa0a1e58SJeff Roberson
667aa0a1e58SJeff Roberson if (ib_devname) {
668aa0a1e58SJeff Roberson while (*dev_list) {
669aa0a1e58SJeff Roberson if (!strcmp(ibv_get_device_name(*dev_list), ib_devname))
670aa0a1e58SJeff Roberson break;
671aa0a1e58SJeff Roberson ++dev_list;
672aa0a1e58SJeff Roberson }
673aa0a1e58SJeff Roberson
674aa0a1e58SJeff Roberson if (!*dev_list) {
675aa0a1e58SJeff Roberson fprintf(stderr, "IB device '%s' wasn't found\n", ib_devname);
676aa0a1e58SJeff Roberson return -1;
677aa0a1e58SJeff Roberson }
678aa0a1e58SJeff Roberson
679aa0a1e58SJeff Roberson ret |= print_hca_cap(*dev_list, ib_port);
680aa0a1e58SJeff Roberson } else {
681aa0a1e58SJeff Roberson if (!*dev_list) {
682aa0a1e58SJeff Roberson fprintf(stderr, "No IB devices found\n");
683aa0a1e58SJeff Roberson return -1;
684aa0a1e58SJeff Roberson }
685aa0a1e58SJeff Roberson
686aa0a1e58SJeff Roberson while (*dev_list) {
687aa0a1e58SJeff Roberson ret |= print_hca_cap(*dev_list, ib_port);
688aa0a1e58SJeff Roberson ++dev_list;
689aa0a1e58SJeff Roberson }
690aa0a1e58SJeff Roberson }
691aa0a1e58SJeff Roberson
692aa0a1e58SJeff Roberson if (ib_devname)
693aa0a1e58SJeff Roberson free(ib_devname);
694aa0a1e58SJeff Roberson
695aa0a1e58SJeff Roberson ibv_free_device_list(orig_dev_list);
696aa0a1e58SJeff Roberson
697aa0a1e58SJeff Roberson return ret;
698aa0a1e58SJeff Roberson }
699