Skip to content

Commit b305a6a

Browse files
Stanislaw GruszkaKalle Valo
authored andcommitted
mt7601u: use EWMA to calculate avg_rssi
avr_rssi is not calculated correctly as we do not divide result by 256 (mt76 sum avg_rssi1 and avg_rssi2 and divide by 512). However dividing by 256 will make avg_rssi almost the same as last rssi value - not really an average. So use EWMA to calculate avg_rssi. I've chosen weight_rcp=4 to convergence quicker on signal strength changes. Signed-off-by: Stanislaw Gruszka <[email protected]> Acked-by: Jakub Kicinski <[email protected]> Signed-off-by: Kalle Valo <[email protected]>
1 parent b9e5d4f commit b305a6a

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

drivers/net/wireless/mediatek/mt7601u/mac.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ mt7601u_rx_monitor_beacon(struct mt7601u_dev *dev, struct mt7601u_rxwi *rxwi,
453453
{
454454
dev->bcn_freq_off = rxwi->freq_off;
455455
dev->bcn_phy_mode = FIELD_GET(MT_RXWI_RATE_PHY, rate);
456-
dev->avg_rssi = (dev->avg_rssi * 15) / 16 + (rssi << 8);
456+
ewma_rssi_add(&dev->avg_rssi, -rssi);
457457
}
458458

459459
static int
@@ -503,7 +503,7 @@ u32 mt76_mac_process_rx(struct mt7601u_dev *dev, struct sk_buff *skb,
503503
if (mt7601u_rx_is_our_beacon(dev, data))
504504
mt7601u_rx_monitor_beacon(dev, rxwi, rate, rssi);
505505
else if (rxwi->rxinfo & cpu_to_le32(MT_RXINFO_U2M))
506-
dev->avg_rssi = (dev->avg_rssi * 15) / 16 + (rssi << 8);
506+
ewma_rssi_add(&dev->avg_rssi, -rssi);
507507
spin_unlock_bh(&dev->con_mon_lock);
508508

509509
return len;

drivers/net/wireless/mediatek/mt7601u/mt7601u.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <linux/completion.h>
2424
#include <net/mac80211.h>
2525
#include <linux/debugfs.h>
26+
#include <linux/average.h>
2627

2728
#include "regs.h"
2829

@@ -138,6 +139,8 @@ enum {
138139
MT7601U_STATE_MORE_STATS,
139140
};
140141

142+
DECLARE_EWMA(rssi, 10, 4);
143+
141144
/**
142145
* struct mt7601u_dev - adapter structure
143146
* @lock: protects @wcid->tx_rate.
@@ -220,7 +223,7 @@ struct mt7601u_dev {
220223
s8 bcn_freq_off;
221224
u8 bcn_phy_mode;
222225

223-
int avg_rssi; /* starts at 0 and converges */
226+
struct ewma_rssi avg_rssi;
224227

225228
u8 agc_save;
226229

drivers/net/wireless/mediatek/mt7601u/phy.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -975,6 +975,7 @@ void mt7601u_agc_restore(struct mt7601u_dev *dev)
975975
static void mt7601u_agc_tune(struct mt7601u_dev *dev)
976976
{
977977
u8 val = mt7601u_agc_default(dev);
978+
long avg_rssi;
978979

979980
if (test_bit(MT7601U_STATE_SCANNING, &dev->state))
980981
return;
@@ -984,9 +985,12 @@ static void mt7601u_agc_tune(struct mt7601u_dev *dev)
984985
* Rssi updates are only on beacons and U2M so should work...
985986
*/
986987
spin_lock_bh(&dev->con_mon_lock);
987-
if (dev->avg_rssi <= -70)
988+
avg_rssi = ewma_rssi_read(&dev->avg_rssi);
989+
WARN_ON_ONCE(avg_rssi == 0);
990+
avg_rssi = -avg_rssi;
991+
if (avg_rssi <= -70)
988992
val -= 0x20;
989-
else if (dev->avg_rssi <= -60)
993+
else if (avg_rssi <= -60)
990994
val -= 0x10;
991995
spin_unlock_bh(&dev->con_mon_lock);
992996

@@ -1102,7 +1106,7 @@ void mt7601u_phy_con_cal_onoff(struct mt7601u_dev *dev,
11021106
/* Start/stop collecting beacon data */
11031107
spin_lock_bh(&dev->con_mon_lock);
11041108
ether_addr_copy(dev->ap_bssid, info->bssid);
1105-
dev->avg_rssi = 0;
1109+
ewma_rssi_init(&dev->avg_rssi);
11061110
dev->bcn_freq_off = MT_FREQ_OFFSET_INVALID;
11071111
spin_unlock_bh(&dev->con_mon_lock);
11081112

0 commit comments

Comments
 (0)