From f01169d8c6ded59c98e83ba9bf7e13de5165c1bd Mon Sep 17 00:00:00 2001
From: Jan-Tarek Butt <tarek@ring0.de>
Date: Mon, 2 Nov 2020 21:11:15 +0100
Subject: [PATCH] gluon_patches: add ath deaf detection

Signed-off-by: Jan-Tarek Butt <tarek@ring0.de>
---
 gluon_patches/0001-add-gluon-geolocator.patch |   4 +-
 ...ation-from-gluon-node-info-to-geoloc.patch |   4 +-
 ...03-hoodselector-to-domain-migration.patch} |   4 +-
 ...add-0016-ath9k-check-for-deaf-rx-pat.patch | 147 ++++++++++++++++++
 4 files changed, 153 insertions(+), 6 deletions(-)
 rename gluon_patches/{0004-hoodselector-to-domain-migration.patch => 0003-hoodselector-to-domain-migration.patch} (93%)
 create mode 100644 gluon_patches/0004-patches-openwrt-add-0016-ath9k-check-for-deaf-rx-pat.patch

diff --git a/gluon_patches/0001-add-gluon-geolocator.patch b/gluon_patches/0001-add-gluon-geolocator.patch
index dbe3fa0..04a65d3 100644
--- a/gluon_patches/0001-add-gluon-geolocator.patch
+++ b/gluon_patches/0001-add-gluon-geolocator.patch
@@ -1,7 +1,7 @@
-From 9f696624c92d853ef2717d788f170dd221e6bc84 Mon Sep 17 00:00:00 2001
+From 28944a798cdd929f3b87f18112fcf7b3c2c4c442 Mon Sep 17 00:00:00 2001
 From: runner01 <runner01@ffnw.de>
 Date: Fri, 8 Feb 2019 04:43:50 +0100
-Subject: [PATCH 1/6] add gluon-geolocator
+Subject: [PATCH 1/4] add gluon-geolocator
 
 ---
  package/gluon-geolocator/Makefile             |  14 ++
diff --git a/gluon_patches/0002-ffnw-config-migration-from-gluon-node-info-to-geoloc.patch b/gluon_patches/0002-ffnw-config-migration-from-gluon-node-info-to-geoloc.patch
index 74efe99..1b6d70f 100644
--- a/gluon_patches/0002-ffnw-config-migration-from-gluon-node-info-to-geoloc.patch
+++ b/gluon_patches/0002-ffnw-config-migration-from-gluon-node-info-to-geoloc.patch
@@ -1,7 +1,7 @@
-From a0dace39f87ef109ebb7c53f442cc7c1f25563bb Mon Sep 17 00:00:00 2001
+From 71bcf5add0180cda356f6c9ce69e2a676e4daba6 Mon Sep 17 00:00:00 2001
 From: Jan-Tarek Butt <tarek@ring0.de>
 Date: Sun, 25 Feb 2018 08:42:42 +0100
-Subject: [PATCH 2/6] ffnw config migration from gluon-node-info to geolocator
+Subject: [PATCH 2/4] ffnw config migration from gluon-node-info to geolocator
 
 Signed-off-by: Jan-Tarek Butt <tarek@ring0.de>
 ---
diff --git a/gluon_patches/0004-hoodselector-to-domain-migration.patch b/gluon_patches/0003-hoodselector-to-domain-migration.patch
similarity index 93%
rename from gluon_patches/0004-hoodselector-to-domain-migration.patch
rename to gluon_patches/0003-hoodselector-to-domain-migration.patch
index 58d6aee..18b148e 100644
--- a/gluon_patches/0004-hoodselector-to-domain-migration.patch
+++ b/gluon_patches/0003-hoodselector-to-domain-migration.patch
@@ -1,7 +1,7 @@
-From 6ea8b47ee5d30663fdaef97e9797b8eaab9d5ffb Mon Sep 17 00:00:00 2001
+From a273489a54d14454e6e53af94ab479b7c72f74d2 Mon Sep 17 00:00:00 2001
 From: runner01 <runner01@ffnw.de>
 Date: Mon, 18 Mar 2019 21:29:26 +0100
