From d77c861208a47d8c6864ade7039c9cdfa978fd32 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Fri, 11 Jan 2019 14:17:30 +0100 Subject: [PATCH] mt76: fix rssi ewma tracking The generic EWMA code cannot deal with negative numbers, so convert signal to a positive number before adding it Fixes mt76x2 AGC tuning Signed-off-by: Felix Fietkau --- mac80211.c | 4 +++- util.c | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/mac80211.c b/mac80211.c index 3830455c..d7aad013 100644 --- a/mac80211.c +++ b/mac80211.c @@ -564,7 +564,9 @@ mt76_check_sta(struct mt76_dev *dev, struct sk_buff *skb) sta = container_of((void *) wcid, struct ieee80211_sta, drv_priv); - ewma_signal_add(&wcid->rssi, status->signal); + if (status->signal <= 0) + ewma_signal_add(&wcid->rssi, -status->signal); + wcid->inactive_count = 0; if (!test_bit(MT_WCID_FLAG_CHECK_PS, &wcid->flags)) diff --git a/util.c b/util.c index 6242421c..69270c1a 100644 --- a/util.c +++ b/util.c @@ -100,7 +100,7 @@ int mt76_get_min_avg_rssi(struct mt76_dev *dev) spin_lock(&dev->rx_lock); if (wcid->inactive_count++ < 5) - cur_rssi = ewma_signal_read(&wcid->rssi); + cur_rssi = -ewma_signal_read(&wcid->rssi); else cur_rssi = 0; spin_unlock(&dev->rx_lock);