From 8a5fe63cb68e165c3a3ea071c7d3f9aa342c9877 Mon Sep 17 00:00:00 2001 From: Arjun Govindjee Date: Fri, 17 Apr 2026 17:58:43 -0600 Subject: [PATCH 1/2] pmon: fix egress bit encoding and decoding in event counter setup The egress (ingress/egress) bit belongs in bit 7 of the byte following the 32-bit mask field, alongside type mask bits 24-30 in bits 6:0. Previously, the egress flag was written as 0x01 into this byte instead of 0x80, and type mask bits 24-30 were not included. On readback, the egress flag was incorrectly extracted from bit 0 rather than bit 7, and the upper type mask bits were dropped entirely. --- inc/switchtec/pmon.h | 3 +++ lib/pmon.c | 13 +++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/inc/switchtec/pmon.h b/inc/switchtec/pmon.h index a3274d2c9..4dabe4848 100644 --- a/inc/switchtec/pmon.h +++ b/inc/switchtec/pmon.h @@ -28,6 +28,9 @@ #include #include +#define SWITCHTEC_PMON_EVENT_EGRESS 0x80 +#define SWITCHTEC_PMON_EVENT_INGRESS 0x00 + #pragma pack(push, 1) struct pmon_event_counter_setup { diff --git a/lib/pmon.c b/lib/pmon.c index cb9625c2d..0c89710e9 100644 --- a/lib/pmon.c +++ b/lib/pmon.c @@ -150,7 +150,9 @@ int switchtec_evcntr_setup(struct switchtec_dev *dev, unsigned stack_id, [0] = { .mask = htole32((setup->type_mask << 8) | (setup->port_mask & 0xFF)), - .ieg = setup->egress, + .ieg = (setup->egress ? SWITCHTEC_PMON_EVENT_EGRESS : + SWITCHTEC_PMON_EVENT_INGRESS) | + ((setup->type_mask >> 24) & 0x7F), .thresh = htole32(setup->threshold), }, }, @@ -231,9 +233,12 @@ int switchtec_evcntr_get_setup(struct switchtec_dev *dev, unsigned stack_id, return ret; for (i = 0; i < nr_cntrs; i++) { - res[i].port_mask = le32toh(data[i].mask) & 0xFF; - res[i].type_mask = le32toh(data[i].mask) >> 8; - res[i].egress = data[i].ieg; + uint32_t m = le32toh(data[i].mask); + + res[i].port_mask = m & 0xFF; + res[i].type_mask = ((m >> 8) & 0xFFFFFF) | + ((data[i].ieg & 0x7F) << 24); + res[i].egress = (data[i].ieg >> 7) & 1; res[i].threshold = le32toh(data[i].thresh); } From 302637ea7fc1196e7ad70faa33b46d0e7b26d9d7 Mon Sep 17 00:00:00 2001 From: Arjun Govindjee Date: Fri, 17 Apr 2026 17:58:49 -0600 Subject: [PATCH 2/2] evcntr: display ingress/egress direction in event counter output Add INGRESS/EGRESS label to the evcntr display for counters that count TLP types (ALL_TLPS, POSTED_TLP, COMP_TLP, NON_POSTED_TLP), where direction is meaningful. --- cli/main.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cli/main.c b/cli/main.c index 4fb1f153d..e9071aabb 100644 --- a/cli/main.c +++ b/cli/main.c @@ -2622,7 +2622,12 @@ static int display_event_counters(struct switchtec_dev *dev, int stack, if (strlen(buf) > 39) strcpy(buf, "MANY"); - printf("%-40s %10u\n", buf, counts[i]); + if (setups[i].type_mask & ALL_TLPS) + printf("%-40s %-8s %10u\n", buf, + setups[i].egress ? "EGRESS" : "INGRESS", + counts[i]); + else + printf("%-40s %-8s %10u\n", buf, "", counts[i]); count++; }