Skip to content

Commit b0d3016

Browse files
rtlwifi-linuxKalle Valo
authored andcommitted
rtw88: 8821c: Correct CCK RSSI
Incorrect CCK RSSI may cause periodically scan from upper layer. 8821c phy status does NOT has actual value of CCK power. It provides only lna and vga index. Driver have to use these indexes to calculate actual RSSI. Signed-off-by: Guo-Feng Fan <vincent_fann@realtek.com> Signed-off-by: Ping-Ke Shih <pkshih@realtek.com> Signed-off-by: Kalle Valo <kvalo@codeaurora.org> Link: https://lore.kernel.org/r/20210202055012.8296-3-pkshih@realtek.com
1 parent adba838 commit b0d3016

File tree

2 files changed

+49
-5
lines changed

2 files changed

+49
-5
lines changed

drivers/net/wireless/realtek/rtw88/rtw8821c.c

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
#include "debug.h"
1616
#include "bf.h"
1717

18+
static const s8 lna_gain_table_0[8] = {22, 8, -6, -22, -31, -40, -46, -52};
19+
static const s8 lna_gain_table_1[16] = {10, 6, 2, -2, -6, -10, -14, -17,
20+
-20, -24, -28, -31, -34, -37, -40, -44};
21+
1822
static void rtw8821ce_efuse_parsing(struct rtw_efuse *efuse,
1923
struct rtw8821c_efuse *map)
2024
{
@@ -426,17 +430,49 @@ static void rtw8821c_set_channel(struct rtw_dev *rtwdev, u8 channel, u8 bw,
426430
rtw8821c_set_channel_rxdfir(rtwdev, bw);
427431
}
428432

433+
static s8 get_cck_rx_pwr(struct rtw_dev *rtwdev, u8 lna_idx, u8 vga_idx)
434+
{
435+
struct rtw_efuse *efuse = &rtwdev->efuse;
436+
const s8 *lna_gain_table;
437+
int lna_gain_table_size;
438+
s8 rx_pwr_all = 0;
439+
s8 lna_gain = 0;
440+
441+
if (efuse->rfe_option == 0) {
442+
lna_gain_table = lna_gain_table_0;
443+
lna_gain_table_size = ARRAY_SIZE(lna_gain_table_0);
444+
} else {
445+
lna_gain_table = lna_gain_table_1;
446+
lna_gain_table_size = ARRAY_SIZE(lna_gain_table_1);
447+
}
448+
449+
if (lna_idx >= lna_gain_table_size) {
450+
rtw_info(rtwdev, "incorrect lna index (%d)\n", lna_idx);
451+
return -120;
452+
}
453+
454+
lna_gain = lna_gain_table[lna_idx];
455+
rx_pwr_all = lna_gain - 2 * vga_idx;
456+
457+
return rx_pwr_all;
458+
}
459+
429460
static void query_phy_status_page0(struct rtw_dev *rtwdev, u8 *phy_status,
430461
struct rtw_rx_pkt_stat *pkt_stat)
431462
{
432-
s8 min_rx_power = -120;
433-
u8 pwdb = GET_PHY_STAT_P0_PWDB(phy_status);
463+
s8 rx_power;
464+
u8 lna_idx = 0;
465+
u8 vga_idx = 0;
434466

435-
pkt_stat->rx_power[RF_PATH_A] = pwdb - 100;
467+
vga_idx = GET_PHY_STAT_P0_VGA(phy_status);
468+
lna_idx = FIELD_PREP(BIT_LNA_H_MASK, GET_PHY_STAT_P0_LNA_H(phy_status)) |
469+
FIELD_PREP(BIT_LNA_L_MASK, GET_PHY_STAT_P0_LNA_L(phy_status));
470+
rx_power = get_cck_rx_pwr(rtwdev, lna_idx, vga_idx);
471+
472+
pkt_stat->rx_power[RF_PATH_A] = rx_power;
436473
pkt_stat->rssi = rtw_phy_rf_power_2_rssi(pkt_stat->rx_power, 1);
437474
pkt_stat->bw = RTW_CHANNEL_WIDTH_20;
438-
pkt_stat->signal_power = max(pkt_stat->rx_power[RF_PATH_A],
439-
min_rx_power);
475+
pkt_stat->signal_power = rx_power;
440476
}
441477

442478
static void query_phy_status_page1(struct rtw_dev *rtwdev, u8 *phy_status,

drivers/net/wireless/realtek/rtw88/rtw8821c.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,14 @@ _rtw_write32s_mask(struct rtw_dev *rtwdev, u32 addr, u32 mask, u32 data)
148148
/* phy status page0 */
149149
#define GET_PHY_STAT_P0_PWDB(phy_stat) \
150150
le32_get_bits(*((__le32 *)(phy_stat) + 0x00), GENMASK(15, 8))
151+
#define GET_PHY_STAT_P0_VGA(phy_stat) \
152+
le32_get_bits(*((__le32 *)(phy_stat) + 0x03), GENMASK(12, 8))
153+
#define GET_PHY_STAT_P0_LNA_L(phy_stat) \
154+
le32_get_bits(*((__le32 *)(phy_stat) + 0x03), GENMASK(15, 13))
155+
#define GET_PHY_STAT_P0_LNA_H(phy_stat) \
156+
le32_get_bits(*((__le32 *)(phy_stat) + 0x03), BIT(23))
157+
#define BIT_LNA_H_MASK BIT(3)
158+
#define BIT_LNA_L_MASK GENMASK(2, 0)
151159

152160
/* phy status page1 */
153161
#define GET_PHY_STAT_P1_PWDB_A(phy_stat) \

0 commit comments

Comments
 (0)