diff mbox series

[6/7] mt76: measure the time between mt76x02_edcca_check runs

Message ID 20190207134723.59163-6-nbd@nbd.name (mailing list archive)
State Accepted
Delegated to: Kalle Valo
Headers show
Series [1/7] mt76: fix software encryption issues | expand

Commit Message

Felix Fietkau Feb. 7, 2019, 1:47 p.m. UTC
Based on system load and time needed by other calibration runs, the time
between dev->mac_work runs can vary quite a bit.
Calculate busy time based on the actual time difference in order to avoid
potentially over-estimating busy time, which could lead to unnecessary tx
blocking.

Signed-off-by: Felix Fietkau <nbd@nbd.name>
---
 drivers/net/wireless/mediatek/mt76/mt76x02.h     |  1 +
 drivers/net/wireless/mediatek/mt76/mt76x02_mac.c | 11 +++++++++--
 2 files changed, 10 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02.h b/drivers/net/wireless/mediatek/mt76/mt76x02.h
index 7e405297028f..3464b4ca2ea8 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x02.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76x02.h
@@ -117,6 +117,7 @@  struct mt76x02_dev {
 	bool ed_monitor;
 	u8 ed_trigger;
 	u8 ed_silent;
+	ktime_t ed_time;
 };
 
 extern struct ieee80211_rate mt76x02_rates[12];
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_mac.c b/drivers/net/wireless/mediatek/mt76/mt76x02_mac.c
index aecf514bb89b..462ac030c08a 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x02_mac.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x02_mac.c
@@ -922,6 +922,7 @@  void mt76x02_edcca_init(struct mt76x02_dev *dev, bool enable)
 
 	/* clear previous CCA timer value */
 	mt76_rr(dev, MT_ED_CCA_TIMER);
+	dev->ed_time = ktime_get_boottime();
 }
 EXPORT_SYMBOL_GPL(mt76x02_edcca_init);
 
@@ -929,10 +930,16 @@  EXPORT_SYMBOL_GPL(mt76x02_edcca_init);
 #define MT_EDCCA_BLOCK_TH	2
 static void mt76x02_edcca_check(struct mt76x02_dev *dev)
 {
-	u32 val, busy;
+	ktime_t cur_time;
+	u32 active, val, busy;
 
+	cur_time = ktime_get_boottime();
 	val = mt76_rr(dev, MT_ED_CCA_TIMER);
-	busy = (val * 100) / jiffies_to_usecs(MT_MAC_WORK_INTERVAL);
+
+	active = ktime_to_us(ktime_sub(cur_time, dev->ed_time));
+	dev->ed_time = cur_time;
+
+	busy = (val * 100) / active;
 	busy = min_t(u32, busy, 100);
 
 	if (busy > MT_EDCCA_TH) {