Commit ac85ab8c authored by Lorenzo Bianconi's avatar Lorenzo Bianconi Committed by Felix Fietkau

mt76x0: mac: use sta ewma estimation for rssi tracking

Use shared mt76x02 utility routines for rssi tracking.
Moreover remove no longer used con_mon_lock spinlock
and following variable:
- ap_bssid
- bcn_freq_off
- bcn_phy_mode
- avg_rssi
Signed-off-by: default avatarLorenzo Bianconi <lorenzo.bianconi@redhat.com>
Signed-off-by: default avatarFelix Fietkau <nbd@nbd.name>
parent 56e8d4dd
...@@ -348,7 +348,6 @@ mt76x0_alloc_device(struct device *pdev, ...@@ -348,7 +348,6 @@ mt76x0_alloc_device(struct device *pdev,
mutex_init(&dev->reg_atomic_mutex); mutex_init(&dev->reg_atomic_mutex);
mutex_init(&dev->hw_atomic_mutex); mutex_init(&dev->hw_atomic_mutex);
spin_lock_init(&dev->mac_lock); spin_lock_init(&dev->mac_lock);
spin_lock_init(&dev->con_mon_lock);
atomic_set(&dev->avg_ampdu_len, 1); atomic_set(&dev->avg_ampdu_len, 1);
return dev; return dev;
......
...@@ -196,31 +196,16 @@ void mt76x0_mac_set_ampdu_factor(struct mt76x0_dev *dev) ...@@ -196,31 +196,16 @@ void mt76x0_mac_set_ampdu_factor(struct mt76x0_dev *dev)
FIELD_PREP(MT_MAX_LEN_CFG_AMPDU, min_factor)); FIELD_PREP(MT_MAX_LEN_CFG_AMPDU, min_factor));
} }
static void
mt76x0_rx_monitor_beacon(struct mt76x0_dev *dev, struct mt76x02_rxwi *rxwi,
u16 rate, int rssi)
{
dev->bcn_phy_mode = FIELD_GET(MT_RXWI_RATE_PHY, rate);
dev->avg_rssi = ((dev->avg_rssi * 15) / 16 + (rssi << 8)) / 256;
}
static int
mt76x0_rx_is_our_beacon(struct mt76x0_dev *dev, u8 *data)
{
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)data;
return ieee80211_is_beacon(hdr->frame_control) &&
ether_addr_equal(hdr->addr2, dev->ap_bssid);
}
u32 mt76x0_mac_process_rx(struct mt76x0_dev *dev, struct sk_buff *skb, u32 mt76x0_mac_process_rx(struct mt76x0_dev *dev, struct sk_buff *skb,
void *rxi) void *rxi)
{ {
struct mt76_rx_status *status = (struct mt76_rx_status *) skb->cb; struct mt76_rx_status *status = (struct mt76_rx_status *) skb->cb;
struct mt76x02_rxwi *rxwi = rxi; struct mt76x02_rxwi *rxwi = rxi;
u32 len, ctl = le32_to_cpu(rxwi->ctl); u32 len, ctl = le32_to_cpu(rxwi->ctl);
u16 rate = le16_to_cpu(rxwi->rate); u16 rate = le16_to_cpu(rxwi->rate);
struct mt76x02_sta *sta;
int rssi, pad_len = 0; int rssi, pad_len = 0;
u8 wcid;
len = FIELD_GET(MT_RXWI_CTL_MPDU_LEN, ctl); len = FIELD_GET(MT_RXWI_CTL_MPDU_LEN, ctl);
if (WARN_ON(len < 10)) if (WARN_ON(len < 10))
...@@ -234,6 +219,9 @@ u32 mt76x0_mac_process_rx(struct mt76x0_dev *dev, struct sk_buff *skb, ...@@ -234,6 +219,9 @@ u32 mt76x0_mac_process_rx(struct mt76x0_dev *dev, struct sk_buff *skb,
if (rxwi->rxinfo & MT_RXINFO_L2PAD) if (rxwi->rxinfo & MT_RXINFO_L2PAD)
pad_len += 2; pad_len += 2;
wcid = FIELD_GET(MT_RXWI_CTL_WCID, ctl);
sta = mt76x02_rx_get_sta(&dev->mt76, wcid);
mt76x02_remove_hdr_pad(skb, pad_len); mt76x02_remove_hdr_pad(skb, pad_len);
pskb_trim(skb, len); pskb_trim(skb, len);
...@@ -243,19 +231,10 @@ u32 mt76x0_mac_process_rx(struct mt76x0_dev *dev, struct sk_buff *skb, ...@@ -243,19 +231,10 @@ u32 mt76x0_mac_process_rx(struct mt76x0_dev *dev, struct sk_buff *skb,
status->freq = dev->mt76.chandef.chan->center_freq; status->freq = dev->mt76.chandef.chan->center_freq;
status->band = dev->mt76.chandef.chan->band; status->band = dev->mt76.chandef.chan->band;
mt76x02_mac_process_rate(status, rate); if (sta) {
ewma_signal_add(&sta->rssi, status->signal);
spin_lock_bh(&dev->con_mon_lock); sta->inactive_count = 0;
if (mt76x0_rx_is_our_beacon(dev, skb->data)) {
mt76x0_rx_monitor_beacon(dev, rxwi, rate, rssi);
} else if (rxwi->rxinfo & cpu_to_le32(MT_RXINFO_UNICAST)) {
if (dev->avg_rssi == 0)
dev->avg_rssi = rssi;
else
dev->avg_rssi = (dev->avg_rssi * 15) / 16 + rssi / 16;
} }
spin_unlock_bh(&dev->con_mon_lock);
return len; return mt76x02_mac_process_rate(status, rate);
} }
...@@ -68,9 +68,6 @@ void mt76x0_bss_info_changed(struct ieee80211_hw *hw, ...@@ -68,9 +68,6 @@ void mt76x0_bss_info_changed(struct ieee80211_hw *hw,
mutex_lock(&dev->mt76.mutex); mutex_lock(&dev->mt76.mutex);
if (changed & BSS_CHANGED_ASSOC)
mt76x0_phy_con_cal_onoff(dev, info);
if (changed & BSS_CHANGED_BSSID) { if (changed & BSS_CHANGED_BSSID) {
mt76x0_addr_wr(dev, MT_MAC_BSSID_DW0, info->bssid); mt76x0_addr_wr(dev, MT_MAC_BSSID_DW0, info->bssid);
......
...@@ -70,7 +70,6 @@ enum mt_bw { ...@@ -70,7 +70,6 @@ enum mt_bw {
* struct mt76x0_dev - adapter structure * struct mt76x0_dev - adapter structure
* @lock: protects @wcid->tx_rate. * @lock: protects @wcid->tx_rate.
* @mac_lock: locks out mac80211's tx status and rx paths. * @mac_lock: locks out mac80211's tx status and rx paths.
* @con_mon_lock: protects @ap_bssid, @bcn_*, @avg_rssi.
* @mutex: ensures exclusive access from mac80211 callbacks. * @mutex: ensures exclusive access from mac80211 callbacks.
* @reg_atomic_mutex: ensures atomicity of indirect register accesses * @reg_atomic_mutex: ensures atomicity of indirect register accesses
* (accesses to RF and BBP). * (accesses to RF and BBP).
...@@ -94,15 +93,6 @@ struct mt76x0_dev { ...@@ -94,15 +93,6 @@ struct mt76x0_dev {
atomic_t avg_ampdu_len; atomic_t avg_ampdu_len;
/* Connection monitoring things */
spinlock_t con_mon_lock;
u8 ap_bssid[ETH_ALEN];
s8 bcn_freq_off;
u8 bcn_phy_mode;
int avg_rssi; /* starts at 0 and converges */
u8 agc_save; u8 agc_save;
bool no_2ghz; bool no_2ghz;
...@@ -153,8 +143,6 @@ int mt76x0_phy_set_channel(struct mt76x0_dev *dev, ...@@ -153,8 +143,6 @@ int mt76x0_phy_set_channel(struct mt76x0_dev *dev,
struct cfg80211_chan_def *chandef); struct cfg80211_chan_def *chandef);
void mt76x0_phy_recalibrate_after_assoc(struct mt76x0_dev *dev); void mt76x0_phy_recalibrate_after_assoc(struct mt76x0_dev *dev);
int mt76x0_phy_get_rssi(struct mt76x0_dev *dev, struct mt76x02_rxwi *rxwi); int mt76x0_phy_get_rssi(struct mt76x0_dev *dev, struct mt76x02_rxwi *rxwi);
void mt76x0_phy_con_cal_onoff(struct mt76x0_dev *dev,
struct ieee80211_bss_conf *info);
void mt76x0_phy_set_txpower(struct mt76x0_dev *dev); void mt76x0_phy_set_txpower(struct mt76x0_dev *dev);
/* MAC */ /* MAC */
......
...@@ -818,12 +818,15 @@ static void mt76x0_temp_sensor(struct mt76x0_dev *dev) ...@@ -818,12 +818,15 @@ static void mt76x0_temp_sensor(struct mt76x0_dev *dev)
static void mt76x0_dynamic_vga_tuning(struct mt76x0_dev *dev) static void mt76x0_dynamic_vga_tuning(struct mt76x0_dev *dev)
{ {
struct cfg80211_chan_def *chandef = &dev->mt76.chandef;
u32 val, init_vga; u32 val, init_vga;
int avg_rssi;
init_vga = (dev->mt76.chandef.chan->band == NL80211_BAND_5GHZ) ? 0x54 : 0x4E; init_vga = chandef->chan->band == NL80211_BAND_5GHZ ? 0x54 : 0x4E;
if (dev->avg_rssi > -60) avg_rssi = mt76x02_phy_get_min_avg_rssi(&dev->mt76);
if (avg_rssi > -60)
init_vga -= 0x20; init_vga -= 0x20;
else if (dev->avg_rssi > -70) else if (avg_rssi > -70)
init_vga -= 0x10; init_vga -= 0x10;
val = mt76_rr(dev, MT_BBP(AGC, 8)); val = mt76_rr(dev, MT_BBP(AGC, 8));
...@@ -844,17 +847,6 @@ static void mt76x0_phy_calibrate(struct work_struct *work) ...@@ -844,17 +847,6 @@ static void mt76x0_phy_calibrate(struct work_struct *work)
MT_CALIBRATE_INTERVAL); MT_CALIBRATE_INTERVAL);
} }
void mt76x0_phy_con_cal_onoff(struct mt76x0_dev *dev,
struct ieee80211_bss_conf *info)
{
/* Start/stop collecting beacon data */
spin_lock_bh(&dev->con_mon_lock);
ether_addr_copy(dev->ap_bssid, info->bssid);
dev->avg_rssi = 0;
dev->bcn_freq_off = MT_FREQ_OFFSET_INVALID;
spin_unlock_bh(&dev->con_mon_lock);
}
static void static void
mt76x0_rf_init(struct mt76x0_dev *dev) mt76x0_rf_init(struct mt76x0_dev *dev)
{ {
......
...@@ -53,7 +53,7 @@ void mt76x0_queue_rx_skb(struct mt76_dev *mdev, enum mt76_rxq_id q, ...@@ -53,7 +53,7 @@ void mt76x0_queue_rx_skb(struct mt76_dev *mdev, enum mt76_rxq_id q,
void *rxwi = skb->data; void *rxwi = skb->data;
skb_pull(skb, sizeof(struct mt76x02_rxwi)); skb_pull(skb, sizeof(struct mt76x02_rxwi));
if (!mt76x0_mac_process_rx(dev, skb, rxwi)) { if (mt76x0_mac_process_rx(dev, skb, rxwi)) {
dev_kfree_skb(skb); dev_kfree_skb(skb);
return; return;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment