Revert "CHROMIUM: mesh: Update mesh metric calculation to upstream"

This reverts commit 669eb3b4ccc2dbfa5fb43be09b2693cf7b5a2165.

Reason for revert: The Mesh link broken logs shooted up from fleet wide dashboard after pushing this Cl, for further investigation, reverting this CL and observing the Mesh link broken signals on the fleet wide.

Original change's description:
> CHROMIUM: mesh: Update mesh metric calculation to upstream
>
> Move mesh metric calculation to upstream logic to align with
> latest sync
>
> Change-Id: I77af55ec8d5dd43033adbeb05df797bf37c88ccb
> Signed-off-by: Tamizh Chelvam <tamizhr@codeaurora.org>
> Signed-off-by: Maharaja Kennadyrajan <mkenna@codeaurora.org>
> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/kernel/+/2391021
> Reviewed-by: Julan Hsu <julanhsu@google.com>
> Commit-Queue: Julan Hsu <julanhsu@google.com>
> Commit-Queue: Srinivasa duvvuri <sduvvuri@google.com>
> Tested-by: Srinivasa duvvuri <sduvvuri@google.com>

BUG=b:181670526

Change-Id: I59ece4dc46fb810a931aabd7bc4067cec72b3f9e
Signed-off-by: Dheeraj Kaniyala Melinapanja <dmelinapanja@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/kernel/+/2732408
Reviewed-by: Tamizh Raja <tamizhr@qualcomm.corp-partner.google.com>
Reviewed-by: Srinivasa duvvuri <sduvvuri@google.com>
Commit-Queue: Srinivasa duvvuri <sduvvuri@google.com>
Tested-by: Srinivasa duvvuri <sduvvuri@google.com>
(cherry picked from commit fd781b4ea215e222373da6f690e089c8d93f338d)
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/kernel/+/2746708
Auto-Submit: Srinivasa duvvuri <sduvvuri@google.com>
diff --git a/net/mac80211-4.2/mesh_hwmp.c b/net/mac80211-4.2/mesh_hwmp.c
index ac6127e..4529769 100644
--- a/net/mac80211-4.2/mesh_hwmp.c
+++ b/net/mac80211-4.2/mesh_hwmp.c
@@ -18,8 +18,6 @@
 #define MAX_METRIC	0xffffffff
 #define ARITH_SHIFT	8
 
-#define LINK_FAIL_THRESH 95
-
 #define MAX_PREQ_QUEUE_LEN	64
 
 /* minimum link metric averaging time constant in milliseconds */
@@ -337,10 +335,14 @@
 		struct sta_info *sta, struct sk_buff *skb, int retry_count)
 {
 	struct ieee80211_tx_info *txinfo = IEEE80211_SKB_CB(skb);
+	struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
 	int failed;
 	struct rate_info rinfo;
 	unsigned long delta;
 
+	if (!ieee80211_is_data(hdr->frame_control))
+		return;
+
 	failed = !(txinfo->flags & IEEE80211_TX_STAT_ACK);
 
 	if (failed) {
@@ -355,8 +357,10 @@
 	}
 
 	/* moving average, scaled to 100 */
-	ewma_add(&sta->mesh->fail_avg, failed * 100);
-	if (ewma_read(&sta->mesh->fail_avg) > LINK_FAIL_THRESH)
+	sta->mesh->fail_avg =
+		((80 * sta->mesh->fail_avg + 5) / 100 +
+		 20 * (retry_count + failed) / (retry_count + 1));
+	if (sta->mesh->fail_avg > 95)
 		mesh_plink_broken(sta);
 
 	/* bitrate, in units of 100 Kbps */
@@ -397,14 +401,9 @@
 	u64 result;
 	u32 bitrate_avg;
 	struct rate_info rinfo;
-	unsigned long fail_avg =
-		ewma_read(&sta->mesh->fail_avg);
 
-	if (fail_avg > LINK_FAIL_THRESH) {
-		pr_warn("Fail average(%lu) exceeds the fail threshold(95)\n",
-			fail_avg);
+	if (sta->mesh->fail_avg >= 100)
 		return MAX_METRIC;
-	}
 
 	if (!sta->mesh->bitrate_avg) {
 		sta_set_rate_info_tx(sta, &sta->last_tx_rate, &rinfo);
@@ -417,7 +416,7 @@
 	}
 
 	bitrate_avg = sta->mesh->bitrate_avg;
-	err = (fail_avg << ARITH_SHIFT) / 100;
+	err = (sta->mesh->fail_avg << ARITH_SHIFT) / 100;
 
 #ifdef CONFIG_MAC80211_DEBUGFS
 /* signal strength in db below witch the rate remains at 6Mbps */
@@ -646,9 +645,6 @@
 			mpath->hop_count = hopcount;
 			mesh_path_activate(mpath);
 			spin_unlock_bh(&mpath->state_lock);
-			ewma_init(&sta->mesh->fail_avg, 16, 8);
-			/* init it at a low value - 0 start is tricky */
-			ewma_add(&sta->mesh->fail_avg, 1);
 			mesh_path_tx_pending(mpath);
 			/* draft says preq_id should be saved to, but there does
 			 * not seem to be any use for it, skipping by now
@@ -708,9 +704,6 @@
 			mpath->hop_count = 1;
 			mesh_path_activate(mpath);
 			spin_unlock_bh(&mpath->state_lock);
-			ewma_init(&sta->mesh->fail_avg, 16, 8);
-			/* init it at a low value - 0 start is tricky */
-			ewma_add(&sta->mesh->fail_avg, 1);
 			mesh_path_tx_pending(mpath);
 		} else
 			spin_unlock_bh(&mpath->state_lock);
diff --git a/net/mac80211-4.2/mesh_pathtbl.c b/net/mac80211-4.2/mesh_pathtbl.c
index 8a5c5bd..a6d638f 100644
--- a/net/mac80211-4.2/mesh_pathtbl.c
+++ b/net/mac80211-4.2/mesh_pathtbl.c
@@ -1179,9 +1179,6 @@
 	mpath->flags = (MESH_PATH_FIXED | MESH_PATH_SN_VALID);
 	mesh_path_activate(mpath);
 	spin_unlock_bh(&mpath->state_lock);
-	ewma_init(&next_hop->mesh->fail_avg, 16, 8);
-	/* init it at a low value - 0 start is tricky */
-	ewma_add(&next_hop->mesh->fail_avg, 1);
 	mesh_path_tx_pending(mpath);
 }
 
diff --git a/net/mac80211-4.2/sta_info.h b/net/mac80211-4.2/sta_info.h
index c52bfb1..5954aa0 100644
--- a/net/mac80211-4.2/sta_info.h
+++ b/net/mac80211-4.2/sta_info.h
@@ -330,7 +330,7 @@
 	u8 tx_fail_log;
 
 	/* moving percentage of failed MSDUs */
-	struct ewma fail_avg;
+	unsigned int fail_avg;
 
 	/* moving avg of bitrate in 1kbps */
 	u32 bitrate_avg;