diff --git a/mt76x2.h b/mt76x2.h index 21de1168..ba17fbed 100644 --- a/mt76x2.h +++ b/mt76x2.h @@ -27,6 +27,7 @@ #include #include #include +#include #define MT7662_FIRMWARE "mt7662.bin" #define MT7662_ROM_PATCH "mt7662_rom_patch.bin" @@ -47,6 +48,8 @@ #include "mt76x2_mac.h" #include "mt76x2_dfs.h" +DECLARE_EWMA(signal, 10, 8) + struct mt76x2_mcu { struct mutex mutex; @@ -66,13 +69,14 @@ struct mt76x2_rx_freq_cal { struct mt76x2_calibration { struct mt76x2_rx_freq_cal rx; + struct ewma_signal rssi; + u32 rssi_count; + u8 agc_gain_init[MT_MAX_CHAINS]; u8 agc_gain_cur[MT_MAX_CHAINS]; - int avg_rssi[MT_MAX_CHAINS]; - int avg_rssi_all; - u16 false_cca; + s8 avg_rssi_all; s8 agc_gain_adjust; s8 low_gain; diff --git a/mt76x2_init.c b/mt76x2_init.c index 143e53f3..e597acec 100644 --- a/mt76x2_init.c +++ b/mt76x2_init.c @@ -657,6 +657,7 @@ struct mt76x2_dev *mt76x2_alloc_device(struct device *pdev) mdev->drv = &drv_ops; mutex_init(&dev->mutex); spin_lock_init(&dev->irq_lock); + ewma_signal_init(&dev->cal.rssi); return dev; } diff --git a/mt76x2_mac.c b/mt76x2_mac.c index 8ddc03b8..ebe5ea3f 100644 --- a/mt76x2_mac.c +++ b/mt76x2_mac.c @@ -374,6 +374,11 @@ int mt76x2_mac_process_rx(struct mt76x2_dev *dev, struct sk_buff *skb, status->tid = FIELD_GET(MT_RXWI_TID, tid_sn); status->seqno = FIELD_GET(MT_RXWI_SN, tid_sn); + if (unicast) { + ewma_signal_add(&dev->cal.rssi, status->signal); + dev->cal.rssi_count++; + } + return mt76x2_mac_process_rate(status, rate); } diff --git a/mt76x2_phy.c b/mt76x2_phy.c index 94943aeb..cc874e6e 100644 --- a/mt76x2_phy.c +++ b/mt76x2_phy.c @@ -502,19 +502,20 @@ mt76x2_phy_adjust_vga_gain(struct mt76x2_dev *dev) static void mt76x2_phy_update_channel_gain(struct mt76x2_dev *dev) { - u32 val = mt76_rr(dev, MT_BBP(AGC, 20)); - int rssi0 = (s8) FIELD_GET(MT_BBP_AGC20_RSSI0, val); - int rssi1 = (s8) FIELD_GET(MT_BBP_AGC20_RSSI1, val); u8 *gain = dev->cal.agc_gain_init; u8 gain_delta; int low_gain; + u32 rssi_count; + u32 val; - dev->cal.avg_rssi[0] = (dev->cal.avg_rssi[0] * 15) / 16 + - (rssi0 << 8) / 16; - dev->cal.avg_rssi[1] = (dev->cal.avg_rssi[1] * 15) / 16 + - (rssi1 << 8) / 16; - dev->cal.avg_rssi_all = (dev->cal.avg_rssi[0] + - dev->cal.avg_rssi[1]) / 512; + spin_lock_bh(&dev->mt76.rx_lock); + dev->cal.avg_rssi_all = ewma_signal_read(&dev->cal.rssi); + rssi_count = dev->cal.rssi_count; + dev->cal.rssi_count = 0; + spin_unlock_bh(&dev->mt76.rx_lock); + + if (!rssi_count) + dev->cal.avg_rssi_all = -75; low_gain = (dev->cal.avg_rssi_all > mt76x2_get_rssi_gain_thresh(dev)) + (dev->cal.avg_rssi_all > mt76x2_get_low_rssi_gain_thresh(dev));