Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

IB/core: Display extended counter set if available

Check if the extended counters are available and if so
create the proper extended and additional counters.

Signed-off-by: Christoph Lameter <cl@linux.com>
Reviewed-by: Ira Weiny <ira.weiny@intel.com>
Reviewed-by: Hal Rosenstock <hal@mellanox.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>

authored by

Christoph Lameter and committed by
Doug Ledford
145d9c54 b2788ce5

+108 -3
+107 -3
drivers/infiniband/core/sysfs.c
··· 57 57 struct attribute_group gid_group; 58 58 struct attribute_group pkey_group; 59 59 u8 port_num; 60 + struct attribute_group *pma_table; 60 61 }; 61 62 62 63 struct port_attribute { ··· 402 401 .attr_id = IB_PMA_PORT_COUNTERS , \ 403 402 } 404 403 404 + #define PORT_PMA_ATTR_EXT(_name, _width, _offset) \ 405 + struct port_table_attribute port_pma_attr_ext_##_name = { \ 406 + .attr = __ATTR(_name, S_IRUGO, show_pma_counter, NULL), \ 407 + .index = (_offset) | ((_width) << 16), \ 408 + .attr_id = IB_PMA_PORT_COUNTERS_EXT , \ 409 + } 410 + 405 411 /* 406 412 * Get a Perfmgmt MAD block of data. 407 413 * Returns error code or the number of bytes retrieved. ··· 489 481 ret = sprintf(buf, "%u\n", 490 482 be32_to_cpup((__be32 *)data)); 491 483 break; 484 + case 64: 485 + ret = sprintf(buf, "%llu\n", 486 + be64_to_cpup((__be64 *)data)); 487 + break; 488 + 492 489 default: 493 490 ret = 0; 494 491 } ··· 518 505 static PORT_PMA_ATTR(port_xmit_packets , 14, 32, 256); 519 506 static PORT_PMA_ATTR(port_rcv_packets , 15, 32, 288); 520 507 508 + /* 509 + * Counters added by extended set 510 + */ 511 + static PORT_PMA_ATTR_EXT(port_xmit_data , 64, 64); 512 + static PORT_PMA_ATTR_EXT(port_rcv_data , 64, 128); 513 + static PORT_PMA_ATTR_EXT(port_xmit_packets , 64, 192); 514 + static PORT_PMA_ATTR_EXT(port_rcv_packets , 64, 256); 515 + static PORT_PMA_ATTR_EXT(unicast_xmit_packets , 64, 320); 516 + static PORT_PMA_ATTR_EXT(unicast_rcv_packets , 64, 384); 517 + static PORT_PMA_ATTR_EXT(multicast_xmit_packets , 64, 448); 518 + static PORT_PMA_ATTR_EXT(multicast_rcv_packets , 64, 512); 519 + 521 520 static struct attribute *pma_attrs[] = { 522 521 &port_pma_attr_symbol_error.attr.attr, 523 522 &port_pma_attr_link_error_recovery.attr.attr, ··· 550 525 NULL 551 526 }; 552 527 528 + static struct attribute *pma_attrs_ext[] = { 529 + &port_pma_attr_symbol_error.attr.attr, 530 + &port_pma_attr_link_error_recovery.attr.attr, 531 + &port_pma_attr_link_downed.attr.attr, 532 + &port_pma_attr_port_rcv_errors.attr.attr, 533 + &port_pma_attr_port_rcv_remote_physical_errors.attr.attr, 534 + &port_pma_attr_port_rcv_switch_relay_errors.attr.attr, 535 + &port_pma_attr_port_xmit_discards.attr.attr, 536 + &port_pma_attr_port_xmit_constraint_errors.attr.attr, 537 + &port_pma_attr_port_rcv_constraint_errors.attr.attr, 538 + &port_pma_attr_local_link_integrity_errors.attr.attr, 539 + &port_pma_attr_excessive_buffer_overrun_errors.attr.attr, 540 + &port_pma_attr_VL15_dropped.attr.attr, 541 + &port_pma_attr_ext_port_xmit_data.attr.attr, 542 + &port_pma_attr_ext_port_rcv_data.attr.attr, 543 + &port_pma_attr_ext_port_xmit_packets.attr.attr, 544 + &port_pma_attr_ext_port_rcv_packets.attr.attr, 545 + &port_pma_attr_ext_unicast_rcv_packets.attr.attr, 546 + &port_pma_attr_ext_unicast_xmit_packets.attr.attr, 547 + &port_pma_attr_ext_multicast_rcv_packets.attr.attr, 548 + &port_pma_attr_ext_multicast_xmit_packets.attr.attr, 549 + NULL 550 + }; 551 + 552 + static struct attribute *pma_attrs_noietf[] = { 553 + &port_pma_attr_symbol_error.attr.attr, 554 + &port_pma_attr_link_error_recovery.attr.attr, 555 + &port_pma_attr_link_downed.attr.attr, 556 + &port_pma_attr_port_rcv_errors.attr.attr, 557 + &port_pma_attr_port_rcv_remote_physical_errors.attr.attr, 558 + &port_pma_attr_port_rcv_switch_relay_errors.attr.attr, 559 + &port_pma_attr_port_xmit_discards.attr.attr, 560 + &port_pma_attr_port_xmit_constraint_errors.attr.attr, 561 + &port_pma_attr_port_rcv_constraint_errors.attr.attr, 562 + &port_pma_attr_local_link_integrity_errors.attr.attr, 563 + &port_pma_attr_excessive_buffer_overrun_errors.attr.attr, 564 + &port_pma_attr_VL15_dropped.attr.attr, 565 + &port_pma_attr_ext_port_xmit_data.attr.attr, 566 + &port_pma_attr_ext_port_rcv_data.attr.attr, 567 + &port_pma_attr_ext_port_xmit_packets.attr.attr, 568 + &port_pma_attr_ext_port_rcv_packets.attr.attr, 569 + NULL 570 + }; 571 + 553 572 static struct attribute_group pma_group = { 554 573 .name = "counters", 555 574 .attrs = pma_attrs 575 + }; 576 + 577 + static struct attribute_group pma_group_ext = { 578 + .name = "counters", 579 + .attrs = pma_attrs_ext 580 + }; 581 + 582 + static struct attribute_group pma_group_noietf = { 583 + .name = "counters", 584 + .attrs = pma_attrs_noietf 556 585 }; 557 586 558 587 static void ib_port_release(struct kobject *kobj) ··· 710 631 return NULL; 711 632 } 712 633 634 + /* 635 + * Figure out which counter table to use depending on 636 + * the device capabilities. 637 + */ 638 + static struct attribute_group *get_counter_table(struct ib_device *dev) 639 + { 640 + struct ib_class_port_info cpi; 641 + 642 + if (get_perf_mad(dev, 0, IB_PMA_CLASS_PORT_INFO, 643 + &cpi, 40, sizeof(cpi)) >= 0) { 644 + 645 + if (cpi.capability_mask && IB_PMA_CLASS_CAP_EXT_WIDTH) 646 + /* We have extended counters */ 647 + return &pma_group_ext; 648 + 649 + if (cpi.capability_mask && IB_PMA_CLASS_CAP_EXT_WIDTH_NOIETF) 650 + /* But not the IETF ones */ 651 + return &pma_group_noietf; 652 + } 653 + 654 + /* Fall back to normal counters */ 655 + return &pma_group; 656 + } 657 + 713 658 static int add_port(struct ib_device *device, int port_num, 714 659 int (*port_callback)(struct ib_device *, 715 660 u8, struct kobject *)) ··· 776 673 goto err_put; 777 674 } 778 675 779 - ret = sysfs_create_group(&p->kobj, &pma_group); 676 + p->pma_table = get_counter_table(device); 677 + ret = sysfs_create_group(&p->kobj, p->pma_table); 780 678 if (ret) 781 679 goto err_put_gid_attrs; 782 680 ··· 884 780 p->gid_group.attrs = NULL; 885 781 886 782 err_remove_pma: 887 - sysfs_remove_group(&p->kobj, &pma_group); 783 + sysfs_remove_group(&p->kobj, p->pma_table); 888 784 889 785 err_put_gid_attrs: 890 786 kobject_put(&p->gid_attr_group->kobj); ··· 1094 990 list_for_each_entry_safe(p, t, &device->port_list, entry) { 1095 991 struct ib_port *port = container_of(p, struct ib_port, kobj); 1096 992 list_del(&p->entry); 1097 - sysfs_remove_group(p, &pma_group); 993 + sysfs_remove_group(p, port->pma_table); 1098 994 sysfs_remove_group(p, &port->pkey_group); 1099 995 sysfs_remove_group(p, &port->gid_group); 1100 996 sysfs_remove_group(&port->gid_attr_group->kobj,
+1
include/rdma/ib_pma.h
··· 42 42 */ 43 43 #define IB_PMA_CLASS_CAP_ALLPORTSELECT cpu_to_be16(1 << 8) 44 44 #define IB_PMA_CLASS_CAP_EXT_WIDTH cpu_to_be16(1 << 9) 45 + #define IB_PMA_CLASS_CAP_EXT_WIDTH_NOIETF cpu_to_be16(1 << 10) 45 46 #define IB_PMA_CLASS_CAP_XMIT_WAIT cpu_to_be16(1 << 12) 46 47 47 48 #define IB_PMA_CLASS_PORT_INFO cpu_to_be16(0x0001)