wifi: rtw89: add RSSI statistics for the case of antenna diversity to debugfs
authorPing-Ke Shih <pkshih@realtek.com>
Tue, 18 Apr 2023 01:28:16 +0000 (09:28 +0800)
committerKalle Valo <kvalo@kernel.org>
Fri, 5 May 2023 11:58:28 +0000 (14:58 +0300)
RSSI strength is only from PHY path A, but there are two antenna for the
module which supports antenna diversity. So, set RSSI value to index 1 of
RSSI array if current antenna is on antenna B. Then, debugfs can show
two RSSI values with a asterisk mark on selected antenna.

  RSSI: -23 dBm (raw=174, prev=173) [-26, -23*]

Signed-off-by: Ping-Ke Shih <pkshih@realtek.com>
Signed-off-by: Kalle Valo <kvalo@kernel.org>
Link: https://lore.kernel.org/r/20230418012820.5139-4-pkshih@realtek.com
drivers/net/wireless/realtek/rtw89/core.c
drivers/net/wireless/realtek/rtw89/debug.c

index 42e68ec..5271d59 100644 (file)
@@ -1244,10 +1244,22 @@ static void rtw89_core_rx_process_phy_ppdu_iter(void *data,
        struct rtw89_sta *rtwsta = (struct rtw89_sta *)sta->drv_priv;
        struct rtw89_rx_phy_ppdu *phy_ppdu = (struct rtw89_rx_phy_ppdu *)data;
        struct rtw89_dev *rtwdev = rtwsta->rtwdev;
+       struct rtw89_hal *hal = &rtwdev->hal;
+       u8 ant_num = hal->ant_diversity ? 2 : rtwdev->chip->rf_path_num;
+       u8 ant_pos = U8_MAX;
        int i;
 
-       if (rtwsta->mac_id == phy_ppdu->mac_id && phy_ppdu->to_self) {
-               ewma_rssi_add(&rtwsta->avg_rssi, phy_ppdu->rssi_avg);
+       if (rtwsta->mac_id != phy_ppdu->mac_id || !phy_ppdu->to_self)
+               return;
+
+       if (hal->ant_diversity && hal->antenna_rx)
+               ant_pos = __ffs(hal->antenna_rx);
+
+       ewma_rssi_add(&rtwsta->avg_rssi, phy_ppdu->rssi_avg);
+
+       if (ant_pos < ant_num) {
+               ewma_rssi_add(&rtwsta->rssi[ant_pos], phy_ppdu->rssi[0]);
+       } else {
                for (i = 0; i < rtwdev->chip->rf_path_num; i++)
                        ewma_rssi_add(&rtwsta->rssi[i], phy_ppdu->rssi[i]);
        }
@@ -2764,6 +2776,8 @@ int rtw89_core_sta_add(struct rtw89_dev *rtwdev,
 {
        struct rtw89_vif *rtwvif = (struct rtw89_vif *)vif->drv_priv;
        struct rtw89_sta *rtwsta = (struct rtw89_sta *)sta->drv_priv;
+       struct rtw89_hal *hal = &rtwdev->hal;
+       u8 ant_num = hal->ant_diversity ? 2 : rtwdev->chip->rf_path_num;
        int i;
        int ret;
 
@@ -2777,7 +2791,7 @@ int rtw89_core_sta_add(struct rtw89_dev *rtwdev,
                rtw89_core_txq_init(rtwdev, sta->txq[i]);
 
        ewma_rssi_init(&rtwsta->avg_rssi);
-       for (i = 0; i < rtwdev->chip->rf_path_num; i++)
+       for (i = 0; i < ant_num; i++)
                ewma_rssi_init(&rtwsta->rssi[i]);
 
        if (vif->type == NL80211_IFTYPE_STATION && !sta->tdls) {
index 1e5b7a9..bc5ea97 100644 (file)
@@ -3206,6 +3206,8 @@ static void rtw89_sta_info_get_iter(void *data, struct ieee80211_sta *sta)
        struct seq_file *m = (struct seq_file *)data;
        struct rtw89_dev *rtwdev = rtwsta->rtwdev;
        struct rtw89_hal *hal = &rtwdev->hal;
+       u8 ant_num = hal->ant_diversity ? 2 : rtwdev->chip->rf_path_num;
+       bool ant_asterisk = hal->tx_path_diversity || hal->ant_diversity;
        u8 rssi;
        int i;
 
@@ -3256,11 +3258,11 @@ static void rtw89_sta_info_get_iter(void *data, struct ieee80211_sta *sta)
        rssi = ewma_rssi_read(&rtwsta->avg_rssi);
        seq_printf(m, "RSSI: %d dBm (raw=%d, prev=%d) [",
                   RTW89_RSSI_RAW_TO_DBM(rssi), rssi, rtwsta->prev_rssi);
-       for (i = 0; i < rtwdev->chip->rf_path_num; i++) {
+       for (i = 0; i < ant_num; i++) {
                rssi = ewma_rssi_read(&rtwsta->rssi[i]);
                seq_printf(m, "%d%s%s", RTW89_RSSI_RAW_TO_DBM(rssi),
-                          hal->tx_path_diversity && (hal->antenna_tx & BIT(i)) ? "*" : "",
-                          i + 1 == rtwdev->chip->rf_path_num ? "" : ", ");
+                          ant_asterisk && (hal->antenna_tx & BIT(i)) ? "*" : "",
+                          i + 1 == ant_num ? "" : ", ");
        }
        seq_puts(m, "]\n");
 }