mt76: move mt76x02_phy_get_min_avg_rssi to mt76 core

This will be used by mt7603 as well

Signed-off-by: Felix Fietkau <nbd@nbd.name>
This commit is contained in:
Felix Fietkau
2018-12-05 17:06:58 +01:00
parent 9313faacbb
commit ef13edc007
10 changed files with 62 additions and 65 deletions

View File

@@ -75,4 +75,46 @@ int mt76_wcid_alloc(unsigned long *mask, int size)
}
EXPORT_SYMBOL_GPL(mt76_wcid_alloc);
int mt76_get_min_avg_rssi(struct mt76_dev *dev)
{
struct mt76_wcid *wcid;
int i, j, min_rssi = 0;
s8 cur_rssi;
local_bh_disable();
rcu_read_lock();
for (i = 0; i < ARRAY_SIZE(dev->wcid_mask); i++) {
unsigned long mask = dev->wcid_mask[i];
if (!mask)
continue;
for (j = i * BITS_PER_LONG; mask; j++, mask >>= 1) {
if (!(mask & 1))
continue;
wcid = rcu_dereference(dev->wcid[j]);
if (!wcid)
continue;
spin_lock(&dev->rx_lock);
if (wcid->inactive_count++ < 5)
cur_rssi = ewma_signal_read(&wcid->rssi);
else
cur_rssi = 0;
spin_unlock(&dev->rx_lock);
if (cur_rssi < min_rssi)
min_rssi = cur_rssi;
}
}
rcu_read_unlock();
local_bh_enable();
return min_rssi;
}
EXPORT_SYMBOL_GPL(mt76_get_min_avg_rssi);
MODULE_LICENSE("Dual BSD/GPL");