From 01abd1679511e48145b1708ec23a9b29a2f460a4 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 3 Dec 2024 09:35:34 +0100 Subject: [PATCH 1/3] fix(libnfb - rxmac): use correct value for pkts in etherStats This should be "Total number of packets received (including bad packets)" --- libnfb/include/netcope/rxmac.h | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/libnfb/include/netcope/rxmac.h b/libnfb/include/netcope/rxmac.h index dc8e6fca..8d5239fa 100644 --- a/libnfb/include/netcope/rxmac.h +++ b/libnfb/include/netcope/rxmac.h @@ -112,9 +112,9 @@ static inline void nc_rxmac_set_error_mask(struct nc_rxmac *mac, uns #define RXMAC_REG_CNT_ES_CRC_ERR_LO 0x0100 #define RXMAC_REG_CNT_ES_CRC_ERR_HI 0x0138 -/* Total received packets over set MTU (etherStatsPkts) */ -#define RXMAC_REG_CNT_ES_PKTS_LO 0x0104 -#define RXMAC_REG_CNT_ES_PKTS_HI 0x013C +/* Total received packets over set MTU */ +#define RXMAC_REG_CNT_ES_OVERSIZE_LO 0x0104 +#define RXMAC_REG_CNT_ES_OVERSIZE_HI 0x013C /* Total received packets below set minimal length */ #define RXMAC_REG_CNT_ES_UNDERSIZE_LO 0x0108 @@ -313,13 +313,19 @@ static inline int nc_rxmac_read_counters(struct nc_rxmac *mac, struct nc_rxmac_c { struct nfb_comp *comp = nfb_user_to_comp(mac); + unsigned long long cnt_total = 0; + if (!nfb_comp_lock(comp, RXMAC_COMP_LOCK)) return -EAGAIN; nfb_comp_write32(comp, RXMAC_REG_CONTROL, RXMAC_CMD_STROBE); + if (c || s) { + cnt_total = RXMAC_READ_CNT(comp, PACKETS); + } + if (c) { - c->cnt_total = RXMAC_READ_CNT(comp, PACKETS); + c->cnt_total = cnt_total; c->cnt_received = RXMAC_READ_CNT(comp, RECEIVED); c->cnt_overflowed = RXMAC_READ_CNT(comp, OVERFLOW); c->cnt_erroneous = RXMAC_READ_CNT(comp, DISCARDED) - c->cnt_overflowed; @@ -328,7 +334,7 @@ static inline int nc_rxmac_read_counters(struct nc_rxmac *mac, struct nc_rxmac_c if (s) { s->octets = RXMAC_READ_CNT(comp, ES_OCTETS); - s->pkts = RXMAC_READ_CNT(comp, ES_PKTS); + s->pkts = cnt_total; s->broadcastPkts = RXMAC_READ_CNT(comp, ES_BCAST); s->multicastPkts = RXMAC_READ_CNT(comp, ES_MCAST); s->CRCAlignErrors = RXMAC_READ_CNT(comp, ES_CRC_ERR); From 6b66e6ba5fa37015eb92b202ca97f01736b22754 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 3 Dec 2024 09:35:39 +0100 Subject: [PATCH 2/3] feat(libnfb - rxmac, tool - eth): add underMinPkts and overMaxPkts to etherstats --- libnfb/include/netcope/rxmac.h | 7 ++++++- tools/eth/rxmac.c | 5 ++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/libnfb/include/netcope/rxmac.h b/libnfb/include/netcope/rxmac.h index 8d5239fa..1973921c 100644 --- a/libnfb/include/netcope/rxmac.h +++ b/libnfb/include/netcope/rxmac.h @@ -66,6 +66,8 @@ struct nc_rxmac_etherstats { unsigned long long pkts256to511Octets; /*!< Total number of received packets that were between 256 and 511 bytes long */ unsigned long long pkts512to1023Octets; /*!< Total number of received packets that were between 512 and 1023 bytes long */ unsigned long long pkts1024to1518Octets; /*!< Total number of received packets that were between 1024 and 1518 bytes long */ + unsigned long long underMinPkts; /*!< Total number of received packets that were shorter than configured minimum */ + unsigned long long overMaxPkts; /*!< Total number of received packets that were longer than configured maximum */ }; struct nc_rxmac_status { @@ -341,8 +343,11 @@ static inline int nc_rxmac_read_counters(struct nc_rxmac *mac, struct nc_rxmac_c if (mac->has_counter_below_64) { s->undersizePkts = RXMAC_READ_CNT(comp, ES_FRAMES_BELOW_64); } else { - s->undersizePkts = RXMAC_READ_CNT(comp, ES_UNDERSIZE); + s->undersizePkts = 0; } + + s->underMinPkts = RXMAC_READ_CNT(comp, ES_UNDERSIZE); + s->overMaxPkts = RXMAC_READ_CNT(comp, ES_OVERSIZE); s->oversizePkts = RXMAC_READ_CNT(comp, ES_FRAMES_OVER_1518); s->fragments = RXMAC_READ_CNT(comp, ES_FRAGMENTS); s->jabbers = RXMAC_READ_CNT(comp, ES_JABBERS); diff --git a/tools/eth/rxmac.c b/tools/eth/rxmac.c index 3d8f2f17..4a0b29f4 100644 --- a/tools/eth/rxmac.c +++ b/tools/eth/rxmac.c @@ -96,7 +96,6 @@ void rxmac_print_ether_stats(struct nc_rxmac *rxmac) } printf("---------------------------- RXMAC etherStatsTable ----\n"); -// printf("etherStatsDropEvents : %llu\n") printf("etherStatsOctets : %llu\n", s.octets); printf("etherStatsPkts : %llu\n", s.pkts); printf("etherStatsBroadcastPkts : %llu\n", s.broadcastPkts); @@ -104,16 +103,16 @@ void rxmac_print_ether_stats(struct nc_rxmac *rxmac) printf("etherStatsCRCAlignErrors : %llu\n", s.CRCAlignErrors); printf("etherStatsUndersizePkts : %llu\n", s.undersizePkts); printf("etherStatsOversizePkts : %llu\n", s.oversizePkts); -// printf("etherStatsOversizePkts : %llu\n"); printf("etherStatsFragments : %llu\n", s.fragments); printf("etherStatsJabbers : %llu\n", s.jabbers); -// printf("etherStatsCollisions : %llu\n"); printf("etherStatsPkts64Octets : %llu\n", s.pkts64Octets); printf("etherStatsPkts65to127Octets : %llu\n", s.pkts65to127Octets); printf("etherStatsPkts128to255Octets : %llu\n", s.pkts128to255Octets); printf("etherStatsPkts256to511Octets : %llu\n", s.pkts256to511Octets); printf("etherStatsPkts512to1023Octets : %llu\n", s.pkts512to1023Octets); printf("etherStatsPkts1024to1518Octets: %llu\n", s.pkts1024to1518Octets); + printf("underMinPkts : %llu\n", s.underMinPkts); + printf("overMaxPkts : %llu\n", s.overMaxPkts); } int clear_mac_addresses(struct nc_rxmac *rxmac) From e6d99b8df0ac04883c73d01a381b703cbe6d3c0c Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 3 Dec 2024 09:35:41 +0100 Subject: [PATCH 3/3] feat(tool - eth): allow user to set RxMAC error mask with parameter -m --- tools/eth/eth.h | 2 +- tools/eth/main.c | 5 ++--- tools/eth/rxmac.c | 20 ++++++++++++-------- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/tools/eth/eth.h b/tools/eth/eth.h index b2872403..2e1d3678 100644 --- a/tools/eth/eth.h +++ b/tools/eth/eth.h @@ -58,7 +58,7 @@ enum commands { CMD_USAGE, CMD_ENABLE, CMD_RESET, - CMD_SET_MASK, + CMD_SET_ERROR_MASK, CMD_SET_PMA_TYPE, CMD_SET_PMA_FEATURE, CMD_SET_MAX_LENGTH, diff --git a/tools/eth/main.c b/tools/eth/main.c index 6218e037..293786b9 100644 --- a/tools/eth/main.c +++ b/tools/eth/main.c @@ -45,7 +45,7 @@ void usage(const char *progname, int verbose) printf("-S Show etherStats counters\n"); printf("-l length Minimal allowed frame length\n"); printf("-L length Maximal allowed frame length\n"); -/* printf("-m mask Set error mask 0-31\n"); */ + printf("-m mask Set RXMAC error bitmask value (integer; use -v to view current configuration)\n"); printf("-c type Set PMA type/mode by name or enable/disable feature (+feat/-feat)\n"); printf("-p repeater_cfg Set transmit data source%s\n", verbose ? "" : " (-hv for more info)"); if (verbose) { @@ -212,10 +212,9 @@ int main(int argc, char *argv[]) p.param < 0 || p.param > 31) { errx(EXIT_FAILURE, "Wrong error mask."); } - p.command = CMD_SET_MASK; + p.command = CMD_SET_ERROR_MASK; cmds++; break; - case 'M': switch (tolower(optarg[0])) { case 's': p.command = CMD_SHOW_MACS; break; diff --git a/tools/eth/rxmac.c b/tools/eth/rxmac.c index 4a0b29f4..5c724bc1 100644 --- a/tools/eth/rxmac.c +++ b/tools/eth/rxmac.c @@ -55,14 +55,15 @@ void rxmac_print_status(struct nc_rxmac *rxmac, struct eth_params *p) return; printf("------------------------------ RXMAC Configuration ----\n"); - printf("Frame error from MII [1] : %s", (s.error_mask & 0x00000001) ? "enabled\n" : "disabled\n"); - printf("CRC check [2] : %s", (s.error_mask & 0x00000002) ? "enabled\n" : "disabled\n"); - printf("Minimum frame length [4] : %s\n" - "* length : %d B\n", + printf("Error mask register : 0x%02x\n", s.error_mask); + printf(" * Frame error from MII [0]: %s\n", (s.error_mask & 0x00000001) ? "enabled" : "disabled"); + printf(" * CRC check [1]: %s\n", (s.error_mask & 0x00000002) ? "enabled" : "disabled"); + printf(" * Minimum frame length [2]: %s\n" + " * length : %d B\n", (s.error_mask & 0x00000004) ? "enabled" : "disabled", s.frame_length_min); - printf("MTU frame length [8] : %s\n" - "* length : %d B", + printf(" * MTU frame length [3]: %s\n" + " * length : %d B", (s.error_mask & 0x00000008) ? "enabled" : "disabled", s.frame_length_max); @@ -78,8 +79,8 @@ void rxmac_print_status(struct nc_rxmac *rxmac, struct eth_params *p) case RXMAC_MAC_FILTER_TABLE_BCAST: text = "Filter by MAC address table, allow broadcast"; break; case RXMAC_MAC_FILTER_TABLE_BCAST_MCAST:text = "Filter by MAC address table, allow broadcast + multicast"; break; } - printf("MAC address check [16] : %s\n" - "* mode : %s\n", + printf(" * MAC address check [4]: %s\n" + " * mode : %s\n", (s.error_mask & 0x00000010) ? "enabled" : "disabled", text); printf("MAC address table size : %d\n", s.mac_addr_count); } @@ -237,6 +238,9 @@ int rxmac_execute_operation(struct nc_rxmac *rxmac, struct eth_params *p) nc_rxmac_set_frame_length(rxmac, p->param, p->command == CMD_SET_MAX_LENGTH ? RXMAC_FRAME_LENGTH_MAX : RXMAC_FRAME_LENGTH_MIN); break; + case CMD_SET_ERROR_MASK: + nc_rxmac_set_error_mask(rxmac, p->param); + break; case CMD_SHOW_MACS: ret = show_mac_addresses(rxmac); break;