Skip to content

Commit

Permalink
mt76: improve signal strength reporting
Browse files Browse the repository at this point in the history
Instead of just taking the maximum per-chain signal strength values,
add an approximation for the sum of the combined signal.
This should more accurately reflect the real signal strength, especially
if the per-chain signal strength values are close to each other

Signed-off-by: Felix Fietkau <nbd@nbd.name>
  • Loading branch information
Felix Fietkau committed Feb 24, 2022
1 parent 7778735 commit 4550fb9
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 29 deletions.
32 changes: 32 additions & 0 deletions drivers/net/wireless/mediatek/mt76/mac80211.c
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,35 @@ void mt76_wcid_key_setup(struct mt76_dev *dev, struct mt76_wcid *wcid,
}
EXPORT_SYMBOL(mt76_wcid_key_setup);

static int
mt76_rx_signal(struct mt76_rx_status *status)
{
s8 *chain_signal = status->chain_signal;
int signal = -128;
u8 chains;

for (chains = status->chains; chains; chains >>= 1, chain_signal++) {
int cur, diff;

if (!(chains & BIT(0)))
continue;

cur = *chain_signal;
if (cur > signal)
swap(cur, signal);

diff = signal - cur;
if (diff == 0)
signal += 3;
else if (diff <= 2)
signal += 2;
else if (diff <= 6)
signal += 1;
}

return signal;
}

static void
mt76_rx_convert(struct mt76_dev *dev, struct sk_buff *skb,
struct ieee80211_hw **hw,
Expand Down Expand Up @@ -960,6 +989,9 @@ mt76_rx_convert(struct mt76_dev *dev, struct sk_buff *skb,
status->ampdu_reference = mstat.ampdu_ref;
status->device_timestamp = mstat.timestamp;
status->mactime = mstat.timestamp;
status->signal = mt76_rx_signal(&mstat);
if (status->signal <= -128)
status->flag |= RX_FLAG_NO_SIGNAL_VAL;

if (ieee80211_is_beacon(hdr->frame_control) ||
ieee80211_is_probe_resp(hdr->frame_control))
Expand Down
5 changes: 0 additions & 5 deletions drivers/net/wireless/mediatek/mt76/mt7603/mac.c
Original file line number Diff line number Diff line change
Expand Up @@ -643,11 +643,6 @@ mt7603_mac_fill_rx(struct mt7603_dev *dev, struct sk_buff *skb)
status->chain_signal[1] = FIELD_GET(MT_RXV4_IB_RSSI1, rxdg3) +
dev->rssi_offset[1];

status->signal = status->chain_signal[0];
if (status->chains & BIT(1))
status->signal = max(status->signal,
status->chain_signal[1]);

if (FIELD_GET(MT_RXV1_FRAME_MODE, rxdg0) == 1)
status->bw = RATE_INFO_BW_40;

Expand Down
9 changes: 0 additions & 9 deletions drivers/net/wireless/mediatek/mt76/mt7615/mac.c
Original file line number Diff line number Diff line change
Expand Up @@ -576,15 +576,6 @@ static int mt7615_mac_fill_rx(struct mt7615_dev *dev, struct sk_buff *skb)
status->chain_signal[1] = to_rssi(MT_RXV4_RCPI1, rxdg3);
status->chain_signal[2] = to_rssi(MT_RXV4_RCPI2, rxdg3);
status->chain_signal[3] = to_rssi(MT_RXV4_RCPI3, rxdg3);
status->signal = status->chain_signal[0];

for (i = 1; i < hweight8(mphy->antenna_mask); i++) {
if (!(status->chains & BIT(i)))
continue;

status->signal = max(status->signal,
status->chain_signal[i]);
}

mt7615_mac_fill_tm_rx(mphy->priv, rxd);

Expand Down
2 changes: 0 additions & 2 deletions drivers/net/wireless/mediatek/mt76/mt76x02_mac.c
Original file line number Diff line number Diff line change
Expand Up @@ -860,9 +860,7 @@ int mt76x02_mac_process_rx(struct mt76x02_dev *dev, struct sk_buff *skb,
status->chain_signal[1] = mt76x02_mac_get_rssi(dev,
rxwi->rssi[1],
1);
signal = max_t(s8, signal, status->chain_signal[1]);
}
status->signal = signal;
status->freq = dev->mphy.chandef.chan->center_freq;
status->band = dev->mphy.chandef.chan->band;

Expand Down
11 changes: 1 addition & 10 deletions drivers/net/wireless/mediatek/mt76/mt7915/mac.c
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ mt7915_mac_fill_rx(struct mt7915_dev *dev, struct sk_buff *skb)
u16 seq_ctrl = 0;
u8 qos_ctl = 0;
__le16 fc = 0;
int i, idx;
int idx;

memset(status, 0, sizeof(*status));

Expand Down Expand Up @@ -753,15 +753,6 @@ mt7915_mac_fill_rx(struct mt7915_dev *dev, struct sk_buff *skb)
status->chain_signal[1] = to_rssi(MT_PRXV_RCPI1, v1);
status->chain_signal[2] = to_rssi(MT_PRXV_RCPI2, v1);
status->chain_signal[3] = to_rssi(MT_PRXV_RCPI3, v1);
status->signal = status->chain_signal[0];

for (i = 1; i < hweight8(mphy->antenna_mask); i++) {
if (!(status->chains & BIT(i)))
continue;

status->signal = max(status->signal,
status->chain_signal[i]);
}

/* RXD Group 5 - C-RXV */
if (rxd1 & MT_RXD1_NORMAL_GROUP_5) {
Expand Down
3 changes: 0 additions & 3 deletions drivers/net/wireless/mediatek/mt76/mt7921/mac.c
Original file line number Diff line number Diff line change
Expand Up @@ -670,9 +670,6 @@ mt7921_mac_fill_rx(struct mt7921_dev *dev, struct sk_buff *skb)
status->chain_signal[i]);
}

if (status->signal == -128)
status->flag |= RX_FLAG_NO_SIGNAL_VAL;

stbc = FIELD_GET(MT_PRXV_STBC, v0);
gi = FIELD_GET(MT_PRXV_SGI, v0);
cck = false;
Expand Down

0 comments on commit 4550fb9

Please sign in to comment.