[PATCH 4.20 113/117] mt76x02: assure we update gain after scan

From: Greg Kroah-Hartman
Date: Tue Jan 29 2019 - 06:41:59 EST


4.20-stable review patch. If anyone has any objections, please let me know.

------------------

From: Stanislaw Gruszka <sgruszka@xxxxxxxxxx>

commit 4784a3cc3fffd0ba5ef6c7a23980ae0318fc1369 upstream.

Assure that after we initialize dev->cal.low_gain to -1 this
will cause update gain calibration. Otherwise this might or
might not happen depending on value of second bit of low_gain
and values read from registers in mt76x02_phy_adjust_vga_gain().

Signed-off-by: Felix Fietkau <nbd@xxxxxxxx>
Signed-off-by: Stanislaw Gruszka <sgruszka@xxxxxxxxxx>
Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
---
drivers/net/wireless/mediatek/mt76/mt76x0/main.c | 5 ++++-
drivers/net/wireless/mediatek/mt76/mt76x0/phy.c | 3 ++-
2 files changed, 6 insertions(+), 2 deletions(-)

--- a/drivers/net/wireless/mediatek/mt76/mt76x0/main.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/main.c
@@ -139,8 +139,11 @@ void mt76x0_sw_scan_complete(struct ieee

clear_bit(MT76_SCANNING, &dev->mt76.state);

- if (dev->cal.gain_init_done)
+ if (dev->cal.gain_init_done) {
+ /* Restore AGC gain and resume calibration after scanning. */
+ dev->cal.low_gain = -1;
ieee80211_queue_delayed_work(hw, &dev->cal_work, 0);
+ }
}
EXPORT_SYMBOL_GPL(mt76x0_sw_scan_complete);

--- a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c
@@ -834,7 +834,8 @@ mt76x0_phy_update_channel_gain(struct mt
low_gain = (dev->cal.avg_rssi_all > mt76x02_get_rssi_gain_thresh(dev)) +
(dev->cal.avg_rssi_all > mt76x02_get_low_rssi_gain_thresh(dev));

- gain_change = (dev->cal.low_gain & 2) ^ (low_gain & 2);
+ gain_change = dev->cal.low_gain < 0 ||
+ (dev->cal.low_gain & 2) ^ (low_gain & 2);
dev->cal.low_gain = low_gain;

if (!gain_change) {