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