-Subject: [PATCH 4/6] hoodselector to domain migration
+Subject: [PATCH 3/4] hoodselector to domain migration
 
 Domain migration: restart services after migration
 
diff --git a/gluon_patches/0004-patches-openwrt-add-0016-ath9k-check-for-deaf-rx-pat.patch b/gluon_patches/0004-patches-openwrt-add-0016-ath9k-check-for-deaf-rx-pat.patch
new file mode 100644
index 0000000..d3a13f5
--- /dev/null
+++ b/gluon_patches/0004-patches-openwrt-add-0016-ath9k-check-for-deaf-rx-pat.patch
@@ -0,0 +1,147 @@
+From 16e48445555a8597a7d6dde41138dff4bc66d139 Mon Sep 17 00:00:00 2001
+From: Jan-Tarek Butt <tarek@ring0.de>
+Date: Sat, 5 Sep 2020 11:45:57 +0200
+Subject: [PATCH 4/4] patches/openwrt: add
+ 0016-ath9k-check-for-deaf-rx-path-state.patch to fix 0% bug on meshlinks
+
+Signed-off-by: Jan-Tarek Butt <tarek@ring0.de>
+---
+ ...6-ath9k-check-for-deaf-rx-path-state.patch | 126 ++++++++++++++++++
+ 1 file changed, 126 insertions(+)
+ create mode 100644 patches/openwrt/0016-ath9k-check-for-deaf-rx-path-state.patch
+
+diff --git a/patches/openwrt/0016-ath9k-check-for-deaf-rx-path-state.patch b/patches/openwrt/0016-ath9k-check-for-deaf-rx-path-state.patch
+new file mode 100644
+index 00000000..1c200536
+--- /dev/null
++++ b/patches/openwrt/0016-ath9k-check-for-deaf-rx-path-state.patch
+@@ -0,0 +1,126 @@
++From: Jan-Tarek Butt <tarek@ring0.de>
++Date: Sat, 5 Sep 2020 11:18:59 +0200
++Subject: ath9k: check for deaf rx path state
++
++Various chips occasionally run into a state where the tx path still
++appears to be working normally, but the rx path is deaf.
++
++There is no known register signature to check for this state explicitly,
++so use the lack of rx interrupts as an indicator.
++
++This detection is prone to false positives, since a device could also
++simply be in an environment where there are no frames on the air.
++However, in this case doing a reset should be harmless since it's
++obviously not interrupting any real activity. To avoid confusion, call
++the reset counters in this case "Rx path inactive" instead of something
++like "Rx path deaf", since it may not be an indication of a real
++hardware failure.
++
++Signed-off-by: Jan-Tarek Butt <tarek@ring0.de>
++
++diff --git a/package/kernel/mac80211/patches/ath/359-ath9k-check-for-deaf-rx-path-state.patch b/package/kernel/mac80211/patches/ath/359-ath9k-check-for-deaf-rx-path-state.patch
++new file mode 100644
++index 0000000000000000000000000000000000000000..347d06ec888c56102523ed40b38aa4b5083d4c9c
++--- /dev/null
+++++ b/package/kernel/mac80211/patches/ath/359-ath9k-check-for-deaf-rx-path-state.patch
++@@ -0,0 +1,100 @@
+++From: Felix Fietkau <nbd@nbd.name>
+++Date: Wed, 25 Jan 2017 13:00:58 +0100
+++Subject: [PATCH] ath9k: check for deaf rx path state
+++
+++Various chips occasionally run into a state where the tx path still
+++appears to be working normally, but the rx path is deaf.
+++
+++There is no known register signature to check for this state explicitly,
+++so use the lack of rx interrupts as an indicator.
+++
+++This detection is prone to false positives, since a device could also
+++simply be in an environment where there are no frames on the air.
+++However, in this case doing a reset should be harmless since it's
+++obviously not interrupting any real activity. To avoid confusion, call
+++the reset counters in this case "Rx path inactive" instead of something
+++like "Rx path deaf", since it may not be an indication of a real
+++hardware failure.
+++
+++Signed-off-by: Felix Fietkau <nbd@nbd.name>
+++---
+++
+++--- a/drivers/net/wireless/ath/ath9k/ath9k.h
++++++ b/drivers/net/wireless/ath/ath9k/ath9k.h
+++@@ -1027,6 +1027,7 @@ struct ath_softc {
+++ 
+++ 	u8 gtt_cnt;
+++ 	u32 intrstatus;
++++	u32 rx_active;
+++ 	u16 ps_flags; /* PS_* */
+++ 	bool ps_enabled;
+++ 	bool ps_idle;
+++--- a/drivers/net/wireless/ath/ath9k/debug.c
++++++ b/drivers/net/wireless/ath/ath9k/debug.c
+++@@ -763,6 +763,7 @@ static int read_file_reset(struct seq_fi
+++ 		[RESET_TYPE_BEACON_STUCK] = "Stuck Beacon",
+++ 		[RESET_TYPE_MCI] = "MCI Reset",
+++ 		[RESET_TYPE_CALIBRATION] = "Calibration error",
++++		[RESET_TYPE_RX_INACTIVE] = "Rx path inactive",
+++ 		[RESET_TX_DMA_ERROR] = "Tx DMA stop error",
+++ 		[RESET_RX_DMA_ERROR] = "Rx DMA stop error",
+++ 	};
+++--- a/drivers/net/wireless/ath/ath9k/debug.h
++++++ b/drivers/net/wireless/ath/ath9k/debug.h
+++@@ -50,6 +50,7 @@ enum ath_reset_type {
+++ 	RESET_TYPE_BEACON_STUCK,
+++ 	RESET_TYPE_MCI,
+++ 	RESET_TYPE_CALIBRATION,
++++	RESET_TYPE_RX_INACTIVE,
+++ 	RESET_TX_DMA_ERROR,
+++ 	RESET_RX_DMA_ERROR,
+++ 	__RESET_TYPE_MAX
+++--- a/drivers/net/wireless/ath/ath9k/link.c
++++++ b/drivers/net/wireless/ath/ath9k/link.c
+++@@ -53,13 +53,27 @@ reset:
+++ 
+++ }
+++ 
++++static bool ath_rx_active_check(struct ath_softc *sc)
++++{
++++	if (sc->rx_active) {
++++		sc->rx_active = 0;
++++		return true;
++++	}
++++
++++	ath_dbg(ath9k_hw_common(sc->sc_ah), RESET,
++++		"rx path inactive, resetting the chip\n");
++++	ath9k_queue_reset(sc, RESET_TYPE_RX_INACTIVE);
++++	return false;
++++}
++++
+++ void ath_hw_check_work(struct work_struct *work)
+++ {
+++ 	struct ath_softc *sc = container_of(work, struct ath_softc,
+++ 					    hw_check_work.work);
+++ 
+++ 	if (!ath_hw_check(sc) ||
+++-	    !ath_tx_complete_check(sc))
++++	    !ath_tx_complete_check(sc) ||
++++	    !ath_rx_active_check(sc))
+++ 		return;
+++ 
+++ 	ieee80211_queue_delayed_work(sc->hw, &sc->hw_check_work,
+++--- a/drivers/net/wireless/ath/ath9k/main.c
++++++ b/drivers/net/wireless/ath/ath9k/main.c
+++@@ -269,6 +269,7 @@ static bool ath_complete_reset(struct at
+++ 	}
+++ 
+++ 	sc->gtt_cnt = 0;
++++	sc->rx_active = 1;
+++ 
+++ 	ath9k_hw_set_interrupts(ah);
+++ 	ath9k_hw_enable_interrupts(ah);
+++@@ -452,6 +453,7 @@ void ath9k_tasklet(unsigned long data)
+++ 			ath_rx_tasklet(sc, 0, true);
+++ 
+++ 		ath_rx_tasklet(sc, 0, false);
++++		sc->rx_active = 1;
+++ 	}
+++ 
+++ 	if (status & ATH9K_INT_TX) {
+-- 
+2.20.1
+
-- 
GitLab