diff --git a/Makefile b/Makefile index 0e994ea96dacce08136737ef69c1e24576ab55d6..12941771a4d4b897f9eaa24263564e1ccb136518 100644 --- a/Makefile +++ b/Makefile @@ -21,7 +21,7 @@ endif ifeq ($(PLATFORM),ECONET) CFLAGS += -Itest_stub $(LIBETH_CFLAGS) objs_lib += econet/econet.o econet/ecnt_prvt.o -LIBS += -lapi_lib_switchmgr +LIBS += -lapi_lib_switchmgr -lapi_lib_fe endif ifeq ($(PLATFORM),LINUX) diff --git a/econet/ecnt_prvt.c b/econet/ecnt_prvt.c index b458c3da8b1c3f40fb987ca51843e00ce5ba1c0c..d47416ef41fb8f30efecd779ccaf9659593399e1 100644 --- a/econet/ecnt_prvt.c +++ b/econet/ecnt_prvt.c @@ -33,6 +33,9 @@ #include <sys/types.h> #include <unistd.h> #include <easy/easy.h> +#include <sys/ioctl.h> +#include <net/if.h> +#include <linux/sockios.h> #include "../ethernet.h" @@ -44,6 +47,7 @@ #include "libapi_lib_switchmgr.h" #endif +#include "libapi_lib_fe.h" #define TC3162_MAX_LINE_LEN (100) #define TC3162_DUPLEX_MODE_LEN (32) #define TC3162_SPEED_MODE_LEN (32) @@ -51,12 +55,122 @@ #define IFNAME_ETH0 "eth0." #define IFNAME_NAS "nas" #define IFNAME_AE_WAN "ae_wan" +#define DRIVER_NAME "hsgmii_lan" +#define DRIVER_NAME_LEN 20 +#define HSGMII_INDEX 2 + /* Not defined in Econet library */ ECNT_SWITCHMGR_RET switchmgr_lib_get_port_link_state(u8 port, ECNT_SWITCHMGR_LINK_STATE *p_link_state, ECNT_SWITCHMGR_LINK_SPEED *p_speed); +static int get_drv_info_by_ifname(char *ifname, char *buffer) +{ + int fd; + int ret = -1; + struct ifreq ifr; + struct ethtool_drvinfo info; + + if (ifname == NULL || buffer == NULL) + return ret; + + fd = socket(AF_INET, SOCK_DGRAM, 0); + if (fd < 0) + return ret; + + memset(&info, 0, sizeof(info)); + info.cmd = ETHTOOL_GDRVINFO; + + memset(&ifr, 0, sizeof(ifr)); + strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name) - 1); + ifr.ifr_data = (void *)&info; + + if (ioctl(fd, SIOCETHTOOL, &ifr) != 0) + goto exit; + + strcpy(buffer, info.driver); + ret = 0; + +exit: + close(fd); + return ret; +} + + +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; + ECNT_FEMGR_GDMA2_RX_STATISTICS rx_stats; + + char driver_name[DRIVER_NAME_LEN]; + 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)) { + + 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_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; + } + } + return 0; + } + return -1; +} + + + int ecnt_prvt_get_port_statistics(uint32_t port, struct eth_stats *stats, struct eth_rmon_stats *rstats) diff --git a/econet/econet.c b/econet/econet.c index 024c09701c2838542f16841d0edd848f0e9dd5b5..42cc04f3b315f2b0b3e893f32f4abe662b55a810 100644 --- a/econet/econet.c +++ b/econet/econet.c @@ -64,6 +64,10 @@ 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)) { + return 0; + } libethernet_err("invalid port name: %s\n", ifname); return -1; } @@ -82,6 +86,12 @@ int econet_eth_get_rmon_stats(const char *ifname, struct eth_rmon_stats *rstats) port_num = ecnt_prvt_get_port_num(ifname); if (port_num == ECNT_PRVT_PORT_NUM_INVALID) { + + /* Check and fetch rstats if the Interface belongs to hsgmii_lan driver */ + if (!hsgmii_lan_prvt_get_port_statistics(ifname, NULL, rstats)) { + return 0; + } + libethernet_err("invalid port name: %s\n", ifname); return -1; }