From be00aa9bd064d1defd94e78835249d0ca04c0440 Mon Sep 17 00:00:00 2001
From: Markus Gothe <markus.gothe@genexis.eu>
Date: Sun, 21 Apr 2024 15:30:18 +0200
Subject: [PATCH] econet: Handle unbound HSGMII LAN interfaces.

---
 econet/ecnt_prvt.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/econet/ecnt_prvt.c b/econet/ecnt_prvt.c
index 12c537f..a37fb49 100644
--- a/econet/ecnt_prvt.c
+++ b/econet/ecnt_prvt.c
@@ -212,6 +212,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;
+		char cmdbuf[512] = {0};
 
 		for (; i < ARRAY_SIZE(hsgmii_lookup_tbl); i++) {
 			int j = 0;
@@ -235,6 +236,11 @@ int hsgmii_lan_prvt_get_port_statistics(char *ifname, struct eth_stats *stats, s
 		memset(&tx_stats, 0, sizeof(ECNT_FEMGR_GDMA2_TX_STATISTICS));
 		memset(&rx_stats, 0, sizeof(ECNT_FEMGR_GDMA2_RX_STATISTICS));
 
+		/* Handle unbound interface statistics */
+		chrCmd(cmdbuf, sizeof(cmdbuf), "cat /proc/tc3162/%s_rebind | awk '{ print $3 }'", ifname);
+		if (cmdbuf[0] != '\0' && strtoul(cmdbuf, NULL, 0) == 1)
+			return 0;
+
 		if (!fe_lib_get_hsgmii_tx_statistics(&tx_stats, hsgmii_index)) {
 			fill_stats_tx_from_gdma(stats, rstats, &tx_stats);
 		}
-- 
GitLab