Skip to content

Commit 145d9c5

Browse files
Christoph Lameterdledford
authored andcommitted
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 <[email protected]> Reviewed-by: Ira Weiny <[email protected]> Reviewed-by: Hal Rosenstock <[email protected]> Signed-off-by: Doug Ledford <[email protected]>
1 parent b2788ce commit 145d9c5

File tree

2 files changed

+108
-3
lines changed

2 files changed

+108
-3
lines changed

drivers/infiniband/core/sysfs.c

Lines changed: 107 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ struct ib_port {
5757
struct attribute_group gid_group;
5858
struct attribute_group pkey_group;
5959
u8 port_num;
60+
struct attribute_group *pma_table;
6061
};
6162

6263
struct port_attribute {
@@ -401,6 +402,13 @@ struct port_table_attribute port_pma_attr_##_name = { \
401402
.attr_id = IB_PMA_PORT_COUNTERS , \
402403
}
403404

405+
#define PORT_PMA_ATTR_EXT(_name, _width, _offset) \
406+
struct port_table_attribute port_pma_attr_ext_##_name = { \
407+
.attr = __ATTR(_name, S_IRUGO, show_pma_counter, NULL), \
408+
.index = (_offset) | ((_width) << 16), \
409+
.attr_id = IB_PMA_PORT_COUNTERS_EXT , \
410+
}
411+
404412
/*
405413
* Get a Perfmgmt MAD block of data.
406414
* Returns error code or the number of bytes retrieved.
@@ -481,6 +489,11 @@ static ssize_t show_pma_counter(struct ib_port *p, struct port_attribute *attr,
481489
ret = sprintf(buf, "%u\n",
482490
be32_to_cpup((__be32 *)data));
483491
break;
492+
case 64:
493+
ret = sprintf(buf, "%llu\n",
494+
be64_to_cpup((__be64 *)data));
495+
break;
496+
484497
default:
485498
ret = 0;
486499
}
@@ -505,6 +518,18 @@ static PORT_PMA_ATTR(port_rcv_data , 13, 32, 224);
505518
static PORT_PMA_ATTR(port_xmit_packets , 14, 32, 256);
506519
static PORT_PMA_ATTR(port_rcv_packets , 15, 32, 288);
507520

521+
/*
522+
* Counters added by extended set
523+
*/
524+
static PORT_PMA_ATTR_EXT(port_xmit_data , 64, 64);
525+
static PORT_PMA_ATTR_EXT(port_rcv_data , 64, 128);
526+
static PORT_PMA_ATTR_EXT(port_xmit_packets , 64, 192);
527+
static PORT_PMA_ATTR_EXT(port_rcv_packets , 64, 256);
528+
static PORT_PMA_ATTR_EXT(unicast_xmit_packets , 64, 320);
529+
static PORT_PMA_ATTR_EXT(unicast_rcv_packets , 64, 384);
530+
static PORT_PMA_ATTR_EXT(multicast_xmit_packets , 64, 448);
531+
static PORT_PMA_ATTR_EXT(multicast_rcv_packets , 64, 512);
532+
508533
static struct attribute *pma_attrs[] = {
509534
&port_pma_attr_symbol_error.attr.attr,
510535
&port_pma_attr_link_error_recovery.attr.attr,
@@ -525,11 +550,65 @@ static struct attribute *pma_attrs[] = {
525550
NULL
526551
};
527552

553+
static struct attribute *pma_attrs_ext[] = {
554+
&port_pma_attr_symbol_error.attr.attr,
555+
&port_pma_attr_link_error_recovery.attr.attr,
556+
&port_pma_attr_link_downed.attr.attr,
557+
&port_pma_attr_port_rcv_errors.attr.attr,
558+
&port_pma_attr_port_rcv_remote_physical_errors.attr.attr,
559+
&port_pma_attr_port_rcv_switch_relay_errors.attr.attr,
560+
&port_pma_attr_port_xmit_discards.attr.attr,
561+
&port_pma_attr_port_xmit_constraint_errors.attr.attr,
562+
&port_pma_attr_port_rcv_constraint_errors.attr.attr,
563+
&port_pma_attr_local_link_integrity_errors.attr.attr,
564+
&port_pma_attr_excessive_buffer_overrun_errors.attr.attr,
565+
&port_pma_attr_VL15_dropped.attr.attr,
566+
&port_pma_attr_ext_port_xmit_data.attr.attr,
567+
&port_pma_attr_ext_port_rcv_data.attr.attr,
568+
&port_pma_attr_ext_port_xmit_packets.attr.attr,
569+
&port_pma_attr_ext_port_rcv_packets.attr.attr,
570+
&port_pma_attr_ext_unicast_rcv_packets.attr.attr,
571+
&port_pma_attr_ext_unicast_xmit_packets.attr.attr,
572+
&port_pma_attr_ext_multicast_rcv_packets.attr.attr,
573+
&port_pma_attr_ext_multicast_xmit_packets.attr.attr,
574+
NULL
575+
};
576+
577+
static struct attribute *pma_attrs_noietf[] = {
578+
&port_pma_attr_symbol_error.attr.attr,
579+
&port_pma_attr_link_error_recovery.attr.attr,
580+
&port_pma_attr_link_downed.attr.attr,
581+
&port_pma_attr_port_rcv_errors.attr.attr,
582+
&port_pma_attr_port_rcv_remote_physical_errors.attr.attr,
583+
&port_pma_attr_port_rcv_switch_relay_errors.attr.attr,
584+
&port_pma_attr_port_xmit_discards.attr.attr,
585+
&port_pma_attr_port_xmit_constraint_errors.attr.attr,
586+
&port_pma_attr_port_rcv_constraint_errors.attr.attr,
587+
&port_pma_attr_local_link_integrity_errors.attr.attr,
588+
&port_pma_attr_excessive_buffer_overrun_errors.attr.attr,
589+
&port_pma_attr_VL15_dropped.attr.attr,
590+
&port_pma_attr_ext_port_xmit_data.attr.attr,
591+
&port_pma_attr_ext_port_rcv_data.attr.attr,
592+
&port_pma_attr_ext_port_xmit_packets.attr.attr,
593+
&port_pma_attr_ext_port_rcv_packets.attr.attr,
594+
NULL
595+
};
596+
528597
static struct attribute_group pma_group = {
529598
.name = "counters",
530599
.attrs = pma_attrs
531600
};
532601

602+
static struct attribute_group pma_group_ext = {
603+
.name = "counters",
604+
.attrs = pma_attrs_ext
605+
};
606+
607+
static struct attribute_group pma_group_noietf = {
608+
.name = "counters",
609+
.attrs = pma_attrs_noietf
610+
};
611+
533612
static void ib_port_release(struct kobject *kobj)
534613
{
535614
struct ib_port *p = container_of(kobj, struct ib_port, kobj);
@@ -631,6 +710,30 @@ alloc_group_attrs(ssize_t (*show)(struct ib_port *,
631710
return NULL;
632711
}
633712

713+
/*
714+
* Figure out which counter table to use depending on
715+
* the device capabilities.
716+
*/
717+
static struct attribute_group *get_counter_table(struct ib_device *dev)
718+
{
719+
struct ib_class_port_info cpi;
720+
721+
if (get_perf_mad(dev, 0, IB_PMA_CLASS_PORT_INFO,
722+
&cpi, 40, sizeof(cpi)) >= 0) {
723+
724+
if (cpi.capability_mask && IB_PMA_CLASS_CAP_EXT_WIDTH)
725+
/* We have extended counters */
726+
return &pma_group_ext;
727+
728+
if (cpi.capability_mask && IB_PMA_CLASS_CAP_EXT_WIDTH_NOIETF)
729+
/* But not the IETF ones */
730+
return &pma_group_noietf;
731+
}
732+
733+
/* Fall back to normal counters */
734+
return &pma_group;
735+
}
736+
634737
static int add_port(struct ib_device *device, int port_num,
635738
int (*port_callback)(struct ib_device *,
636739
u8, struct kobject *))
@@ -673,7 +776,8 @@ static int add_port(struct ib_device *device, int port_num,
673776
goto err_put;
674777
}
675778

676-
ret = sysfs_create_group(&p->kobj, &pma_group);
779+
p->pma_table = get_counter_table(device);
780+
ret = sysfs_create_group(&p->kobj, p->pma_table);
677781
if (ret)
678782
goto err_put_gid_attrs;
679783

@@ -780,7 +884,7 @@ static int add_port(struct ib_device *device, int port_num,
780884
p->gid_group.attrs = NULL;
781885

782886
err_remove_pma:
783-
sysfs_remove_group(&p->kobj, &pma_group);
887+
sysfs_remove_group(&p->kobj, p->pma_table);
784888

785889
err_put_gid_attrs:
786890
kobject_put(&p->gid_attr_group->kobj);
@@ -990,7 +1094,7 @@ static void free_port_list_attributes(struct ib_device *device)
9901094
list_for_each_entry_safe(p, t, &device->port_list, entry) {
9911095
struct ib_port *port = container_of(p, struct ib_port, kobj);
9921096
list_del(&p->entry);
993-
sysfs_remove_group(p, &pma_group);
1097+
sysfs_remove_group(p, port->pma_table);
9941098
sysfs_remove_group(p, &port->pkey_group);
9951099
sysfs_remove_group(p, &port->gid_group);
9961100
sysfs_remove_group(&port->gid_attr_group->kobj,

include/rdma/ib_pma.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
*/
4343
#define IB_PMA_CLASS_CAP_ALLPORTSELECT cpu_to_be16(1 << 8)
4444
#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)
4546
#define IB_PMA_CLASS_CAP_XMIT_WAIT cpu_to_be16(1 << 12)
4647

4748
#define IB_PMA_CLASS_PORT_INFO cpu_to_be16(0x0001)

0 commit comments

Comments
 (0)