Skip to content

Commit

Permalink
Merge branch 'spinler-fix-etherStats' into 'devel'
Browse files Browse the repository at this point in the history
fix(libnfb - rxmac): use correct value for pkts in etherStats

See merge request ndk/swbase!144
  • Loading branch information
martinspinler committed Jan 7, 2025
2 parents 31a8457 + e6d99b8 commit 2951e60
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 21 deletions.
23 changes: 17 additions & 6 deletions libnfb/include/netcope/rxmac.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -112,9 +114,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
Expand Down Expand Up @@ -313,13 +315,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;
Expand All @@ -328,15 +336,18 @@ 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);
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);
Expand Down
2 changes: 1 addition & 1 deletion tools/eth/eth.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 2 additions & 3 deletions tools/eth/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
25 changes: 14 additions & 11 deletions tools/eth/rxmac.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
}
Expand All @@ -96,24 +97,23 @@ 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);
printf("etherStatsMulticastPkts : %llu\n", s.multicastPkts);
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)
Expand Down Expand Up @@ -238,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;
Expand Down

0 comments on commit 2951e60

Please sign in to comment.