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