diff --git a/econet/ecnt_prvt.c b/econet/ecnt_prvt.c index 735ae8484cd6721a5b7eae2acdb70d81a458bfc1..ca9e6345c1fe113cc8f68d267d4f0becdf317006 100644 --- a/econet/ecnt_prvt.c +++ b/econet/ecnt_prvt.c @@ -56,8 +56,19 @@ #define IFNAME_NAS "nas" #define IFNAME_AE_WAN "ae_wan" #define DRIVER_NAME "hsgmii_lan" -#define DRIVER_NAME_LEN 20 -#define HSGMII_INDEX 2 +#define DRIVER_NAME_LEN 20 + +struct hsgmii_lookup_table { + const unsigned int idx; + char *ifnames[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 } }, +}; /* Not defined in Econet library */ @@ -102,13 +113,35 @@ int hsgmii_lan_prvt_get_port_statistics(char *ifname, struct eth_stats *stats, s ECNT_FEMGR_GDMA2_TX_STATISTICS tx_stats; ECNT_FEMGR_GDMA2_RX_STATISTICS rx_stats; - char driver_name[DRIVER_NAME_LEN]; + char driver_name[DRIVER_NAME_LEN] = {0}; if (get_drv_info_by_ifname(ifname, driver_name)) return -1; if (!strncmp(driver_name, DRIVER_NAME, DRIVER_NAME_LEN)) { - if (!fe_lib_get_hsgmii_tx_statistics(&tx_stats, HSGMII_INDEX)) { + int i = 0, hsgmii_index = -1; + + for (; i < ARRAY_SIZE(hsgmii_lookup_tbl); i++) { + int j = 0; + + while (hsgmii_lookup_tbl[i].ifnames[j] != NULL) { + if (!strcmp(ifname, hsgmii_lookup_tbl[i].ifnames[j])) { + hsgmii_index = hsgmii_lookup_tbl[i].idx; + break; + } + j++; + } + + if (hsgmii_index != -1) + break; + } + + if (hsgmii_index == -1) + return -1; + memset(&tx_stats, 0, sizeof(ECNT_FEMGR_GDMA2_TX_STATISTICS)); + 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; @@ -136,9 +169,8 @@ int hsgmii_lan_prvt_get_port_statistics(char *ifname, struct eth_stats *stats, s } } - if (!fe_lib_get_hsgmii_rx_statistics(&rx_stats, HSGMII_INDEX)){ + 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; @@ -166,10 +198,73 @@ int hsgmii_lan_prvt_get_port_statistics(char *ifname, struct eth_stats *stats, s } return 0; } - return -1; + return -1; } +int ae_wan_prvt_get_port_statistics(struct eth_stats *stats, struct eth_rmon_stats *rstats) { + ECNT_FEMGR_GDMA2_TX_STATISTICS tx_stats; + ECNT_FEMGR_GDMA2_RX_STATISTICS rx_stats; + + memset(&tx_stats, 0, sizeof(ECNT_FEMGR_GDMA2_TX_STATISTICS)); + 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; + } + + } + 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; + } + 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; + } + } + return 0; +} int ecnt_prvt_get_port_statistics(uint32_t port, struct eth_stats *stats, diff --git a/econet/ecnt_prvt.h b/econet/ecnt_prvt.h index ba9c8d0d04cd67ead349a0c4dbf88e119e606552..24f4af9a3f25ce85b3201921225401afe83a7ab0 100644 --- a/econet/ecnt_prvt.h +++ b/econet/ecnt_prvt.h @@ -111,6 +111,9 @@ int ecnt_prvt_get_port_statistics(uint32_t port_num, */ int ecnt_prvt_set_port_state(uint32_t port_num, bool state); +int hsgmii_lan_prvt_get_port_statistics(char *ifname, struct eth_stats *stats, struct eth_rmon_stats *rstats); +int ae_wan_prvt_get_port_statistics(struct eth_stats *stats, struct eth_rmon_stats *rstats); + #ifdef __cplusplus } #endif diff --git a/econet/econet.c b/econet/econet.c index b965dfd0eee0ba2a35d1d96d1d58ff66b6caba38..94a79584aeb46b74c080d03947fc3acbd8922236 100644 --- a/econet/econet.c +++ b/econet/econet.c @@ -65,13 +65,23 @@ int econet_eth_get_stats(const char *ifname, struct eth_stats *stats) port_num = ecnt_prvt_get_port_num(ifname); if (port_num == ECNT_PRVT_PORT_NUM_INVALID) { /* Check and fetch stats if the Interface belongs to hsgmii_lan driver */ - if (!hsgmii_lan_prvt_get_port_statistics(ifname, stats, NULL)) { + if (!hsgmii_lan_prvt_get_port_statistics(ifname, stats, NULL)) { return 0; } libethernet_err("invalid port name: %s\n", ifname); return -1; } + if (!strcmp(ifname, "ae_wan")) { + /* Check and fetch rstats if the Interface belongs to ae_wan driver */ + if (!ae_wan_prvt_get_port_statistics(stats, NULL)) { + return 0; + } + + libethernet_err("error reading stats for interface %s\n", ifname); + return -1; + } + if (ecnt_prvt_get_port_statistics(port_num, stats, NULL)) { libethernet_err("error reading stats for interface %s\n", ifname); return -1; @@ -96,6 +106,16 @@ int econet_eth_get_rmon_stats(const char *ifname, struct eth_rmon_stats *rstats) return -1; } + if (!strcmp(ifname, "ae_wan")) { + /* Check and fetch rstats if the Interface belongs to ae_wan driver */ + if (!ae_wan_prvt_get_port_statistics(NULL, rstats)) { + return 0; + } + + libethernet_err("error reading rmon stats for interface %s\n", ifname); + return -1; + } + if (ecnt_prvt_get_port_statistics(port_num, NULL, rstats)) { libethernet_err("error reading rmon stats for interface %s\n", ifname); return -1;