From 21f8ec982af3d31b8f59499db1a992a15301e621 Mon Sep 17 00:00:00 2001
From: Artee Roy <a.roy@gxgroup.eu>
Date: Wed, 16 Nov 2022 16:32:05 +0530
Subject: [PATCH] libethernet: Support for 64 bit counters.

---
 bcm/bcm.c  | 26 ++++++++++++++++----------
 ethernet.h | 30 +++++++++++++++---------------
 2 files changed, 31 insertions(+), 25 deletions(-)

diff --git a/bcm/bcm.c b/bcm/bcm.c
index e475dd0..3e410fc 100644
--- a/bcm/bcm.c
+++ b/bcm/bcm.c
@@ -222,14 +222,14 @@ int bcm_eth_reset_phy(const char *name, int phy_id)
 
 static int bcm_eth_get_stats_from_proc(const char *ifname, struct eth_stats *s)
 {
-	unsigned long rx_bytes, rx_packets, rx_err, rx_drop;
-	unsigned long rx_fifo, rx_frame, rx_comp, rx_multi;
-	unsigned long tx_bytes, tx_packets, tx_err, tx_drop;
-	unsigned long tx_fifo, tx_coll, tx_carr, tx_comp;
-	unsigned long tx_mcast_packets = 0, rx_mcast_bytes = 0, tx_mcast_bytes = 0;
-	unsigned long rx_ucast_packets = 0, tx_ucast_packets = 0;
-	unsigned long rx_bcast_packets = 0, tx_bcast_packets = 0;
-	unsigned long rx_err_unknown = 0;
+	uint64_t rx_bytes, rx_packets, rx_err, rx_drop;
+	uint64_t rx_fifo, rx_frame, rx_comp, rx_multi;
+	uint64_t tx_bytes, tx_packets, tx_err, tx_drop;
+	uint64_t tx_fifo, tx_coll, tx_carr, tx_comp;
+	uint64_t tx_mcast_packets = 0, rx_mcast_bytes = 0, tx_mcast_bytes = 0;
+	uint64_t rx_ucast_packets = 0, tx_ucast_packets = 0;
+	uint64_t rx_bcast_packets = 0, tx_bcast_packets = 0;
+	uint64_t rx_err_unknown = 0;
 	char cmdbuf[512] = {0};
 	char *ptr;
 	int ret;
@@ -243,8 +243,14 @@ static int bcm_eth_get_stats_from_proc(const char *ifname, struct eth_stats *s)
 
 	ptr = cmdbuf + strlen(ifname) + strlen(":");
 	ret = sscanf(ptr,
-		" %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu"
-		" %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu",
+		" %" SCNu64 " %" SCNu64 " %" SCNu64 " %" SCNu64
+		" %" SCNu64 " %" SCNu64 " %" SCNu64 " %" SCNu64
+		" %" SCNu64 " %" SCNu64 " %" SCNu64 " %" SCNu64
+		" %" SCNu64 " %" SCNu64 " %" SCNu64 " %" SCNu64
+		" %" SCNu64 " %" SCNu64 " %" SCNu64
+		" %" SCNu64 " %" SCNu64
+		" %" SCNu64 " %" SCNu64
+		" %" SCNu64,
 		&rx_bytes, &rx_packets, &rx_err, &rx_drop,
 		&rx_fifo, &rx_frame, &rx_comp, &rx_multi,
 		&tx_bytes, &tx_packets, &tx_err, &tx_drop,
diff --git a/ethernet.h b/ethernet.h
index 0116428..540aa0a 100644
--- a/ethernet.h
+++ b/ethernet.h
@@ -109,21 +109,21 @@ enum eth_callstatus {
 };
 
 struct eth_stats {
-	unsigned long tx_bytes;
-	unsigned long rx_bytes;
-	unsigned long tx_packets;
-	unsigned long rx_packets;
-	uint32_t tx_errors;                 /* error packets */
-	uint32_t rx_errors;
-	unsigned long tx_ucast_packets;     /* unicast packets */
-	unsigned long rx_ucast_packets;
-	unsigned long tx_mcast_packets;     /* multicast packets */
-	unsigned long rx_mcast_packets;
-	unsigned long tx_bcast_packets;     /* broadcast packets */
-	unsigned long rx_bcast_packets;
-	uint32_t tx_discard_packets;        /* no error packets dropped */
-	uint32_t rx_discard_packets;        /* no error packets dropped */
-	uint32_t rx_unknown_packets;        /* unknown protocol packets */
+	uint64_t tx_bytes;
+	uint64_t rx_bytes;
+	uint64_t tx_packets;
+	uint64_t rx_packets;
+	uint64_t tx_errors;                 /* error packets */
+	uint64_t rx_errors;
+	uint64_t tx_ucast_packets;     /* unicast packets */
+	uint64_t rx_ucast_packets;
+	uint64_t tx_mcast_packets;     /* multicast packets */
+	uint64_t rx_mcast_packets;
+	uint64_t tx_bcast_packets;     /* broadcast packets */
+	uint64_t rx_bcast_packets;
+	uint64_t tx_discard_packets;        /* no error packets dropped */
+	uint64_t rx_discard_packets;        /* no error packets dropped */
+	uint64_t rx_unknown_packets;        /* unknown protocol packets */
 };
 
 /* struct eth_vlan - vlan over eth_link */
-- 
GitLab