diff mbox series

[07/11] rtw88: 8822c: use more accurate ofdm fa counting

Message ID 1560321917-17751-8-git-send-email-yhchuang@realtek.com (mailing list archive)
State Superseded
Delegated to: Kalle Valo
Headers show
Series rtw88: regular driver upgrade with minor changes | expand

Commit Message

Tony Chuang June 12, 2019, 6:45 a.m. UTC
From: Yan-Hsuan Chuang <yhchuang@realtek.com>

8822c used to count OFDM FA count by subtracting tx count from FA count.
But it need to substract more counters to be accurate.

However, we can count it by adding up all of the FA counters we want.
And it is simpler to add than list all of the components to substract.

Signed-off-by: Yan-Hsuan Chuang <yhchuang@realtek.com>
---
 drivers/net/wireless/realtek/rtw88/rtw8822c.c | 24 ++++++++++++++++++++----
 drivers/net/wireless/realtek/rtw88/rtw8822c.h |  5 +++++
 2 files changed, 25 insertions(+), 4 deletions(-)

Comments

Kalle Valo June 12, 2019, 7:42 a.m. UTC | #1
<yhchuang@realtek.com> writes:

> From: Yan-Hsuan Chuang <yhchuang@realtek.com>
>
> 8822c used to count OFDM FA count by subtracting tx count from FA count.
> But it need to substract more counters to be accurate.
>
> However, we can count it by adding up all of the FA counters we want.
> And it is simpler to add than list all of the components to substract.
>
> Signed-off-by: Yan-Hsuan Chuang <yhchuang@realtek.com>

[...]

> --- a/drivers/net/wireless/realtek/rtw88/rtw8822c.c
> +++ b/drivers/net/wireless/realtek/rtw88/rtw8822c.c
> @@ -1491,13 +1491,29 @@ static void rtw8822c_false_alarm_statistics(struct rtw_dev *rtwdev)
>  	u32 cck_enable;
>  	u32 cck_fa_cnt;
>  	u32 ofdm_fa_cnt;
> -	u32 ofdm_tx_counter;
> +	u32 ofdm_fa_cnt1, ofdm_fa_cnt2, ofdm_fa_cnt3, ofdm_fa_cnt4, ofdm_fa_cnt5;
> +	u16 parity_fail, rate_illegal, crc8_fail, mcs_fail, sb_search_fail,
> +	    fast_fsync, crc8_fail_vhta, mcs_fail_vht;
>  
>  	cck_enable = rtw_read32(rtwdev, REG_ENCCK) & BIT_CCK_BLK_EN;
>  	cck_fa_cnt = rtw_read16(rtwdev, REG_CCK_FACNT);
> -	ofdm_fa_cnt = rtw_read16(rtwdev, REG_OFDM_FACNT);
> -	ofdm_tx_counter = rtw_read16(rtwdev, REG_OFDM_TXCNT);
> -	ofdm_fa_cnt -= ofdm_tx_counter;
> +
> +	ofdm_fa_cnt1 = rtw_read32(rtwdev, REG_OFDM_FACNT1);
> +	ofdm_fa_cnt2 = rtw_read32(rtwdev, REG_OFDM_FACNT2);
> +	ofdm_fa_cnt3 = rtw_read32(rtwdev, REG_OFDM_FACNT3);
> +	ofdm_fa_cnt4 = rtw_read32(rtwdev, REG_OFDM_FACNT4);
> +	ofdm_fa_cnt5 = rtw_read32(rtwdev, REG_OFDM_FACNT5);
> +
> +	parity_fail = (ofdm_fa_cnt1 & 0xffff0000) >> 16;
> +	rate_illegal = (ofdm_fa_cnt2 & 0xffff);
> +	crc8_fail = (ofdm_fa_cnt2 & 0xffff0000) >> 16;
> +	crc8_fail_vhta = (ofdm_fa_cnt3 & 0xffff);
> +	mcs_fail = (ofdm_fa_cnt4 & 0xffff);
> +	mcs_fail_vht = (ofdm_fa_cnt4 & 0xffff0000) >> 16;
> +	fast_fsync = (ofdm_fa_cnt5 & 0xffff);
> +	sb_search_fail = (ofdm_fa_cnt5 & 0xffff0000) >> 16;

No magic numbers, please. IMO the cleanest way is to use create defines
using GENMASK() and FIELD_GET(), that way the values are proper
documented. An example (but not compile tested so can be buggy!):

