mt76: mt7615: add support for per-chain signal strength reporting
authorRyder Lee <ryder.lee@mediatek.com>
Thu, 13 Jun 2019 07:13:29 +0000 (15:13 +0800)
committerFelix Fietkau <nbd@nbd.name>
Thu, 27 Jun 2019 10:58:13 +0000 (12:58 +0200)
Fill in RX status->chain_signal to avoid empty value.

Signed-off-by: Ryder Lee <ryder.lee@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
drivers/net/wireless/mediatek/mt76/mt7615/mac.c
drivers/net/wireless/mediatek/mt76/mt7615/mac.h

index b60d42b..1eb0e9c 100644 (file)
 #include "../dma.h"
 #include "mac.h"
 
+static inline s8 to_rssi(u32 field, u32 rxv)
+{
+       return (FIELD_GET(field, rxv) - 220) / 2;
+}
+
 static struct mt76_wcid *mt7615_rx_get_wcid(struct mt7615_dev *dev,
                                            u8 idx, bool unicast)
 {
@@ -120,6 +125,7 @@ int mt7615_mac_fill_rx(struct mt7615_dev *dev, struct sk_buff *skb)
        if (rxd0 & MT_RXD0_NORMAL_GROUP_3) {
                u32 rxdg0 = le32_to_cpu(rxd[0]);
                u32 rxdg1 = le32_to_cpu(rxd[1]);
+               u32 rxdg3 = le32_to_cpu(rxd[3]);
                u8 stbc = FIELD_GET(MT_RXV1_HT_STBC, rxdg0);
                bool cck = false;
 
@@ -169,7 +175,21 @@ int mt7615_mac_fill_rx(struct mt7615_dev *dev, struct sk_buff *skb)
 
                status->enc_flags |= RX_ENC_FLAG_STBC_MASK * stbc;
 
-               /* TODO: RSSI */
+               status->chains = dev->mt76.antenna_mask;
+               status->chain_signal[0] = to_rssi(MT_RXV4_RCPI0, rxdg3);
+               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(dev->mt76.antenna_mask); i++) {
+                       if (!(status->chains & BIT(i)))
+                               continue;
+
+                       status->signal = max(status->signal,
+                                            status->chain_signal[i]);
+               }
+
                rxd += 6;
                if ((u8 *)rxd - skb->data >= skb->len)
                        return -EINVAL;
index 18ad4b8..b00ce8d 100644 (file)
@@ -98,6 +98,11 @@ enum rx_pkt_type {
 #define MT_RXV2_GROUP_ID               GENMASK(26, 21)
 #define MT_RXV2_LENGTH                 GENMASK(20, 0)
 
+#define MT_RXV4_RCPI3                  GENMASK(31, 24)
+#define MT_RXV4_RCPI2                  GENMASK(23, 16)
+#define MT_RXV4_RCPI1                  GENMASK(15, 8)
+#define MT_RXV4_RCPI0                  GENMASK(7, 0)
+
 enum tx_header_format {
        MT_HDR_FORMAT_802_3,
        MT_HDR_FORMAT_CMD,