diff --git a/econet/ecnt_prvt.c b/econet/ecnt_prvt.c index ca9e6345c1fe113cc8f68d267d4f0becdf317006..12c537f6d88b57f37a1ed1d2dbd4042276e05ea9 100644 --- a/econet/ecnt_prvt.c +++ b/econet/ecnt_prvt.c @@ -61,13 +61,14 @@ struct hsgmii_lookup_table { const unsigned int idx; char *ifnames[IFNAMSIZ]; + const char iftype[IFNAMSIZ]; }; const struct hsgmii_lookup_table hsgmii_lookup_tbl[] = { - { 2, { "eth0.5", "eth1", NULL } }, - { 0, { "eth0.6", "eth2", NULL } }, - { 1, { "eth0.7", "eth3", NULL } }, - { 3, { "eth0.8", "eth4", NULL } }, + { 2, { "eth0.5", "eth1", NULL }, "usb" }, + { 0, { "eth0.6", "eth2", NULL }, "pcie0" }, + { 1, { "eth0.7", "eth3", NULL }, "pcie1" }, + { 3, { "eth0.8", "eth4", NULL }, "eth" }, }; @@ -108,6 +109,97 @@ exit: return ret; } +static int get_pause_stats_from_proc(const char *ifprefix, const char *iftype, + uint64_t *rx_pause_packets, uint64_t *tx_pause_packets) +{ + uint64_t rx_pause_on, rx_pause_off, tx_pause_on, tx_pause_off; + char cmdbuf[512] = {0}; + int ret; + chrCmd(cmdbuf, sizeof(cmdbuf), + "cat /proc/tc3162/%s%s_mac_dbg | grep PAUSE", + ifprefix, iftype); + + if (cmdbuf[0] == '\0') + return -1; + + ret = sscanf(cmdbuf, /* Flawfinder: ignore */ + "TXMBI_PAUSEON_CNT\t\t= %" SCNx64 ", TXMBI_PAUSEOFF_CNT\t\t= %" SCNx64 + " RX_PAUSEON_CNT\t\t\t= %" SCNx64 ", RX_PAUSEOFF_CNT\t\t\t= %" SCNx64, + &tx_pause_on, &tx_pause_off, &rx_pause_on, &rx_pause_off); + + if (ret < 4) + return -1; + + *tx_pause_packets = tx_pause_on + tx_pause_off; + *rx_pause_packets = rx_pause_on + rx_pause_off; + + return 0; +} + +static void fill_stats_tx_from_gdma(struct eth_stats *stats, struct eth_rmon_stats *rstats, + ECNT_FEMGR_GDMA2_TX_STATISTICS *tx_stats) +{ + if (tx_stats == NULL) + return; + + if (stats != NULL) { + stats->tx_bytes = 0; + stats->tx_packets = tx_stats->frame_cnt; + stats->tx_errors = 0; + stats->tx_ucast_packets = 0; + stats->tx_mcast_packets = tx_stats->broadcast; + stats->tx_bcast_packets = tx_stats->multicast; + stats->tx_discard_packets = tx_stats->drop_cnt; + } + + if (rstats != NULL) { + rstats->tx.packets = tx_stats->frame_cnt; + rstats->tx.bytes = 0; + rstats->tx.bcast_packets = tx_stats->broadcast; + rstats->tx.mcast_packets = tx_stats->multicast; + rstats->tx.crc_err_packets = 0; + rstats->tx.under_sz_packets = 0; + rstats->tx.over_sz_packets = 0; + rstats->tx.packets_64bytes = tx_stats->eq_64; + rstats->tx.packets_65to127bytes = tx_stats->from_65_to_127; + rstats->tx.packets_256to511bytes = tx_stats->from_256_to_511; + rstats->tx.packets_512to1023bytes = tx_stats->from_512_to_1023; + rstats->tx.packets_1024to1518bytes = tx_stats->from_1024_to_1518; + } +} + +static void fill_stats_rx_from_gdma(struct eth_stats *stats, struct eth_rmon_stats *rstats, + ECNT_FEMGR_GDMA2_RX_STATISTICS *rx_stats) +{ + if (rx_stats == NULL) + return; + + if (stats != NULL) { + stats->rx_bytes = 0; + stats->rx_packets = rx_stats->frame_cnt; + stats->rx_errors = 0; + stats->rx_ucast_packets = 0; + stats->rx_mcast_packets = rx_stats->broadcast; + stats->rx_bcast_packets = rx_stats->multicast; + stats->rx_discard_packets = rx_stats->drop_cnt; + stats->rx_unknown_packets = 0; + } + + if (rstats != NULL) { + rstats->rx.packets = rx_stats->frame_cnt; + rstats->rx.bytes = 0; + rstats->rx.bcast_packets = rx_stats->broadcast; + rstats->rx.mcast_packets = rx_stats->multicast; + rstats->rx.crc_err_packets = 0; + rstats->rx.under_sz_packets = 0; + rstats->rx.over_sz_packets = 0; + rstats->rx.packets_64bytes = rx_stats->eq_64; + rstats->rx.packets_65to127bytes = rx_stats->from_65_to_127; + rstats->rx.packets_256to511bytes = rx_stats->from_256_to_511; + rstats->rx.packets_512to1023bytes = rx_stats->from_512_to_1023; + rstats->rx.packets_1024to1518bytes = rx_stats->from_1024_to_1518; + } +} int hsgmii_lan_prvt_get_port_statistics(char *ifname, struct eth_stats *stats, struct eth_rmon_stats *rstats) { ECNT_FEMGR_GDMA2_TX_STATISTICS tx_stats; @@ -119,6 +211,7 @@ int hsgmii_lan_prvt_get_port_statistics(char *ifname, struct eth_stats *stats, s if (!strncmp(driver_name, DRIVER_NAME, DRIVER_NAME_LEN)) { int i = 0, hsgmii_index = -1; + const char *hsgmii_iftype; for (; i < ARRAY_SIZE(hsgmii_lookup_tbl); i++) { int j = 0; @@ -126,6 +219,7 @@ int hsgmii_lan_prvt_get_port_statistics(char *ifname, struct eth_stats *stats, s while (hsgmii_lookup_tbl[i].ifnames[j] != NULL) { if (!strcmp(ifname, hsgmii_lookup_tbl[i].ifnames[j])) { hsgmii_index = hsgmii_lookup_tbl[i].idx; + hsgmii_iftype = hsgmii_lookup_tbl[i].iftype; break; } j++; @@ -142,60 +236,17 @@ int hsgmii_lan_prvt_get_port_statistics(char *ifname, struct eth_stats *stats, s memset(&rx_stats, 0, sizeof(ECNT_FEMGR_GDMA2_RX_STATISTICS)); if (!fe_lib_get_hsgmii_tx_statistics(&tx_stats, hsgmii_index)) { - if (stats != NULL) { - stats->tx_bytes = 0; - stats->tx_packets = tx_stats.frame_cnt; - stats->tx_errors = 0; - stats->tx_ucast_packets = 0; - stats->tx_mcast_packets = tx_stats.broadcast; - stats->tx_bcast_packets = tx_stats.multicast; - stats->tx_discard_packets = tx_stats.drop_cnt; - stats->rx_unknown_packets = 0; - } - - if (rstats != NULL) { - rstats->tx.packets = tx_stats.frame_cnt; - rstats->tx.bytes = 0; - rstats->tx.bcast_packets = tx_stats.broadcast; - rstats->tx.mcast_packets = tx_stats.multicast; - rstats->tx.crc_err_packets = 0; - rstats->tx.under_sz_packets = 0; - rstats->tx.over_sz_packets = 0; - rstats->tx.packets_64bytes = tx_stats.eq_64; - rstats->tx.packets_65to127bytes = tx_stats.from_65_to_127; - rstats->tx.packets_256to511bytes = tx_stats.from_256_to_511; - rstats->tx.packets_512to1023bytes = tx_stats.from_512_to_1023; - rstats->tx.packets_1024to1518bytes = tx_stats.from_1024_to_1518; - } - + fill_stats_tx_from_gdma(stats, rstats, &tx_stats); + } + if (!fe_lib_get_hsgmii_rx_statistics(&rx_stats, hsgmii_index)) { + fill_stats_rx_from_gdma(stats, rstats, &rx_stats); } - if (!fe_lib_get_hsgmii_rx_statistics(&rx_stats, hsgmii_index)){ - if (rstats != NULL) { - rstats->rx.packets = rx_stats.frame_cnt; - rstats->rx.bytes = 0; - rstats->rx.bcast_packets = rx_stats.broadcast; - rstats->rx.mcast_packets = rx_stats.multicast; - rstats->rx.crc_err_packets = rx_stats.crc; - rstats->rx.under_sz_packets = rx_stats.undersize; - rstats->rx.over_sz_packets = rx_stats.oversize; - rstats->rx.packets_64bytes = rx_stats.eq_64; - rstats->rx.packets_65to127bytes = rx_stats.from_65_to_127; - rstats->rx.packets_256to511bytes = rx_stats.from_256_to_511; - rstats->rx.packets_512to1023bytes = rx_stats.from_512_to_1023; - rstats->rx.packets_1024to1518bytes = rx_stats.from_1024_to_1518; - } - if (stats != NULL) { - stats->rx_bytes = 0; - stats->rx_packets = rx_stats.frame_cnt; - stats->rx_errors = 0; - stats->rx_ucast_packets = 0; - stats->rx_mcast_packets = rx_stats.multicast; - stats->rx_bcast_packets = rx_stats.broadcast; - stats->rx_discard_packets = rx_stats.drop_cnt; - stats->rx_unknown_packets = 0; - } + if (rstats != NULL) { + get_pause_stats_from_proc("hsgmii_", hsgmii_iftype, &rstats->rx.pause_packets, + &rstats->tx.pause_packets); } + return 0; } return -1; @@ -209,60 +260,18 @@ int ae_wan_prvt_get_port_statistics(struct eth_stats *stats, struct eth_rmon_sta memset(&rx_stats, 0, sizeof(ECNT_FEMGR_GDMA2_RX_STATISTICS)); if (!fe_lib_get_gdma2_tx_statistics(&tx_stats)) { - if (stats != NULL) { - stats->tx_bytes = 0; - stats->tx_packets = tx_stats.frame_cnt; - stats->tx_errors = 0; - stats->tx_ucast_packets = 0; - stats->tx_mcast_packets = tx_stats.broadcast; - stats->tx_bcast_packets = tx_stats.multicast; - stats->tx_discard_packets = tx_stats.drop_cnt; - stats->rx_unknown_packets = 0; - } - - if (rstats != NULL) { - rstats->tx.packets = tx_stats.frame_cnt; - rstats->tx.bytes = 0; - rstats->tx.bcast_packets = tx_stats.broadcast; - rstats->tx.mcast_packets = tx_stats.multicast; - rstats->tx.crc_err_packets = 0; - rstats->tx.under_sz_packets = 0; - rstats->tx.over_sz_packets = 0; - rstats->tx.packets_64bytes = tx_stats.eq_64; - rstats->tx.packets_65to127bytes = tx_stats.from_65_to_127; - rstats->tx.packets_256to511bytes = tx_stats.from_256_to_511; - rstats->tx.packets_512to1023bytes = tx_stats.from_512_to_1023; - rstats->tx.packets_1024to1518bytes = tx_stats.from_1024_to_1518; - } - + fill_stats_tx_from_gdma(stats, rstats, &tx_stats); } + if (!fe_lib_get_gdma2_rx_statistics(&rx_stats)) { - if (rstats != NULL) { - rstats->rx.packets = rx_stats.frame_cnt; - rstats->rx.bytes = 0; - rstats->rx.bcast_packets = rx_stats.broadcast; - rstats->rx.mcast_packets = rx_stats.multicast; - rstats->rx.crc_err_packets = rx_stats.crc; - rstats->rx.under_sz_packets = rx_stats.undersize; - rstats->rx.over_sz_packets = rx_stats.oversize; - rstats->rx.packets_64bytes = rx_stats.eq_64; - rstats->rx.packets_65to127bytes = rx_stats.from_65_to_127; - rstats->rx.packets_256to511bytes = rx_stats.from_256_to_511; - rstats->rx.packets_512to1023bytes = rx_stats.from_512_to_1023; - rstats->rx.packets_1024to1518bytes = rx_stats.from_1024_to_1518; - } + fill_stats_rx_from_gdma(stats, rstats, &rx_stats); + } - if (stats != NULL) { - stats->rx_bytes = 0; - stats->rx_packets = rx_stats.frame_cnt; - stats->rx_errors = 0; - stats->rx_ucast_packets = 0; - stats->rx_mcast_packets = rx_stats.multicast; - stats->rx_bcast_packets = rx_stats.broadcast; - stats->rx_discard_packets = rx_stats.drop_cnt; - stats->rx_unknown_packets = 0; - } + if (rstats != NULL) { + get_pause_stats_from_proc("", "ae_wan", &rstats->rx.pause_packets, + &rstats->tx.pause_packets); } + return 0; } @@ -327,6 +336,8 @@ int ecnt_prvt_get_port_statistics(uint32_t port, portcnt.__ecnt_prefix ## UnderSizePktsCnt; \ rstats->__rmon_field.over_sz_packets = \ portcnt.__ecnt_prefix ## OverSizePktsCnt; \ + rstats->__rmon_field.pause_packets = \ + portcnt.__ecnt_prefix ## PauseFramesCnt; \ rstats->__rmon_field.packets_64bytes = \ portcnt.__ecnt_prefix ## 64BytePktsCnt; \ rstats->__rmon_field.packets_65to127bytes = \ diff --git a/test_stub/stub.h b/test_stub/stub.h index f104620ec388e4ea7a56183d58184565705b79d0..8f23ff83e7823d66239b5c777fe6b3880b3a5dad 100644 --- a/test_stub/stub.h +++ b/test_stub/stub.h @@ -59,6 +59,7 @@ const struct eth_rmon_stats test_eth_rmon_stats_data = { .tx.crc_err_packets = 43, .tx.under_sz_packets = 2, .tx.over_sz_packets = 300, + .tx.pause_packets = 10, .tx.packets_64bytes = 900000, .tx.packets_65to127bytes = 8200, .tx.packets_128to255bytes = 120000, @@ -72,6 +73,7 @@ const struct eth_rmon_stats test_eth_rmon_stats_data = { .rx.crc_err_packets = 6000, .rx.under_sz_packets = 24, .rx.over_sz_packets = 4500, + .rx.pause_packets = 20, .rx.packets_64bytes = 6000, .rx.packets_65to127bytes = 41000, .rx.packets_128to255bytes = 3000000,