#define OFDM_FA_CNT1_PARITY_FAIL GENMASK(31, 16)

parity_fail = FIELD_GET(OFDM_FA_CNT1_PARITY_FAIL, ofdm_fa_cnt1);
diff mbox series

Patch

diff --git a/drivers/net/wireless/realtek/rtw88/rtw8822c.c b/drivers/net/wireless/realtek/rtw88/rtw8822c.c
index b9185b2..4896f25 100644
--- a/drivers/net/wireless/realtek/rtw88/rtw8822c.c
+++ b/drivers/net/wireless/realtek/rtw88/rtw8822c.c
@@ -1491,13 +1491,29 @@  static void rtw8822c_false_alarm_statistics(struct rtw_dev *rtwdev)
 	u32 cck_enable;
 	u32 cck_fa_cnt;
 	u32 ofdm_fa_cnt;
-	u32 ofdm_tx_counter;
+	u32 ofdm_fa_cnt1, ofdm_fa_cnt2, ofdm_fa_cnt3, ofdm_fa_cnt4, ofdm_fa_cnt5;
+	u16 parity_fail, rate_illegal, crc8_fail, mcs_fail, sb_search_fail,
+	    fast_fsync, crc8_fail_vhta, mcs_fail_vht;
 
 	cck_enable = rtw_read32(rtwdev, REG_ENCCK) & BIT_CCK_BLK_EN;
 	cck_fa_cnt = rtw_read16(rtwdev, REG_CCK_FACNT);
-	ofdm_fa_cnt = rtw_read16(rtwdev, REG_OFDM_FACNT);
-	ofdm_tx_counter = rtw_read16(rtwdev, REG_OFDM_TXCNT);
-	ofdm_fa_cnt -= ofdm_tx_counter;
+
+	ofdm_fa_cnt1 = rtw_read32(rtwdev, REG_OFDM_FACNT1);
+	ofdm_fa_cnt2 = rtw_read32(rtwdev, REG_OFDM_FACNT2);
+	ofdm_fa_cnt3 = rtw_read32(rtwdev, REG_OFDM_FACNT3);
+	ofdm_fa_cnt4 = rtw_read32(rtwdev, REG_OFDM_FACNT4);
+	ofdm_fa_cnt5 = rtw_read32(rtwdev, REG_OFDM_FACNT5);
+
+	parity_fail = (ofdm_fa_cnt1 & 0xffff0000) >> 16;
+	rate_illegal = (ofdm_fa_cnt2 & 0xffff);
+	crc8_fail = (ofdm_fa_cnt2 & 0xffff0000) >> 16;
+	crc8_fail_vhta = (ofdm_fa_cnt3 & 0xffff);
+	mcs_fail = (ofdm_fa_cnt4 & 0xffff);
+	mcs_fail_vht = (ofdm_fa_cnt4 & 0xffff0000) >> 16;
+	fast_fsync = (ofdm_fa_cnt5 & 0xffff);
+	sb_search_fail = (ofdm_fa_cnt5 & 0xffff0000) >> 16;
+	ofdm_fa_cnt = parity_fail + rate_illegal + crc8_fail + crc8_fail_vhta +
+		      mcs_fail + mcs_fail_vht + fast_fsync + sb_search_fail;
 
 	dm_info->cck_fa_cnt = cck_fa_cnt;
 	dm_info->ofdm_fa_cnt = ofdm_fa_cnt;
diff --git a/drivers/net/wireless/realtek/rtw88/rtw8822c.h b/drivers/net/wireless/realtek/rtw88/rtw8822c.h
index bf41359..62ef128 100644
--- a/drivers/net/wireless/realtek/rtw88/rtw8822c.h
+++ b/drivers/net/wireless/realtek/rtw88/rtw8822c.h
@@ -187,6 +187,11 @@  struct rtw8822c_efuse {
 #define REG_CNT_CTRL	0x1eb4
 #define BIT_ALL_CNT_RST		BIT(25)
 #define REG_OFDM_FACNT	0x2d00
+#define REG_OFDM_FACNT1	0x2d04
+#define REG_OFDM_FACNT2	0x2d08
+#define REG_OFDM_FACNT3	0x2d0c
+#define REG_OFDM_FACNT4	0x2d10
+#define REG_OFDM_FACNT5	0x2d20
 #define REG_OFDM_TXCNT	0x2de0
 #define REG_ORITXCODE2	0x4100
 #define REG_3WIRE2	0x410c