18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci/* Copyright(c) 2009-2012  Realtek Corporation.*/
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ci#include "../wifi.h"
58c2ecf20Sopenharmony_ci#include "../base.h"
68c2ecf20Sopenharmony_ci#include "../core.h"
78c2ecf20Sopenharmony_ci#include "reg.h"
88c2ecf20Sopenharmony_ci#include "def.h"
98c2ecf20Sopenharmony_ci#include "phy.h"
108c2ecf20Sopenharmony_ci#include "dm.h"
118c2ecf20Sopenharmony_ci#include "fw.h"
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci#define UNDEC_SM_PWDB	entry_min_undec_sm_pwdb
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_cistatic const u32 ofdmswing_table[OFDM_TABLE_SIZE_92D] = {
168c2ecf20Sopenharmony_ci	0x7f8001fe,		/* 0, +6.0dB */
178c2ecf20Sopenharmony_ci	0x788001e2,		/* 1, +5.5dB */
188c2ecf20Sopenharmony_ci	0x71c001c7,		/* 2, +5.0dB */
198c2ecf20Sopenharmony_ci	0x6b8001ae,		/* 3, +4.5dB */
208c2ecf20Sopenharmony_ci	0x65400195,		/* 4, +4.0dB */
218c2ecf20Sopenharmony_ci	0x5fc0017f,		/* 5, +3.5dB */
228c2ecf20Sopenharmony_ci	0x5a400169,		/* 6, +3.0dB */
238c2ecf20Sopenharmony_ci	0x55400155,		/* 7, +2.5dB */
248c2ecf20Sopenharmony_ci	0x50800142,		/* 8, +2.0dB */
258c2ecf20Sopenharmony_ci	0x4c000130,		/* 9, +1.5dB */
268c2ecf20Sopenharmony_ci	0x47c0011f,		/* 10, +1.0dB */
278c2ecf20Sopenharmony_ci	0x43c0010f,		/* 11, +0.5dB */
288c2ecf20Sopenharmony_ci	0x40000100,		/* 12, +0dB */
298c2ecf20Sopenharmony_ci	0x3c8000f2,		/* 13, -0.5dB */
308c2ecf20Sopenharmony_ci	0x390000e4,		/* 14, -1.0dB */
318c2ecf20Sopenharmony_ci	0x35c000d7,		/* 15, -1.5dB */
328c2ecf20Sopenharmony_ci	0x32c000cb,		/* 16, -2.0dB */
338c2ecf20Sopenharmony_ci	0x300000c0,		/* 17, -2.5dB */
348c2ecf20Sopenharmony_ci	0x2d4000b5,		/* 18, -3.0dB */
358c2ecf20Sopenharmony_ci	0x2ac000ab,		/* 19, -3.5dB */
368c2ecf20Sopenharmony_ci	0x288000a2,		/* 20, -4.0dB */
378c2ecf20Sopenharmony_ci	0x26000098,		/* 21, -4.5dB */
388c2ecf20Sopenharmony_ci	0x24000090,		/* 22, -5.0dB */
398c2ecf20Sopenharmony_ci	0x22000088,		/* 23, -5.5dB */
408c2ecf20Sopenharmony_ci	0x20000080,		/* 24, -6.0dB */
418c2ecf20Sopenharmony_ci	0x1e400079,		/* 25, -6.5dB */
428c2ecf20Sopenharmony_ci	0x1c800072,		/* 26, -7.0dB */
438c2ecf20Sopenharmony_ci	0x1b00006c,		/* 27. -7.5dB */
448c2ecf20Sopenharmony_ci	0x19800066,		/* 28, -8.0dB */
458c2ecf20Sopenharmony_ci	0x18000060,		/* 29, -8.5dB */
468c2ecf20Sopenharmony_ci	0x16c0005b,		/* 30, -9.0dB */
478c2ecf20Sopenharmony_ci	0x15800056,		/* 31, -9.5dB */
488c2ecf20Sopenharmony_ci	0x14400051,		/* 32, -10.0dB */
498c2ecf20Sopenharmony_ci	0x1300004c,		/* 33, -10.5dB */
508c2ecf20Sopenharmony_ci	0x12000048,		/* 34, -11.0dB */
518c2ecf20Sopenharmony_ci	0x11000044,		/* 35, -11.5dB */
528c2ecf20Sopenharmony_ci	0x10000040,		/* 36, -12.0dB */
538c2ecf20Sopenharmony_ci	0x0f00003c,		/* 37, -12.5dB */
548c2ecf20Sopenharmony_ci	0x0e400039,		/* 38, -13.0dB */
558c2ecf20Sopenharmony_ci	0x0d800036,		/* 39, -13.5dB */
568c2ecf20Sopenharmony_ci	0x0cc00033,		/* 40, -14.0dB */
578c2ecf20Sopenharmony_ci	0x0c000030,		/* 41, -14.5dB */
588c2ecf20Sopenharmony_ci	0x0b40002d,		/* 42, -15.0dB */
598c2ecf20Sopenharmony_ci};
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_cistatic const u8 cckswing_table_ch1ch13[CCK_TABLE_SIZE][8] = {
628c2ecf20Sopenharmony_ci	{0x36, 0x35, 0x2e, 0x25, 0x1c, 0x12, 0x09, 0x04},    /* 0, +0dB */
638c2ecf20Sopenharmony_ci	{0x33, 0x32, 0x2b, 0x23, 0x1a, 0x11, 0x08, 0x04},    /* 1, -0.5dB */
648c2ecf20Sopenharmony_ci	{0x30, 0x2f, 0x29, 0x21, 0x19, 0x10, 0x08, 0x03},    /* 2, -1.0dB */
658c2ecf20Sopenharmony_ci	{0x2d, 0x2d, 0x27, 0x1f, 0x18, 0x0f, 0x08, 0x03},    /* 3, -1.5dB */
668c2ecf20Sopenharmony_ci	{0x2b, 0x2a, 0x25, 0x1e, 0x16, 0x0e, 0x07, 0x03},    /* 4, -2.0dB */
678c2ecf20Sopenharmony_ci	{0x28, 0x28, 0x22, 0x1c, 0x15, 0x0d, 0x07, 0x03},    /* 5, -2.5dB */
688c2ecf20Sopenharmony_ci	{0x26, 0x25, 0x21, 0x1b, 0x14, 0x0d, 0x06, 0x03},    /* 6, -3.0dB */
698c2ecf20Sopenharmony_ci	{0x24, 0x23, 0x1f, 0x19, 0x13, 0x0c, 0x06, 0x03},    /* 7, -3.5dB */
708c2ecf20Sopenharmony_ci	{0x22, 0x21, 0x1d, 0x18, 0x11, 0x0b, 0x06, 0x02},    /* 8, -4.0dB */
718c2ecf20Sopenharmony_ci	{0x20, 0x20, 0x1b, 0x16, 0x11, 0x08, 0x05, 0x02},    /* 9, -4.5dB */
728c2ecf20Sopenharmony_ci	{0x1f, 0x1e, 0x1a, 0x15, 0x10, 0x0a, 0x05, 0x02},    /* 10, -5.0dB */
738c2ecf20Sopenharmony_ci	{0x1d, 0x1c, 0x18, 0x14, 0x0f, 0x0a, 0x05, 0x02},    /* 11, -5.5dB */
748c2ecf20Sopenharmony_ci	{0x1b, 0x1a, 0x17, 0x13, 0x0e, 0x09, 0x04, 0x02},    /* 12, -6.0dB */
758c2ecf20Sopenharmony_ci	{0x1a, 0x19, 0x16, 0x12, 0x0d, 0x09, 0x04, 0x02},    /* 13, -6.5dB */
768c2ecf20Sopenharmony_ci	{0x18, 0x17, 0x15, 0x11, 0x0c, 0x08, 0x04, 0x02},    /* 14, -7.0dB */
778c2ecf20Sopenharmony_ci	{0x17, 0x16, 0x13, 0x10, 0x0c, 0x08, 0x04, 0x02},    /* 15, -7.5dB */
788c2ecf20Sopenharmony_ci	{0x16, 0x15, 0x12, 0x0f, 0x0b, 0x07, 0x04, 0x01},    /* 16, -8.0dB */
798c2ecf20Sopenharmony_ci	{0x14, 0x14, 0x11, 0x0e, 0x0b, 0x07, 0x03, 0x02},    /* 17, -8.5dB */
808c2ecf20Sopenharmony_ci	{0x13, 0x13, 0x10, 0x0d, 0x0a, 0x06, 0x03, 0x01},    /* 18, -9.0dB */
818c2ecf20Sopenharmony_ci	{0x12, 0x12, 0x0f, 0x0c, 0x09, 0x06, 0x03, 0x01},    /* 19, -9.5dB */
828c2ecf20Sopenharmony_ci	{0x11, 0x11, 0x0f, 0x0c, 0x09, 0x06, 0x03, 0x01},    /* 20, -10.0dB */
838c2ecf20Sopenharmony_ci	{0x10, 0x10, 0x0e, 0x0b, 0x08, 0x05, 0x03, 0x01},    /* 21, -10.5dB */
848c2ecf20Sopenharmony_ci	{0x0f, 0x0f, 0x0d, 0x0b, 0x08, 0x05, 0x03, 0x01},    /* 22, -11.0dB */
858c2ecf20Sopenharmony_ci	{0x0e, 0x0e, 0x0c, 0x0a, 0x08, 0x05, 0x02, 0x01},    /* 23, -11.5dB */
868c2ecf20Sopenharmony_ci	{0x0d, 0x0d, 0x0c, 0x0a, 0x07, 0x05, 0x02, 0x01},    /* 24, -12.0dB */
878c2ecf20Sopenharmony_ci	{0x0d, 0x0c, 0x0b, 0x09, 0x07, 0x04, 0x02, 0x01},    /* 25, -12.5dB */
888c2ecf20Sopenharmony_ci	{0x0c, 0x0c, 0x0a, 0x09, 0x06, 0x04, 0x02, 0x01},    /* 26, -13.0dB */
898c2ecf20Sopenharmony_ci	{0x0b, 0x0b, 0x0a, 0x08, 0x06, 0x04, 0x02, 0x01},    /* 27, -13.5dB */
908c2ecf20Sopenharmony_ci	{0x0b, 0x0a, 0x09, 0x08, 0x06, 0x04, 0x02, 0x01},    /* 28, -14.0dB */
918c2ecf20Sopenharmony_ci	{0x0a, 0x0a, 0x09, 0x07, 0x05, 0x03, 0x02, 0x01},    /* 29, -14.5dB */
928c2ecf20Sopenharmony_ci	{0x0a, 0x09, 0x08, 0x07, 0x05, 0x03, 0x02, 0x01},    /* 30, -15.0dB */
938c2ecf20Sopenharmony_ci	{0x09, 0x09, 0x08, 0x06, 0x05, 0x03, 0x01, 0x01},    /* 31, -15.5dB */
948c2ecf20Sopenharmony_ci	{0x09, 0x08, 0x07, 0x06, 0x04, 0x03, 0x01, 0x01}     /* 32, -16.0dB */
958c2ecf20Sopenharmony_ci};
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_cistatic const u8 cckswing_table_ch14[CCK_TABLE_SIZE][8] = {
988c2ecf20Sopenharmony_ci	{0x36, 0x35, 0x2e, 0x1b, 0x00, 0x00, 0x00, 0x00},    /* 0, +0dB */
998c2ecf20Sopenharmony_ci	{0x33, 0x32, 0x2b, 0x19, 0x00, 0x00, 0x00, 0x00},    /* 1, -0.5dB */
1008c2ecf20Sopenharmony_ci	{0x30, 0x2f, 0x29, 0x18, 0x00, 0x00, 0x00, 0x00},    /* 2, -1.0dB */
1018c2ecf20Sopenharmony_ci	{0x2d, 0x2d, 0x17, 0x17, 0x00, 0x00, 0x00, 0x00},    /* 3, -1.5dB */
1028c2ecf20Sopenharmony_ci	{0x2b, 0x2a, 0x25, 0x15, 0x00, 0x00, 0x00, 0x00},    /* 4, -2.0dB */
1038c2ecf20Sopenharmony_ci	{0x28, 0x28, 0x24, 0x14, 0x00, 0x00, 0x00, 0x00},    /* 5, -2.5dB */
1048c2ecf20Sopenharmony_ci	{0x26, 0x25, 0x21, 0x13, 0x00, 0x00, 0x00, 0x00},    /* 6, -3.0dB */
1058c2ecf20Sopenharmony_ci	{0x24, 0x23, 0x1f, 0x12, 0x00, 0x00, 0x00, 0x00},    /* 7, -3.5dB */
1068c2ecf20Sopenharmony_ci	{0x22, 0x21, 0x1d, 0x11, 0x00, 0x00, 0x00, 0x00},    /* 8, -4.0dB */
1078c2ecf20Sopenharmony_ci	{0x20, 0x20, 0x1b, 0x10, 0x00, 0x00, 0x00, 0x00},    /* 9, -4.5dB */
1088c2ecf20Sopenharmony_ci	{0x1f, 0x1e, 0x1a, 0x0f, 0x00, 0x00, 0x00, 0x00},    /* 10, -5.0dB */
1098c2ecf20Sopenharmony_ci	{0x1d, 0x1c, 0x18, 0x0e, 0x00, 0x00, 0x00, 0x00},    /* 11, -5.5dB */
1108c2ecf20Sopenharmony_ci	{0x1b, 0x1a, 0x17, 0x0e, 0x00, 0x00, 0x00, 0x00},    /* 12, -6.0dB */
1118c2ecf20Sopenharmony_ci	{0x1a, 0x19, 0x16, 0x0d, 0x00, 0x00, 0x00, 0x00},    /* 13, -6.5dB */
1128c2ecf20Sopenharmony_ci	{0x18, 0x17, 0x15, 0x0c, 0x00, 0x00, 0x00, 0x00},    /* 14, -7.0dB */
1138c2ecf20Sopenharmony_ci	{0x17, 0x16, 0x13, 0x0b, 0x00, 0x00, 0x00, 0x00},    /* 15, -7.5dB */
1148c2ecf20Sopenharmony_ci	{0x16, 0x15, 0x12, 0x0b, 0x00, 0x00, 0x00, 0x00},    /* 16, -8.0dB */
1158c2ecf20Sopenharmony_ci	{0x14, 0x14, 0x11, 0x0a, 0x00, 0x00, 0x00, 0x00},    /* 17, -8.5dB */
1168c2ecf20Sopenharmony_ci	{0x13, 0x13, 0x10, 0x0a, 0x00, 0x00, 0x00, 0x00},    /* 18, -9.0dB */
1178c2ecf20Sopenharmony_ci	{0x12, 0x12, 0x0f, 0x09, 0x00, 0x00, 0x00, 0x00},    /* 19, -9.5dB */
1188c2ecf20Sopenharmony_ci	{0x11, 0x11, 0x0f, 0x09, 0x00, 0x00, 0x00, 0x00},    /* 20, -10.0dB */
1198c2ecf20Sopenharmony_ci	{0x10, 0x10, 0x0e, 0x08, 0x00, 0x00, 0x00, 0x00},    /* 21, -10.5dB */
1208c2ecf20Sopenharmony_ci	{0x0f, 0x0f, 0x0d, 0x08, 0x00, 0x00, 0x00, 0x00},    /* 22, -11.0dB */
1218c2ecf20Sopenharmony_ci	{0x0e, 0x0e, 0x0c, 0x07, 0x00, 0x00, 0x00, 0x00},    /* 23, -11.5dB */
1228c2ecf20Sopenharmony_ci	{0x0d, 0x0d, 0x0c, 0x07, 0x00, 0x00, 0x00, 0x00},    /* 24, -12.0dB */
1238c2ecf20Sopenharmony_ci	{0x0d, 0x0c, 0x0b, 0x06, 0x00, 0x00, 0x00, 0x00},    /* 25, -12.5dB */
1248c2ecf20Sopenharmony_ci	{0x0c, 0x0c, 0x0a, 0x06, 0x00, 0x00, 0x00, 0x00},    /* 26, -13.0dB */
1258c2ecf20Sopenharmony_ci	{0x0b, 0x0b, 0x0a, 0x06, 0x00, 0x00, 0x00, 0x00},    /* 27, -13.5dB */
1268c2ecf20Sopenharmony_ci	{0x0b, 0x0a, 0x09, 0x05, 0x00, 0x00, 0x00, 0x00},    /* 28, -14.0dB */
1278c2ecf20Sopenharmony_ci	{0x0a, 0x0a, 0x09, 0x05, 0x00, 0x00, 0x00, 0x00},    /* 29, -14.5dB */
1288c2ecf20Sopenharmony_ci	{0x0a, 0x09, 0x08, 0x05, 0x00, 0x00, 0x00, 0x00},    /* 30, -15.0dB */
1298c2ecf20Sopenharmony_ci	{0x09, 0x09, 0x08, 0x05, 0x00, 0x00, 0x00, 0x00},    /* 31, -15.5dB */
1308c2ecf20Sopenharmony_ci	{0x09, 0x08, 0x07, 0x04, 0x00, 0x00, 0x00, 0x00}     /* 32, -16.0dB */
1318c2ecf20Sopenharmony_ci};
1328c2ecf20Sopenharmony_ci
1338c2ecf20Sopenharmony_cistatic void rtl92d_dm_false_alarm_counter_statistics(struct ieee80211_hw *hw)
1348c2ecf20Sopenharmony_ci{
1358c2ecf20Sopenharmony_ci	u32 ret_value;
1368c2ecf20Sopenharmony_ci	struct rtl_priv *rtlpriv = rtl_priv(hw);
1378c2ecf20Sopenharmony_ci	struct false_alarm_statistics *falsealm_cnt = &(rtlpriv->falsealm_cnt);
1388c2ecf20Sopenharmony_ci	unsigned long flag = 0;
1398c2ecf20Sopenharmony_ci
1408c2ecf20Sopenharmony_ci	/* hold ofdm counter */
1418c2ecf20Sopenharmony_ci	rtl_set_bbreg(hw, ROFDM0_LSTF, BIT(31), 1); /* hold page C counter */
1428c2ecf20Sopenharmony_ci	rtl_set_bbreg(hw, ROFDM1_LSTF, BIT(31), 1); /*hold page D counter */
1438c2ecf20Sopenharmony_ci
1448c2ecf20Sopenharmony_ci	ret_value = rtl_get_bbreg(hw, ROFDM0_FRAMESYNC, MASKDWORD);
1458c2ecf20Sopenharmony_ci	falsealm_cnt->cnt_fast_fsync_fail = (ret_value & 0xffff);
1468c2ecf20Sopenharmony_ci	falsealm_cnt->cnt_sb_search_fail = ((ret_value & 0xffff0000) >> 16);
1478c2ecf20Sopenharmony_ci	ret_value = rtl_get_bbreg(hw, ROFDM_PHYCOUNTER1, MASKDWORD);
1488c2ecf20Sopenharmony_ci	falsealm_cnt->cnt_parity_fail = ((ret_value & 0xffff0000) >> 16);
1498c2ecf20Sopenharmony_ci	ret_value = rtl_get_bbreg(hw, ROFDM_PHYCOUNTER2, MASKDWORD);
1508c2ecf20Sopenharmony_ci	falsealm_cnt->cnt_rate_illegal = (ret_value & 0xffff);
1518c2ecf20Sopenharmony_ci	falsealm_cnt->cnt_crc8_fail = ((ret_value & 0xffff0000) >> 16);
1528c2ecf20Sopenharmony_ci	ret_value = rtl_get_bbreg(hw, ROFDM_PHYCOUNTER3, MASKDWORD);
1538c2ecf20Sopenharmony_ci	falsealm_cnt->cnt_mcs_fail = (ret_value & 0xffff);
1548c2ecf20Sopenharmony_ci	falsealm_cnt->cnt_ofdm_fail = falsealm_cnt->cnt_parity_fail +
1558c2ecf20Sopenharmony_ci				      falsealm_cnt->cnt_rate_illegal +
1568c2ecf20Sopenharmony_ci				      falsealm_cnt->cnt_crc8_fail +
1578c2ecf20Sopenharmony_ci				      falsealm_cnt->cnt_mcs_fail +
1588c2ecf20Sopenharmony_ci				      falsealm_cnt->cnt_fast_fsync_fail +
1598c2ecf20Sopenharmony_ci				      falsealm_cnt->cnt_sb_search_fail;
1608c2ecf20Sopenharmony_ci
1618c2ecf20Sopenharmony_ci	if (rtlpriv->rtlhal.current_bandtype != BAND_ON_5G) {
1628c2ecf20Sopenharmony_ci		/* hold cck counter */
1638c2ecf20Sopenharmony_ci		rtl92d_acquire_cckandrw_pagea_ctl(hw, &flag);
1648c2ecf20Sopenharmony_ci		ret_value = rtl_get_bbreg(hw, RCCK0_FACOUNTERLOWER, MASKBYTE0);
1658c2ecf20Sopenharmony_ci		falsealm_cnt->cnt_cck_fail = ret_value;
1668c2ecf20Sopenharmony_ci		ret_value = rtl_get_bbreg(hw, RCCK0_FACOUNTERUPPER, MASKBYTE3);
1678c2ecf20Sopenharmony_ci		falsealm_cnt->cnt_cck_fail += (ret_value & 0xff) << 8;
1688c2ecf20Sopenharmony_ci		rtl92d_release_cckandrw_pagea_ctl(hw, &flag);
1698c2ecf20Sopenharmony_ci	} else {
1708c2ecf20Sopenharmony_ci		falsealm_cnt->cnt_cck_fail = 0;
1718c2ecf20Sopenharmony_ci	}
1728c2ecf20Sopenharmony_ci
1738c2ecf20Sopenharmony_ci	/* reset false alarm counter registers */
1748c2ecf20Sopenharmony_ci	falsealm_cnt->cnt_all = falsealm_cnt->cnt_fast_fsync_fail +
1758c2ecf20Sopenharmony_ci				falsealm_cnt->cnt_sb_search_fail +
1768c2ecf20Sopenharmony_ci				falsealm_cnt->cnt_parity_fail +
1778c2ecf20Sopenharmony_ci				falsealm_cnt->cnt_rate_illegal +
1788c2ecf20Sopenharmony_ci				falsealm_cnt->cnt_crc8_fail +
1798c2ecf20Sopenharmony_ci				falsealm_cnt->cnt_mcs_fail +
1808c2ecf20Sopenharmony_ci				falsealm_cnt->cnt_cck_fail;
1818c2ecf20Sopenharmony_ci
1828c2ecf20Sopenharmony_ci	rtl_set_bbreg(hw, ROFDM1_LSTF, 0x08000000, 1);
1838c2ecf20Sopenharmony_ci	/* update ofdm counter */
1848c2ecf20Sopenharmony_ci	rtl_set_bbreg(hw, ROFDM1_LSTF, 0x08000000, 0);
1858c2ecf20Sopenharmony_ci	/* update page C counter */
1868c2ecf20Sopenharmony_ci	rtl_set_bbreg(hw, ROFDM0_LSTF, BIT(31), 0);
1878c2ecf20Sopenharmony_ci	/* update page D counter */
1888c2ecf20Sopenharmony_ci	rtl_set_bbreg(hw, ROFDM1_LSTF, BIT(31), 0);
1898c2ecf20Sopenharmony_ci	if (rtlpriv->rtlhal.current_bandtype != BAND_ON_5G) {
1908c2ecf20Sopenharmony_ci		/* reset cck counter */
1918c2ecf20Sopenharmony_ci		rtl92d_acquire_cckandrw_pagea_ctl(hw, &flag);
1928c2ecf20Sopenharmony_ci		rtl_set_bbreg(hw, RCCK0_FALSEALARMREPORT, 0x0000c000, 0);
1938c2ecf20Sopenharmony_ci		/* enable cck counter */
1948c2ecf20Sopenharmony_ci		rtl_set_bbreg(hw, RCCK0_FALSEALARMREPORT, 0x0000c000, 2);
1958c2ecf20Sopenharmony_ci		rtl92d_release_cckandrw_pagea_ctl(hw, &flag);
1968c2ecf20Sopenharmony_ci	}
1978c2ecf20Sopenharmony_ci	rtl_dbg(rtlpriv, COMP_DIG, DBG_LOUD,
1988c2ecf20Sopenharmony_ci		"Cnt_Fast_Fsync_fail = %x, Cnt_SB_Search_fail = %x\n",
1998c2ecf20Sopenharmony_ci		falsealm_cnt->cnt_fast_fsync_fail,
2008c2ecf20Sopenharmony_ci		falsealm_cnt->cnt_sb_search_fail);
2018c2ecf20Sopenharmony_ci	rtl_dbg(rtlpriv, COMP_DIG, DBG_LOUD,
2028c2ecf20Sopenharmony_ci		"Cnt_Parity_Fail = %x, Cnt_Rate_Illegal = %x, Cnt_Crc8_fail = %x, Cnt_Mcs_fail = %x\n",
2038c2ecf20Sopenharmony_ci		falsealm_cnt->cnt_parity_fail,
2048c2ecf20Sopenharmony_ci		falsealm_cnt->cnt_rate_illegal,
2058c2ecf20Sopenharmony_ci		falsealm_cnt->cnt_crc8_fail,
2068c2ecf20Sopenharmony_ci		falsealm_cnt->cnt_mcs_fail);
2078c2ecf20Sopenharmony_ci	rtl_dbg(rtlpriv, COMP_DIG, DBG_LOUD,
2088c2ecf20Sopenharmony_ci		"Cnt_Ofdm_fail = %x, Cnt_Cck_fail = %x, Cnt_all = %x\n",
2098c2ecf20Sopenharmony_ci		falsealm_cnt->cnt_ofdm_fail,
2108c2ecf20Sopenharmony_ci		falsealm_cnt->cnt_cck_fail,
2118c2ecf20Sopenharmony_ci		falsealm_cnt->cnt_all);
2128c2ecf20Sopenharmony_ci}
2138c2ecf20Sopenharmony_ci
2148c2ecf20Sopenharmony_cistatic void rtl92d_dm_find_minimum_rssi(struct ieee80211_hw *hw)
2158c2ecf20Sopenharmony_ci{
2168c2ecf20Sopenharmony_ci	struct rtl_priv *rtlpriv = rtl_priv(hw);
2178c2ecf20Sopenharmony_ci	struct dig_t *de_digtable = &rtlpriv->dm_digtable;
2188c2ecf20Sopenharmony_ci	struct rtl_mac *mac = rtl_mac(rtlpriv);
2198c2ecf20Sopenharmony_ci
2208c2ecf20Sopenharmony_ci	/* Determine the minimum RSSI  */
2218c2ecf20Sopenharmony_ci	if ((mac->link_state < MAC80211_LINKED) &&
2228c2ecf20Sopenharmony_ci	    (rtlpriv->dm.UNDEC_SM_PWDB == 0)) {
2238c2ecf20Sopenharmony_ci		de_digtable->min_undec_pwdb_for_dm = 0;
2248c2ecf20Sopenharmony_ci		rtl_dbg(rtlpriv, COMP_BB_POWERSAVING, DBG_LOUD,
2258c2ecf20Sopenharmony_ci			"Not connected to any\n");
2268c2ecf20Sopenharmony_ci	}
2278c2ecf20Sopenharmony_ci	if (mac->link_state >= MAC80211_LINKED) {
2288c2ecf20Sopenharmony_ci		if (mac->opmode == NL80211_IFTYPE_AP ||
2298c2ecf20Sopenharmony_ci		    mac->opmode == NL80211_IFTYPE_ADHOC) {
2308c2ecf20Sopenharmony_ci			de_digtable->min_undec_pwdb_for_dm =
2318c2ecf20Sopenharmony_ci			    rtlpriv->dm.UNDEC_SM_PWDB;
2328c2ecf20Sopenharmony_ci			rtl_dbg(rtlpriv, COMP_BB_POWERSAVING, DBG_LOUD,
2338c2ecf20Sopenharmony_ci				"AP Client PWDB = 0x%lx\n",
2348c2ecf20Sopenharmony_ci				 rtlpriv->dm.UNDEC_SM_PWDB);
2358c2ecf20Sopenharmony_ci		} else {
2368c2ecf20Sopenharmony_ci			de_digtable->min_undec_pwdb_for_dm =
2378c2ecf20Sopenharmony_ci			    rtlpriv->dm.undec_sm_pwdb;
2388c2ecf20Sopenharmony_ci			rtl_dbg(rtlpriv, COMP_BB_POWERSAVING, DBG_LOUD,
2398c2ecf20Sopenharmony_ci				"STA Default Port PWDB = 0x%x\n",
2408c2ecf20Sopenharmony_ci				de_digtable->min_undec_pwdb_for_dm);
2418c2ecf20Sopenharmony_ci		}
2428c2ecf20Sopenharmony_ci	} else {
2438c2ecf20Sopenharmony_ci		de_digtable->min_undec_pwdb_for_dm = rtlpriv->dm.UNDEC_SM_PWDB;
2448c2ecf20Sopenharmony_ci		rtl_dbg(rtlpriv, COMP_BB_POWERSAVING, DBG_LOUD,
2458c2ecf20Sopenharmony_ci			"AP Ext Port or disconnect PWDB = 0x%x\n",
2468c2ecf20Sopenharmony_ci			de_digtable->min_undec_pwdb_for_dm);
2478c2ecf20Sopenharmony_ci	}
2488c2ecf20Sopenharmony_ci
2498c2ecf20Sopenharmony_ci	rtl_dbg(rtlpriv, COMP_DIG, DBG_LOUD, "MinUndecoratedPWDBForDM =%d\n",
2508c2ecf20Sopenharmony_ci		de_digtable->min_undec_pwdb_for_dm);
2518c2ecf20Sopenharmony_ci}
2528c2ecf20Sopenharmony_ci
2538c2ecf20Sopenharmony_cistatic void rtl92d_dm_cck_packet_detection_thresh(struct ieee80211_hw *hw)
2548c2ecf20Sopenharmony_ci{
2558c2ecf20Sopenharmony_ci	struct rtl_priv *rtlpriv = rtl_priv(hw);
2568c2ecf20Sopenharmony_ci	struct dig_t *de_digtable = &rtlpriv->dm_digtable;
2578c2ecf20Sopenharmony_ci	unsigned long flag = 0;
2588c2ecf20Sopenharmony_ci
2598c2ecf20Sopenharmony_ci	if (de_digtable->cursta_cstate == DIG_STA_CONNECT) {
2608c2ecf20Sopenharmony_ci		if (de_digtable->pre_cck_pd_state == CCK_PD_STAGE_LOWRSSI) {
2618c2ecf20Sopenharmony_ci			if (de_digtable->min_undec_pwdb_for_dm <= 25)
2628c2ecf20Sopenharmony_ci				de_digtable->cur_cck_pd_state =
2638c2ecf20Sopenharmony_ci							 CCK_PD_STAGE_LOWRSSI;
2648c2ecf20Sopenharmony_ci			else
2658c2ecf20Sopenharmony_ci				de_digtable->cur_cck_pd_state =
2668c2ecf20Sopenharmony_ci							 CCK_PD_STAGE_HIGHRSSI;
2678c2ecf20Sopenharmony_ci		} else {
2688c2ecf20Sopenharmony_ci			if (de_digtable->min_undec_pwdb_for_dm <= 20)
2698c2ecf20Sopenharmony_ci				de_digtable->cur_cck_pd_state =
2708c2ecf20Sopenharmony_ci							 CCK_PD_STAGE_LOWRSSI;
2718c2ecf20Sopenharmony_ci			else
2728c2ecf20Sopenharmony_ci				de_digtable->cur_cck_pd_state =
2738c2ecf20Sopenharmony_ci							 CCK_PD_STAGE_HIGHRSSI;
2748c2ecf20Sopenharmony_ci		}
2758c2ecf20Sopenharmony_ci	} else {
2768c2ecf20Sopenharmony_ci		de_digtable->cur_cck_pd_state = CCK_PD_STAGE_LOWRSSI;
2778c2ecf20Sopenharmony_ci	}
2788c2ecf20Sopenharmony_ci	if (de_digtable->pre_cck_pd_state != de_digtable->cur_cck_pd_state) {
2798c2ecf20Sopenharmony_ci		if (de_digtable->cur_cck_pd_state == CCK_PD_STAGE_LOWRSSI) {
2808c2ecf20Sopenharmony_ci			rtl92d_acquire_cckandrw_pagea_ctl(hw, &flag);
2818c2ecf20Sopenharmony_ci			rtl_set_bbreg(hw, RCCK0_CCA, MASKBYTE2, 0x83);
2828c2ecf20Sopenharmony_ci			rtl92d_release_cckandrw_pagea_ctl(hw, &flag);
2838c2ecf20Sopenharmony_ci		} else {
2848c2ecf20Sopenharmony_ci			rtl92d_acquire_cckandrw_pagea_ctl(hw, &flag);
2858c2ecf20Sopenharmony_ci			rtl_set_bbreg(hw, RCCK0_CCA, MASKBYTE2, 0xcd);
2868c2ecf20Sopenharmony_ci			rtl92d_release_cckandrw_pagea_ctl(hw, &flag);
2878c2ecf20Sopenharmony_ci		}
2888c2ecf20Sopenharmony_ci		de_digtable->pre_cck_pd_state = de_digtable->cur_cck_pd_state;
2898c2ecf20Sopenharmony_ci	}
2908c2ecf20Sopenharmony_ci	rtl_dbg(rtlpriv, COMP_DIG, DBG_LOUD, "CurSTAConnectState=%s\n",
2918c2ecf20Sopenharmony_ci		de_digtable->cursta_cstate == DIG_STA_CONNECT ?
2928c2ecf20Sopenharmony_ci		"DIG_STA_CONNECT " : "DIG_STA_DISCONNECT");
2938c2ecf20Sopenharmony_ci	rtl_dbg(rtlpriv, COMP_DIG, DBG_LOUD, "CCKPDStage=%s\n",
2948c2ecf20Sopenharmony_ci		de_digtable->cur_cck_pd_state == CCK_PD_STAGE_LOWRSSI ?
2958c2ecf20Sopenharmony_ci		"Low RSSI " : "High RSSI ");
2968c2ecf20Sopenharmony_ci	rtl_dbg(rtlpriv, COMP_DIG, DBG_LOUD, "is92d single phy =%x\n",
2978c2ecf20Sopenharmony_ci		IS_92D_SINGLEPHY(rtlpriv->rtlhal.version));
2988c2ecf20Sopenharmony_ci
2998c2ecf20Sopenharmony_ci}
3008c2ecf20Sopenharmony_ci
3018c2ecf20Sopenharmony_civoid rtl92d_dm_write_dig(struct ieee80211_hw *hw)
3028c2ecf20Sopenharmony_ci{
3038c2ecf20Sopenharmony_ci	struct rtl_priv *rtlpriv = rtl_priv(hw);
3048c2ecf20Sopenharmony_ci	struct dig_t *de_digtable = &rtlpriv->dm_digtable;
3058c2ecf20Sopenharmony_ci
3068c2ecf20Sopenharmony_ci	rtl_dbg(rtlpriv, COMP_DIG, DBG_LOUD,
3078c2ecf20Sopenharmony_ci		"cur_igvalue = 0x%x, pre_igvalue = 0x%x, back_val = %d\n",
3088c2ecf20Sopenharmony_ci		de_digtable->cur_igvalue, de_digtable->pre_igvalue,
3098c2ecf20Sopenharmony_ci		de_digtable->back_val);
3108c2ecf20Sopenharmony_ci	if (de_digtable->dig_enable_flag == false) {
3118c2ecf20Sopenharmony_ci		rtl_dbg(rtlpriv, COMP_DIG, DBG_LOUD, "DIG is disabled\n");
3128c2ecf20Sopenharmony_ci		de_digtable->pre_igvalue = 0x17;
3138c2ecf20Sopenharmony_ci		return;
3148c2ecf20Sopenharmony_ci	}
3158c2ecf20Sopenharmony_ci	if (de_digtable->pre_igvalue != de_digtable->cur_igvalue) {
3168c2ecf20Sopenharmony_ci		rtl_set_bbreg(hw, ROFDM0_XAAGCCORE1, 0x7f,
3178c2ecf20Sopenharmony_ci			      de_digtable->cur_igvalue);
3188c2ecf20Sopenharmony_ci		rtl_set_bbreg(hw, ROFDM0_XBAGCCORE1, 0x7f,
3198c2ecf20Sopenharmony_ci			      de_digtable->cur_igvalue);
3208c2ecf20Sopenharmony_ci		de_digtable->pre_igvalue = de_digtable->cur_igvalue;
3218c2ecf20Sopenharmony_ci	}
3228c2ecf20Sopenharmony_ci}
3238c2ecf20Sopenharmony_ci
3248c2ecf20Sopenharmony_cistatic void rtl92d_early_mode_enabled(struct rtl_priv *rtlpriv)
3258c2ecf20Sopenharmony_ci{
3268c2ecf20Sopenharmony_ci	struct dig_t *de_digtable = &rtlpriv->dm_digtable;
3278c2ecf20Sopenharmony_ci
3288c2ecf20Sopenharmony_ci	if ((rtlpriv->mac80211.link_state >= MAC80211_LINKED) &&
3298c2ecf20Sopenharmony_ci	    (rtlpriv->mac80211.vendor == PEER_CISCO)) {
3308c2ecf20Sopenharmony_ci		rtl_dbg(rtlpriv, COMP_DIG, DBG_LOUD, "IOT_PEER = CISCO\n");
3318c2ecf20Sopenharmony_ci		if (de_digtable->last_min_undec_pwdb_for_dm >= 50
3328c2ecf20Sopenharmony_ci		    && de_digtable->min_undec_pwdb_for_dm < 50) {
3338c2ecf20Sopenharmony_ci			rtl_write_byte(rtlpriv, REG_EARLY_MODE_CONTROL, 0x00);
3348c2ecf20Sopenharmony_ci			rtl_dbg(rtlpriv, COMP_DIG, DBG_LOUD,
3358c2ecf20Sopenharmony_ci				"Early Mode Off\n");
3368c2ecf20Sopenharmony_ci		} else if (de_digtable->last_min_undec_pwdb_for_dm <= 55 &&
3378c2ecf20Sopenharmony_ci			   de_digtable->min_undec_pwdb_for_dm > 55) {
3388c2ecf20Sopenharmony_ci			rtl_write_byte(rtlpriv, REG_EARLY_MODE_CONTROL, 0x0f);
3398c2ecf20Sopenharmony_ci			rtl_dbg(rtlpriv, COMP_DIG, DBG_LOUD,
3408c2ecf20Sopenharmony_ci				"Early Mode On\n");
3418c2ecf20Sopenharmony_ci		}
3428c2ecf20Sopenharmony_ci	} else if (!(rtl_read_byte(rtlpriv, REG_EARLY_MODE_CONTROL) & 0xf)) {
3438c2ecf20Sopenharmony_ci		rtl_write_byte(rtlpriv, REG_EARLY_MODE_CONTROL, 0x0f);
3448c2ecf20Sopenharmony_ci		rtl_dbg(rtlpriv, COMP_DIG, DBG_LOUD, "Early Mode On\n");
3458c2ecf20Sopenharmony_ci	}
3468c2ecf20Sopenharmony_ci}
3478c2ecf20Sopenharmony_ci
3488c2ecf20Sopenharmony_cistatic void rtl92d_dm_dig(struct ieee80211_hw *hw)
3498c2ecf20Sopenharmony_ci{
3508c2ecf20Sopenharmony_ci	struct rtl_priv *rtlpriv = rtl_priv(hw);
3518c2ecf20Sopenharmony_ci	struct dig_t *de_digtable = &rtlpriv->dm_digtable;
3528c2ecf20Sopenharmony_ci	u8 value_igi = de_digtable->cur_igvalue;
3538c2ecf20Sopenharmony_ci	struct false_alarm_statistics *falsealm_cnt = &(rtlpriv->falsealm_cnt);
3548c2ecf20Sopenharmony_ci
3558c2ecf20Sopenharmony_ci	rtl_dbg(rtlpriv, COMP_DIG, DBG_LOUD, "==>\n");
3568c2ecf20Sopenharmony_ci	if (rtlpriv->rtlhal.earlymode_enable) {
3578c2ecf20Sopenharmony_ci		rtl92d_early_mode_enabled(rtlpriv);
3588c2ecf20Sopenharmony_ci		de_digtable->last_min_undec_pwdb_for_dm =
3598c2ecf20Sopenharmony_ci				 de_digtable->min_undec_pwdb_for_dm;
3608c2ecf20Sopenharmony_ci	}
3618c2ecf20Sopenharmony_ci	if (!rtlpriv->dm.dm_initialgain_enable)
3628c2ecf20Sopenharmony_ci		return;
3638c2ecf20Sopenharmony_ci
3648c2ecf20Sopenharmony_ci	/* because we will send data pkt when scanning
3658c2ecf20Sopenharmony_ci	 * this will cause some ap like gear-3700 wep TP
3668c2ecf20Sopenharmony_ci	 * lower if we return here, this is the diff of
3678c2ecf20Sopenharmony_ci	 * mac80211 driver vs ieee80211 driver */
3688c2ecf20Sopenharmony_ci	/* if (rtlpriv->mac80211.act_scanning)
3698c2ecf20Sopenharmony_ci	 *      return; */
3708c2ecf20Sopenharmony_ci
3718c2ecf20Sopenharmony_ci	/* Not STA mode return tmp */
3728c2ecf20Sopenharmony_ci	if (rtlpriv->mac80211.opmode != NL80211_IFTYPE_STATION)
3738c2ecf20Sopenharmony_ci		return;
3748c2ecf20Sopenharmony_ci	rtl_dbg(rtlpriv, COMP_DIG, DBG_LOUD, "progress\n");
3758c2ecf20Sopenharmony_ci	/* Decide the current status and if modify initial gain or not */
3768c2ecf20Sopenharmony_ci	if (rtlpriv->mac80211.link_state >= MAC80211_LINKED)
3778c2ecf20Sopenharmony_ci		de_digtable->cursta_cstate = DIG_STA_CONNECT;
3788c2ecf20Sopenharmony_ci	else
3798c2ecf20Sopenharmony_ci		de_digtable->cursta_cstate = DIG_STA_DISCONNECT;
3808c2ecf20Sopenharmony_ci
3818c2ecf20Sopenharmony_ci	/* adjust initial gain according to false alarm counter */
3828c2ecf20Sopenharmony_ci	if (falsealm_cnt->cnt_all < DM_DIG_FA_TH0)
3838c2ecf20Sopenharmony_ci		value_igi--;
3848c2ecf20Sopenharmony_ci	else if (falsealm_cnt->cnt_all < DM_DIG_FA_TH1)
3858c2ecf20Sopenharmony_ci		value_igi += 0;
3868c2ecf20Sopenharmony_ci	else if (falsealm_cnt->cnt_all < DM_DIG_FA_TH2)
3878c2ecf20Sopenharmony_ci		value_igi++;
3888c2ecf20Sopenharmony_ci	else if (falsealm_cnt->cnt_all >= DM_DIG_FA_TH2)
3898c2ecf20Sopenharmony_ci		value_igi += 2;
3908c2ecf20Sopenharmony_ci	rtl_dbg(rtlpriv, COMP_DIG, DBG_LOUD,
3918c2ecf20Sopenharmony_ci		"dm_DIG() Before: large_fa_hit=%d, forbidden_igi=%x\n",
3928c2ecf20Sopenharmony_ci		de_digtable->large_fa_hit, de_digtable->forbidden_igi);
3938c2ecf20Sopenharmony_ci	rtl_dbg(rtlpriv, COMP_DIG, DBG_LOUD,
3948c2ecf20Sopenharmony_ci		"dm_DIG() Before: Recover_cnt=%d, rx_gain_min=%x\n",
3958c2ecf20Sopenharmony_ci		de_digtable->recover_cnt, de_digtable->rx_gain_min);
3968c2ecf20Sopenharmony_ci
3978c2ecf20Sopenharmony_ci	/* deal with abnormally large false alarm */
3988c2ecf20Sopenharmony_ci	if (falsealm_cnt->cnt_all > 10000) {
3998c2ecf20Sopenharmony_ci		rtl_dbg(rtlpriv, COMP_DIG, DBG_LOUD,
4008c2ecf20Sopenharmony_ci			"dm_DIG(): Abnormally false alarm case\n");
4018c2ecf20Sopenharmony_ci
4028c2ecf20Sopenharmony_ci		de_digtable->large_fa_hit++;
4038c2ecf20Sopenharmony_ci		if (de_digtable->forbidden_igi < de_digtable->cur_igvalue) {
4048c2ecf20Sopenharmony_ci			de_digtable->forbidden_igi = de_digtable->cur_igvalue;
4058c2ecf20Sopenharmony_ci			de_digtable->large_fa_hit = 1;
4068c2ecf20Sopenharmony_ci		}
4078c2ecf20Sopenharmony_ci		if (de_digtable->large_fa_hit >= 3) {
4088c2ecf20Sopenharmony_ci			if ((de_digtable->forbidden_igi + 1) > DM_DIG_MAX)
4098c2ecf20Sopenharmony_ci				de_digtable->rx_gain_min = DM_DIG_MAX;
4108c2ecf20Sopenharmony_ci			else
4118c2ecf20Sopenharmony_ci				de_digtable->rx_gain_min =
4128c2ecf20Sopenharmony_ci				    (de_digtable->forbidden_igi + 1);
4138c2ecf20Sopenharmony_ci			de_digtable->recover_cnt = 3600;	/* 3600=2hr */
4148c2ecf20Sopenharmony_ci		}
4158c2ecf20Sopenharmony_ci	} else {
4168c2ecf20Sopenharmony_ci		/* Recovery mechanism for IGI lower bound */
4178c2ecf20Sopenharmony_ci		if (de_digtable->recover_cnt != 0) {
4188c2ecf20Sopenharmony_ci			de_digtable->recover_cnt--;
4198c2ecf20Sopenharmony_ci		} else {
4208c2ecf20Sopenharmony_ci			if (de_digtable->large_fa_hit == 0) {
4218c2ecf20Sopenharmony_ci				if ((de_digtable->forbidden_igi - 1) <
4228c2ecf20Sopenharmony_ci				    DM_DIG_FA_LOWER) {
4238c2ecf20Sopenharmony_ci					de_digtable->forbidden_igi =
4248c2ecf20Sopenharmony_ci							 DM_DIG_FA_LOWER;
4258c2ecf20Sopenharmony_ci					de_digtable->rx_gain_min =
4268c2ecf20Sopenharmony_ci							 DM_DIG_FA_LOWER;
4278c2ecf20Sopenharmony_ci
4288c2ecf20Sopenharmony_ci				} else {
4298c2ecf20Sopenharmony_ci					de_digtable->forbidden_igi--;
4308c2ecf20Sopenharmony_ci					de_digtable->rx_gain_min =
4318c2ecf20Sopenharmony_ci					    (de_digtable->forbidden_igi + 1);
4328c2ecf20Sopenharmony_ci				}
4338c2ecf20Sopenharmony_ci			} else if (de_digtable->large_fa_hit == 3) {
4348c2ecf20Sopenharmony_ci				de_digtable->large_fa_hit = 0;
4358c2ecf20Sopenharmony_ci			}
4368c2ecf20Sopenharmony_ci		}
4378c2ecf20Sopenharmony_ci	}
4388c2ecf20Sopenharmony_ci	rtl_dbg(rtlpriv, COMP_DIG, DBG_LOUD,
4398c2ecf20Sopenharmony_ci		"dm_DIG() After: large_fa_hit=%d, forbidden_igi=%x\n",
4408c2ecf20Sopenharmony_ci		de_digtable->large_fa_hit, de_digtable->forbidden_igi);
4418c2ecf20Sopenharmony_ci	rtl_dbg(rtlpriv, COMP_DIG, DBG_LOUD,
4428c2ecf20Sopenharmony_ci		"dm_DIG() After: recover_cnt=%d, rx_gain_min=%x\n",
4438c2ecf20Sopenharmony_ci		de_digtable->recover_cnt, de_digtable->rx_gain_min);
4448c2ecf20Sopenharmony_ci
4458c2ecf20Sopenharmony_ci	if (value_igi > DM_DIG_MAX)
4468c2ecf20Sopenharmony_ci		value_igi = DM_DIG_MAX;
4478c2ecf20Sopenharmony_ci	else if (value_igi < de_digtable->rx_gain_min)
4488c2ecf20Sopenharmony_ci		value_igi = de_digtable->rx_gain_min;
4498c2ecf20Sopenharmony_ci	de_digtable->cur_igvalue = value_igi;
4508c2ecf20Sopenharmony_ci	rtl92d_dm_write_dig(hw);
4518c2ecf20Sopenharmony_ci	if (rtlpriv->rtlhal.current_bandtype != BAND_ON_5G)
4528c2ecf20Sopenharmony_ci		rtl92d_dm_cck_packet_detection_thresh(hw);
4538c2ecf20Sopenharmony_ci	rtl_dbg(rtlpriv, COMP_DIG, DBG_LOUD, "<<==\n");
4548c2ecf20Sopenharmony_ci}
4558c2ecf20Sopenharmony_ci
4568c2ecf20Sopenharmony_cistatic void rtl92d_dm_init_dynamic_txpower(struct ieee80211_hw *hw)
4578c2ecf20Sopenharmony_ci{
4588c2ecf20Sopenharmony_ci	struct rtl_priv *rtlpriv = rtl_priv(hw);
4598c2ecf20Sopenharmony_ci
4608c2ecf20Sopenharmony_ci	rtlpriv->dm.dynamic_txpower_enable = true;
4618c2ecf20Sopenharmony_ci	rtlpriv->dm.last_dtp_lvl = TXHIGHPWRLEVEL_NORMAL;
4628c2ecf20Sopenharmony_ci	rtlpriv->dm.dynamic_txhighpower_lvl = TXHIGHPWRLEVEL_NORMAL;
4638c2ecf20Sopenharmony_ci}
4648c2ecf20Sopenharmony_ci
4658c2ecf20Sopenharmony_cistatic void rtl92d_dm_dynamic_txpower(struct ieee80211_hw *hw)
4668c2ecf20Sopenharmony_ci{
4678c2ecf20Sopenharmony_ci	struct rtl_priv *rtlpriv = rtl_priv(hw);
4688c2ecf20Sopenharmony_ci	struct rtl_phy *rtlphy = &(rtlpriv->phy);
4698c2ecf20Sopenharmony_ci	struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
4708c2ecf20Sopenharmony_ci	struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
4718c2ecf20Sopenharmony_ci	long undec_sm_pwdb;
4728c2ecf20Sopenharmony_ci
4738c2ecf20Sopenharmony_ci	if ((!rtlpriv->dm.dynamic_txpower_enable)
4748c2ecf20Sopenharmony_ci	    || rtlpriv->dm.dm_flag & HAL_DM_HIPWR_DISABLE) {
4758c2ecf20Sopenharmony_ci		rtlpriv->dm.dynamic_txhighpower_lvl = TXHIGHPWRLEVEL_NORMAL;
4768c2ecf20Sopenharmony_ci		return;
4778c2ecf20Sopenharmony_ci	}
4788c2ecf20Sopenharmony_ci	if ((mac->link_state < MAC80211_LINKED) &&
4798c2ecf20Sopenharmony_ci	    (rtlpriv->dm.UNDEC_SM_PWDB == 0)) {
4808c2ecf20Sopenharmony_ci		rtl_dbg(rtlpriv, COMP_POWER, DBG_TRACE,
4818c2ecf20Sopenharmony_ci			"Not connected to any\n");
4828c2ecf20Sopenharmony_ci		rtlpriv->dm.dynamic_txhighpower_lvl = TXHIGHPWRLEVEL_NORMAL;
4838c2ecf20Sopenharmony_ci		rtlpriv->dm.last_dtp_lvl = TXHIGHPWRLEVEL_NORMAL;
4848c2ecf20Sopenharmony_ci		return;
4858c2ecf20Sopenharmony_ci	}
4868c2ecf20Sopenharmony_ci	if (mac->link_state >= MAC80211_LINKED) {
4878c2ecf20Sopenharmony_ci		if (mac->opmode == NL80211_IFTYPE_ADHOC) {
4888c2ecf20Sopenharmony_ci			undec_sm_pwdb =
4898c2ecf20Sopenharmony_ci			    rtlpriv->dm.UNDEC_SM_PWDB;
4908c2ecf20Sopenharmony_ci			rtl_dbg(rtlpriv, COMP_POWER, DBG_LOUD,
4918c2ecf20Sopenharmony_ci				"IBSS Client PWDB = 0x%lx\n",
4928c2ecf20Sopenharmony_ci				undec_sm_pwdb);
4938c2ecf20Sopenharmony_ci		} else {
4948c2ecf20Sopenharmony_ci			undec_sm_pwdb =
4958c2ecf20Sopenharmony_ci			    rtlpriv->dm.undec_sm_pwdb;
4968c2ecf20Sopenharmony_ci			rtl_dbg(rtlpriv, COMP_POWER, DBG_LOUD,
4978c2ecf20Sopenharmony_ci				"STA Default Port PWDB = 0x%lx\n",
4988c2ecf20Sopenharmony_ci				undec_sm_pwdb);
4998c2ecf20Sopenharmony_ci		}
5008c2ecf20Sopenharmony_ci	} else {
5018c2ecf20Sopenharmony_ci		undec_sm_pwdb =
5028c2ecf20Sopenharmony_ci		    rtlpriv->dm.UNDEC_SM_PWDB;
5038c2ecf20Sopenharmony_ci
5048c2ecf20Sopenharmony_ci		rtl_dbg(rtlpriv, COMP_POWER, DBG_LOUD,
5058c2ecf20Sopenharmony_ci			"AP Ext Port PWDB = 0x%lx\n",
5068c2ecf20Sopenharmony_ci			undec_sm_pwdb);
5078c2ecf20Sopenharmony_ci	}
5088c2ecf20Sopenharmony_ci	if (rtlhal->current_bandtype == BAND_ON_5G) {
5098c2ecf20Sopenharmony_ci		if (undec_sm_pwdb >= 0x33) {
5108c2ecf20Sopenharmony_ci			rtlpriv->dm.dynamic_txhighpower_lvl =
5118c2ecf20Sopenharmony_ci						 TXHIGHPWRLEVEL_LEVEL2;
5128c2ecf20Sopenharmony_ci			rtl_dbg(rtlpriv, COMP_HIPWR, DBG_LOUD,
5138c2ecf20Sopenharmony_ci				"5G:TxHighPwrLevel_Level2 (TxPwr=0x0)\n");
5148c2ecf20Sopenharmony_ci		} else if ((undec_sm_pwdb < 0x33)
5158c2ecf20Sopenharmony_ci			   && (undec_sm_pwdb >= 0x2b)) {
5168c2ecf20Sopenharmony_ci			rtlpriv->dm.dynamic_txhighpower_lvl =
5178c2ecf20Sopenharmony_ci						 TXHIGHPWRLEVEL_LEVEL1;
5188c2ecf20Sopenharmony_ci			rtl_dbg(rtlpriv, COMP_HIPWR, DBG_LOUD,
5198c2ecf20Sopenharmony_ci				"5G:TxHighPwrLevel_Level1 (TxPwr=0x10)\n");
5208c2ecf20Sopenharmony_ci		} else if (undec_sm_pwdb < 0x2b) {
5218c2ecf20Sopenharmony_ci			rtlpriv->dm.dynamic_txhighpower_lvl =
5228c2ecf20Sopenharmony_ci						 TXHIGHPWRLEVEL_NORMAL;
5238c2ecf20Sopenharmony_ci			rtl_dbg(rtlpriv, COMP_HIPWR, DBG_LOUD,
5248c2ecf20Sopenharmony_ci				"5G:TxHighPwrLevel_Normal\n");
5258c2ecf20Sopenharmony_ci		}
5268c2ecf20Sopenharmony_ci	} else {
5278c2ecf20Sopenharmony_ci		if (undec_sm_pwdb >=
5288c2ecf20Sopenharmony_ci		    TX_POWER_NEAR_FIELD_THRESH_LVL2) {
5298c2ecf20Sopenharmony_ci			rtlpriv->dm.dynamic_txhighpower_lvl =
5308c2ecf20Sopenharmony_ci						 TXHIGHPWRLEVEL_LEVEL2;
5318c2ecf20Sopenharmony_ci			rtl_dbg(rtlpriv, COMP_POWER, DBG_LOUD,
5328c2ecf20Sopenharmony_ci				"TXHIGHPWRLEVEL_LEVEL1 (TxPwr=0x0)\n");
5338c2ecf20Sopenharmony_ci		} else
5348c2ecf20Sopenharmony_ci		    if ((undec_sm_pwdb <
5358c2ecf20Sopenharmony_ci			 (TX_POWER_NEAR_FIELD_THRESH_LVL2 - 3))
5368c2ecf20Sopenharmony_ci			&& (undec_sm_pwdb >=
5378c2ecf20Sopenharmony_ci			    TX_POWER_NEAR_FIELD_THRESH_LVL1)) {
5388c2ecf20Sopenharmony_ci
5398c2ecf20Sopenharmony_ci			rtlpriv->dm.dynamic_txhighpower_lvl =
5408c2ecf20Sopenharmony_ci						 TXHIGHPWRLEVEL_LEVEL1;
5418c2ecf20Sopenharmony_ci			rtl_dbg(rtlpriv, COMP_POWER, DBG_LOUD,
5428c2ecf20Sopenharmony_ci				"TXHIGHPWRLEVEL_LEVEL1 (TxPwr=0x10)\n");
5438c2ecf20Sopenharmony_ci		} else if (undec_sm_pwdb <
5448c2ecf20Sopenharmony_ci			   (TX_POWER_NEAR_FIELD_THRESH_LVL1 - 5)) {
5458c2ecf20Sopenharmony_ci			rtlpriv->dm.dynamic_txhighpower_lvl =
5468c2ecf20Sopenharmony_ci						 TXHIGHPWRLEVEL_NORMAL;
5478c2ecf20Sopenharmony_ci			rtl_dbg(rtlpriv, COMP_POWER, DBG_LOUD,
5488c2ecf20Sopenharmony_ci				"TXHIGHPWRLEVEL_NORMAL\n");
5498c2ecf20Sopenharmony_ci		}
5508c2ecf20Sopenharmony_ci	}
5518c2ecf20Sopenharmony_ci	if ((rtlpriv->dm.dynamic_txhighpower_lvl != rtlpriv->dm.last_dtp_lvl)) {
5528c2ecf20Sopenharmony_ci		rtl_dbg(rtlpriv, COMP_POWER, DBG_LOUD,
5538c2ecf20Sopenharmony_ci			"PHY_SetTxPowerLevel8192S() Channel = %d\n",
5548c2ecf20Sopenharmony_ci			rtlphy->current_channel);
5558c2ecf20Sopenharmony_ci		rtl92d_phy_set_txpower_level(hw, rtlphy->current_channel);
5568c2ecf20Sopenharmony_ci	}
5578c2ecf20Sopenharmony_ci	rtlpriv->dm.last_dtp_lvl = rtlpriv->dm.dynamic_txhighpower_lvl;
5588c2ecf20Sopenharmony_ci}
5598c2ecf20Sopenharmony_ci
5608c2ecf20Sopenharmony_cistatic void rtl92d_dm_pwdb_monitor(struct ieee80211_hw *hw)
5618c2ecf20Sopenharmony_ci{
5628c2ecf20Sopenharmony_ci	struct rtl_priv *rtlpriv = rtl_priv(hw);
5638c2ecf20Sopenharmony_ci
5648c2ecf20Sopenharmony_ci	/* AP & ADHOC & MESH will return tmp */
5658c2ecf20Sopenharmony_ci	if (rtlpriv->mac80211.opmode != NL80211_IFTYPE_STATION)
5668c2ecf20Sopenharmony_ci		return;
5678c2ecf20Sopenharmony_ci	/* Indicate Rx signal strength to FW. */
5688c2ecf20Sopenharmony_ci	if (rtlpriv->dm.useramask) {
5698c2ecf20Sopenharmony_ci		u32 temp = rtlpriv->dm.undec_sm_pwdb;
5708c2ecf20Sopenharmony_ci
5718c2ecf20Sopenharmony_ci		temp <<= 16;
5728c2ecf20Sopenharmony_ci		temp |= 0x100;
5738c2ecf20Sopenharmony_ci		/* fw v12 cmdid 5:use max macid ,for nic ,
5748c2ecf20Sopenharmony_ci		 * default macid is 0 ,max macid is 1 */
5758c2ecf20Sopenharmony_ci		rtl92d_fill_h2c_cmd(hw, H2C_RSSI_REPORT, 3, (u8 *) (&temp));
5768c2ecf20Sopenharmony_ci	} else {
5778c2ecf20Sopenharmony_ci		rtl_write_byte(rtlpriv, 0x4fe,
5788c2ecf20Sopenharmony_ci			       (u8) rtlpriv->dm.undec_sm_pwdb);
5798c2ecf20Sopenharmony_ci	}
5808c2ecf20Sopenharmony_ci}
5818c2ecf20Sopenharmony_ci
5828c2ecf20Sopenharmony_civoid rtl92d_dm_init_edca_turbo(struct ieee80211_hw *hw)
5838c2ecf20Sopenharmony_ci{
5848c2ecf20Sopenharmony_ci	struct rtl_priv *rtlpriv = rtl_priv(hw);
5858c2ecf20Sopenharmony_ci
5868c2ecf20Sopenharmony_ci	rtlpriv->dm.current_turbo_edca = false;
5878c2ecf20Sopenharmony_ci	rtlpriv->dm.is_any_nonbepkts = false;
5888c2ecf20Sopenharmony_ci	rtlpriv->dm.is_cur_rdlstate = false;
5898c2ecf20Sopenharmony_ci}
5908c2ecf20Sopenharmony_ci
5918c2ecf20Sopenharmony_cistatic void rtl92d_dm_check_edca_turbo(struct ieee80211_hw *hw)
5928c2ecf20Sopenharmony_ci{
5938c2ecf20Sopenharmony_ci	struct rtl_priv *rtlpriv = rtl_priv(hw);
5948c2ecf20Sopenharmony_ci	struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
5958c2ecf20Sopenharmony_ci	static u64 last_txok_cnt;
5968c2ecf20Sopenharmony_ci	static u64 last_rxok_cnt;
5978c2ecf20Sopenharmony_ci	u64 cur_txok_cnt;
5988c2ecf20Sopenharmony_ci	u64 cur_rxok_cnt;
5998c2ecf20Sopenharmony_ci	u32 edca_be_ul = 0x5ea42b;
6008c2ecf20Sopenharmony_ci	u32 edca_be_dl = 0x5ea42b;
6018c2ecf20Sopenharmony_ci
6028c2ecf20Sopenharmony_ci	if (mac->link_state != MAC80211_LINKED) {
6038c2ecf20Sopenharmony_ci		rtlpriv->dm.current_turbo_edca = false;
6048c2ecf20Sopenharmony_ci		goto exit;
6058c2ecf20Sopenharmony_ci	}
6068c2ecf20Sopenharmony_ci
6078c2ecf20Sopenharmony_ci	/* Enable BEQ TxOP limit configuration in wireless G-mode. */
6088c2ecf20Sopenharmony_ci	/* To check whether we shall force turn on TXOP configuration. */
6098c2ecf20Sopenharmony_ci	if ((!rtlpriv->dm.disable_framebursting) &&
6108c2ecf20Sopenharmony_ci	    (rtlpriv->sec.pairwise_enc_algorithm == WEP40_ENCRYPTION ||
6118c2ecf20Sopenharmony_ci	    rtlpriv->sec.pairwise_enc_algorithm == WEP104_ENCRYPTION ||
6128c2ecf20Sopenharmony_ci	    rtlpriv->sec.pairwise_enc_algorithm == TKIP_ENCRYPTION)) {
6138c2ecf20Sopenharmony_ci		/* Force TxOP limit to 0x005e for UL. */
6148c2ecf20Sopenharmony_ci		if (!(edca_be_ul & 0xffff0000))
6158c2ecf20Sopenharmony_ci			edca_be_ul |= 0x005e0000;
6168c2ecf20Sopenharmony_ci		/* Force TxOP limit to 0x005e for DL. */
6178c2ecf20Sopenharmony_ci		if (!(edca_be_dl & 0xffff0000))
6188c2ecf20Sopenharmony_ci			edca_be_dl |= 0x005e0000;
6198c2ecf20Sopenharmony_ci	}
6208c2ecf20Sopenharmony_ci
6218c2ecf20Sopenharmony_ci	if ((!rtlpriv->dm.is_any_nonbepkts) &&
6228c2ecf20Sopenharmony_ci	    (!rtlpriv->dm.disable_framebursting)) {
6238c2ecf20Sopenharmony_ci		cur_txok_cnt = rtlpriv->stats.txbytesunicast - last_txok_cnt;
6248c2ecf20Sopenharmony_ci		cur_rxok_cnt = rtlpriv->stats.rxbytesunicast - last_rxok_cnt;
6258c2ecf20Sopenharmony_ci		if (cur_rxok_cnt > 4 * cur_txok_cnt) {
6268c2ecf20Sopenharmony_ci			if (!rtlpriv->dm.is_cur_rdlstate ||
6278c2ecf20Sopenharmony_ci			    !rtlpriv->dm.current_turbo_edca) {
6288c2ecf20Sopenharmony_ci				rtl_write_dword(rtlpriv, REG_EDCA_BE_PARAM,
6298c2ecf20Sopenharmony_ci						edca_be_dl);
6308c2ecf20Sopenharmony_ci				rtlpriv->dm.is_cur_rdlstate = true;
6318c2ecf20Sopenharmony_ci			}
6328c2ecf20Sopenharmony_ci		} else {
6338c2ecf20Sopenharmony_ci			if (rtlpriv->dm.is_cur_rdlstate ||
6348c2ecf20Sopenharmony_ci			    !rtlpriv->dm.current_turbo_edca) {
6358c2ecf20Sopenharmony_ci				rtl_write_dword(rtlpriv, REG_EDCA_BE_PARAM,
6368c2ecf20Sopenharmony_ci						edca_be_ul);
6378c2ecf20Sopenharmony_ci				rtlpriv->dm.is_cur_rdlstate = false;
6388c2ecf20Sopenharmony_ci			}
6398c2ecf20Sopenharmony_ci		}
6408c2ecf20Sopenharmony_ci		rtlpriv->dm.current_turbo_edca = true;
6418c2ecf20Sopenharmony_ci	} else {
6428c2ecf20Sopenharmony_ci		if (rtlpriv->dm.current_turbo_edca) {
6438c2ecf20Sopenharmony_ci			u8 tmp = AC0_BE;
6448c2ecf20Sopenharmony_ci			rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_AC_PARAM,
6458c2ecf20Sopenharmony_ci						      &tmp);
6468c2ecf20Sopenharmony_ci			rtlpriv->dm.current_turbo_edca = false;
6478c2ecf20Sopenharmony_ci		}
6488c2ecf20Sopenharmony_ci	}
6498c2ecf20Sopenharmony_ci
6508c2ecf20Sopenharmony_ciexit:
6518c2ecf20Sopenharmony_ci	rtlpriv->dm.is_any_nonbepkts = false;
6528c2ecf20Sopenharmony_ci	last_txok_cnt = rtlpriv->stats.txbytesunicast;
6538c2ecf20Sopenharmony_ci	last_rxok_cnt = rtlpriv->stats.rxbytesunicast;
6548c2ecf20Sopenharmony_ci}
6558c2ecf20Sopenharmony_ci
6568c2ecf20Sopenharmony_cistatic void rtl92d_dm_rxgain_tracking_thermalmeter(struct ieee80211_hw *hw)
6578c2ecf20Sopenharmony_ci{
6588c2ecf20Sopenharmony_ci	struct rtl_priv *rtlpriv = rtl_priv(hw);
6598c2ecf20Sopenharmony_ci	u8 index_mapping[RX_INDEX_MAPPING_NUM] = {
6608c2ecf20Sopenharmony_ci		0x0f, 0x0f, 0x0d, 0x0c, 0x0b,
6618c2ecf20Sopenharmony_ci		0x0a, 0x09, 0x08, 0x07, 0x06,
6628c2ecf20Sopenharmony_ci		0x05, 0x04, 0x04, 0x03, 0x02
6638c2ecf20Sopenharmony_ci	};
6648c2ecf20Sopenharmony_ci	int i;
6658c2ecf20Sopenharmony_ci	u32 u4tmp;
6668c2ecf20Sopenharmony_ci
6678c2ecf20Sopenharmony_ci	u4tmp = (index_mapping[(rtlpriv->efuse.eeprom_thermalmeter -
6688c2ecf20Sopenharmony_ci				rtlpriv->dm.thermalvalue_rxgain)]) << 12;
6698c2ecf20Sopenharmony_ci	rtl_dbg(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
6708c2ecf20Sopenharmony_ci		"===> Rx Gain %x\n", u4tmp);
6718c2ecf20Sopenharmony_ci	for (i = RF90_PATH_A; i < rtlpriv->phy.num_total_rfpath; i++)
6728c2ecf20Sopenharmony_ci		rtl_set_rfreg(hw, i, 0x3C, RFREG_OFFSET_MASK,
6738c2ecf20Sopenharmony_ci			      (rtlpriv->phy.reg_rf3c[i] & (~(0xF000))) | u4tmp);
6748c2ecf20Sopenharmony_ci}
6758c2ecf20Sopenharmony_ci
6768c2ecf20Sopenharmony_cistatic void rtl92d_bandtype_2_4G(struct ieee80211_hw *hw, long *temp_cckg,
6778c2ecf20Sopenharmony_ci				 u8 *cck_index_old)
6788c2ecf20Sopenharmony_ci{
6798c2ecf20Sopenharmony_ci	struct rtl_priv *rtlpriv = rtl_priv(hw);
6808c2ecf20Sopenharmony_ci	int i;
6818c2ecf20Sopenharmony_ci	unsigned long flag = 0;
6828c2ecf20Sopenharmony_ci	long temp_cck;
6838c2ecf20Sopenharmony_ci	const u8 *cckswing;
6848c2ecf20Sopenharmony_ci
6858c2ecf20Sopenharmony_ci	/* Query CCK default setting From 0xa24 */
6868c2ecf20Sopenharmony_ci	rtl92d_acquire_cckandrw_pagea_ctl(hw, &flag);
6878c2ecf20Sopenharmony_ci	temp_cck = rtl_get_bbreg(hw, RCCK0_TXFILTER2,
6888c2ecf20Sopenharmony_ci				 MASKDWORD) & MASKCCK;
6898c2ecf20Sopenharmony_ci	rtl92d_release_cckandrw_pagea_ctl(hw, &flag);
6908c2ecf20Sopenharmony_ci	for (i = 0; i < CCK_TABLE_LENGTH; i++) {
6918c2ecf20Sopenharmony_ci		if (rtlpriv->dm.cck_inch14)
6928c2ecf20Sopenharmony_ci			cckswing = &cckswing_table_ch14[i][2];
6938c2ecf20Sopenharmony_ci		else
6948c2ecf20Sopenharmony_ci			cckswing = &cckswing_table_ch1ch13[i][2];
6958c2ecf20Sopenharmony_ci
6968c2ecf20Sopenharmony_ci		if (temp_cck == le32_to_cpu(*((__le32 *)cckswing))) {
6978c2ecf20Sopenharmony_ci			*cck_index_old = (u8)i;
6988c2ecf20Sopenharmony_ci			rtl_dbg(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
6998c2ecf20Sopenharmony_ci				"Initial reg0x%x = 0x%lx, cck_index = 0x%x, ch14 %d\n",
7008c2ecf20Sopenharmony_ci				RCCK0_TXFILTER2, temp_cck,
7018c2ecf20Sopenharmony_ci				*cck_index_old,
7028c2ecf20Sopenharmony_ci				rtlpriv->dm.cck_inch14);
7038c2ecf20Sopenharmony_ci			break;
7048c2ecf20Sopenharmony_ci		}
7058c2ecf20Sopenharmony_ci	}
7068c2ecf20Sopenharmony_ci	*temp_cckg = temp_cck;
7078c2ecf20Sopenharmony_ci}
7088c2ecf20Sopenharmony_ci
7098c2ecf20Sopenharmony_cistatic void rtl92d_bandtype_5G(struct rtl_hal *rtlhal, u8 *ofdm_index,
7108c2ecf20Sopenharmony_ci			       bool *internal_pa, u8 thermalvalue, u8 delta,
7118c2ecf20Sopenharmony_ci			       u8 rf, struct rtl_efuse *rtlefuse,
7128c2ecf20Sopenharmony_ci			       struct rtl_priv *rtlpriv, struct rtl_phy *rtlphy,
7138c2ecf20Sopenharmony_ci			       const u8 index_mapping[5][INDEX_MAPPING_NUM],
7148c2ecf20Sopenharmony_ci			       const u8 index_mapping_pa[8][INDEX_MAPPING_NUM])
7158c2ecf20Sopenharmony_ci{
7168c2ecf20Sopenharmony_ci	int i;
7178c2ecf20Sopenharmony_ci	u8 index;
7188c2ecf20Sopenharmony_ci	u8 offset = 0;
7198c2ecf20Sopenharmony_ci
7208c2ecf20Sopenharmony_ci	for (i = 0; i < rf; i++) {
7218c2ecf20Sopenharmony_ci		if (rtlhal->macphymode == DUALMAC_DUALPHY &&
7228c2ecf20Sopenharmony_ci		    rtlhal->interfaceindex == 1)	/* MAC 1 5G */
7238c2ecf20Sopenharmony_ci			*internal_pa = rtlefuse->internal_pa_5g[1];
7248c2ecf20Sopenharmony_ci		else
7258c2ecf20Sopenharmony_ci			*internal_pa = rtlefuse->internal_pa_5g[i];
7268c2ecf20Sopenharmony_ci		if (*internal_pa) {
7278c2ecf20Sopenharmony_ci			if (rtlhal->interfaceindex == 1 || i == rf)
7288c2ecf20Sopenharmony_ci				offset = 4;
7298c2ecf20Sopenharmony_ci			else
7308c2ecf20Sopenharmony_ci				offset = 0;
7318c2ecf20Sopenharmony_ci			if (rtlphy->current_channel >= 100 &&
7328c2ecf20Sopenharmony_ci				rtlphy->current_channel <= 165)
7338c2ecf20Sopenharmony_ci				offset += 2;
7348c2ecf20Sopenharmony_ci		} else {
7358c2ecf20Sopenharmony_ci			if (rtlhal->interfaceindex == 1 || i == rf)
7368c2ecf20Sopenharmony_ci				offset = 2;
7378c2ecf20Sopenharmony_ci			else
7388c2ecf20Sopenharmony_ci				offset = 0;
7398c2ecf20Sopenharmony_ci		}
7408c2ecf20Sopenharmony_ci		if (thermalvalue > rtlefuse->eeprom_thermalmeter)
7418c2ecf20Sopenharmony_ci			offset++;
7428c2ecf20Sopenharmony_ci		if (*internal_pa) {
7438c2ecf20Sopenharmony_ci			if (delta > INDEX_MAPPING_NUM - 1)
7448c2ecf20Sopenharmony_ci				index = index_mapping_pa[offset]
7458c2ecf20Sopenharmony_ci						    [INDEX_MAPPING_NUM - 1];
7468c2ecf20Sopenharmony_ci			else
7478c2ecf20Sopenharmony_ci				index =
7488c2ecf20Sopenharmony_ci				     index_mapping_pa[offset][delta];
7498c2ecf20Sopenharmony_ci		} else {
7508c2ecf20Sopenharmony_ci			if (delta > INDEX_MAPPING_NUM - 1)
7518c2ecf20Sopenharmony_ci				index =
7528c2ecf20Sopenharmony_ci				   index_mapping[offset][INDEX_MAPPING_NUM - 1];
7538c2ecf20Sopenharmony_ci			else
7548c2ecf20Sopenharmony_ci				index = index_mapping[offset][delta];
7558c2ecf20Sopenharmony_ci		}
7568c2ecf20Sopenharmony_ci		if (thermalvalue > rtlefuse->eeprom_thermalmeter) {
7578c2ecf20Sopenharmony_ci			if (*internal_pa && thermalvalue > 0x12) {
7588c2ecf20Sopenharmony_ci				ofdm_index[i] = rtlpriv->dm.ofdm_index[i] -
7598c2ecf20Sopenharmony_ci						((delta / 2) * 3 + (delta % 2));
7608c2ecf20Sopenharmony_ci			} else {
7618c2ecf20Sopenharmony_ci				ofdm_index[i] -= index;
7628c2ecf20Sopenharmony_ci			}
7638c2ecf20Sopenharmony_ci		} else {
7648c2ecf20Sopenharmony_ci			ofdm_index[i] += index;
7658c2ecf20Sopenharmony_ci		}
7668c2ecf20Sopenharmony_ci	}
7678c2ecf20Sopenharmony_ci}
7688c2ecf20Sopenharmony_ci
7698c2ecf20Sopenharmony_cistatic void rtl92d_dm_txpower_tracking_callback_thermalmeter(
7708c2ecf20Sopenharmony_ci			struct ieee80211_hw *hw)
7718c2ecf20Sopenharmony_ci{
7728c2ecf20Sopenharmony_ci	struct rtl_priv *rtlpriv = rtl_priv(hw);
7738c2ecf20Sopenharmony_ci	struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
7748c2ecf20Sopenharmony_ci	struct rtl_phy *rtlphy = &(rtlpriv->phy);
7758c2ecf20Sopenharmony_ci	struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
7768c2ecf20Sopenharmony_ci	u8 thermalvalue, delta, delta_lck, delta_iqk, delta_rxgain;
7778c2ecf20Sopenharmony_ci	u8 offset, thermalvalue_avg_count = 0;
7788c2ecf20Sopenharmony_ci	u32 thermalvalue_avg = 0;
7798c2ecf20Sopenharmony_ci	bool internal_pa = false;
7808c2ecf20Sopenharmony_ci	long ele_a = 0, ele_d, temp_cck, val_x, value32;
7818c2ecf20Sopenharmony_ci	long val_y, ele_c = 0;
7828c2ecf20Sopenharmony_ci	u8 ofdm_index[2];
7838c2ecf20Sopenharmony_ci	s8 cck_index = 0;
7848c2ecf20Sopenharmony_ci	u8 ofdm_index_old[2] = {0, 0};
7858c2ecf20Sopenharmony_ci	s8 cck_index_old = 0;
7868c2ecf20Sopenharmony_ci	u8 index;
7878c2ecf20Sopenharmony_ci	int i;
7888c2ecf20Sopenharmony_ci	bool is2t = IS_92D_SINGLEPHY(rtlhal->version);
7898c2ecf20Sopenharmony_ci	u8 ofdm_min_index = 6, ofdm_min_index_internal_pa = 3, rf;
7908c2ecf20Sopenharmony_ci	u8 indexforchannel =
7918c2ecf20Sopenharmony_ci	    rtl92d_get_rightchnlplace_for_iqk(rtlphy->current_channel);
7928c2ecf20Sopenharmony_ci	static const u8 index_mapping[5][INDEX_MAPPING_NUM] = {
7938c2ecf20Sopenharmony_ci		/* 5G, path A/MAC 0, decrease power  */
7948c2ecf20Sopenharmony_ci		{0, 1, 3, 6, 8, 9,	11, 13, 14, 16, 17, 18, 18},
7958c2ecf20Sopenharmony_ci		/* 5G, path A/MAC 0, increase power  */
7968c2ecf20Sopenharmony_ci		{0, 2, 4, 5, 7, 10,	12, 14, 16, 18, 18, 18, 18},
7978c2ecf20Sopenharmony_ci		/* 5G, path B/MAC 1, decrease power */
7988c2ecf20Sopenharmony_ci		{0, 2, 3, 6, 8, 9,	11, 13, 14, 16, 17, 18, 18},
7998c2ecf20Sopenharmony_ci		/* 5G, path B/MAC 1, increase power */
8008c2ecf20Sopenharmony_ci		{0, 2, 4, 5, 7, 10,	13, 16, 16, 18, 18, 18, 18},
8018c2ecf20Sopenharmony_ci		/* 2.4G, for decreas power */
8028c2ecf20Sopenharmony_ci		{0, 1, 2, 3, 4, 5,	6, 7, 7, 8, 9, 10, 10},
8038c2ecf20Sopenharmony_ci	};
8048c2ecf20Sopenharmony_ci	static const u8 index_mapping_internal_pa[8][INDEX_MAPPING_NUM] = {
8058c2ecf20Sopenharmony_ci		/* 5G, path A/MAC 0, ch36-64, decrease power  */
8068c2ecf20Sopenharmony_ci		{0, 1, 2, 4, 6, 7,	9, 11, 12, 14, 15, 16, 16},
8078c2ecf20Sopenharmony_ci		/* 5G, path A/MAC 0, ch36-64, increase power  */
8088c2ecf20Sopenharmony_ci		{0, 2, 4, 5, 7, 10,	12, 14, 16, 18, 18, 18, 18},
8098c2ecf20Sopenharmony_ci		/* 5G, path A/MAC 0, ch100-165, decrease power  */
8108c2ecf20Sopenharmony_ci		{0, 1, 2, 3, 5, 6,	8, 10, 11, 13, 14, 15, 15},
8118c2ecf20Sopenharmony_ci		/* 5G, path A/MAC 0, ch100-165, increase power  */
8128c2ecf20Sopenharmony_ci		{0, 2, 4, 5, 7, 10,	12, 14, 16, 18, 18, 18, 18},
8138c2ecf20Sopenharmony_ci		/* 5G, path B/MAC 1, ch36-64, decrease power */
8148c2ecf20Sopenharmony_ci		{0, 1, 2, 4, 6, 7,	9, 11, 12, 14, 15, 16, 16},
8158c2ecf20Sopenharmony_ci		/* 5G, path B/MAC 1, ch36-64, increase power */
8168c2ecf20Sopenharmony_ci		{0, 2, 4, 5, 7, 10,	13, 16, 16, 18, 18, 18, 18},
8178c2ecf20Sopenharmony_ci		/* 5G, path B/MAC 1, ch100-165, decrease power */
8188c2ecf20Sopenharmony_ci		{0, 1, 2, 3, 5, 6,	8, 9, 10, 12, 13, 14, 14},
8198c2ecf20Sopenharmony_ci		/* 5G, path B/MAC 1, ch100-165, increase power */
8208c2ecf20Sopenharmony_ci		{0, 2, 4, 5, 7, 10,	13, 16, 16, 18, 18, 18, 18},
8218c2ecf20Sopenharmony_ci	};
8228c2ecf20Sopenharmony_ci
8238c2ecf20Sopenharmony_ci	rtlpriv->dm.txpower_trackinginit = true;
8248c2ecf20Sopenharmony_ci	rtl_dbg(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD, "\n");
8258c2ecf20Sopenharmony_ci	thermalvalue = (u8) rtl_get_rfreg(hw, RF90_PATH_A, RF_T_METER, 0xf800);
8268c2ecf20Sopenharmony_ci	rtl_dbg(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
8278c2ecf20Sopenharmony_ci		"Readback Thermal Meter = 0x%x pre thermal meter 0x%x eeprom_thermalmeter 0x%x\n",
8288c2ecf20Sopenharmony_ci		thermalvalue,
8298c2ecf20Sopenharmony_ci		rtlpriv->dm.thermalvalue, rtlefuse->eeprom_thermalmeter);
8308c2ecf20Sopenharmony_ci	rtl92d_phy_ap_calibrate(hw, (thermalvalue -
8318c2ecf20Sopenharmony_ci				     rtlefuse->eeprom_thermalmeter));
8328c2ecf20Sopenharmony_ci
8338c2ecf20Sopenharmony_ci	if (!thermalvalue)
8348c2ecf20Sopenharmony_ci		goto exit;
8358c2ecf20Sopenharmony_ci
8368c2ecf20Sopenharmony_ci	if (is2t)
8378c2ecf20Sopenharmony_ci		rf = 2;
8388c2ecf20Sopenharmony_ci	else
8398c2ecf20Sopenharmony_ci		rf = 1;
8408c2ecf20Sopenharmony_ci
8418c2ecf20Sopenharmony_ci	if (rtlpriv->dm.thermalvalue && !rtlhal->reloadtxpowerindex)
8428c2ecf20Sopenharmony_ci		goto old_index_done;
8438c2ecf20Sopenharmony_ci
8448c2ecf20Sopenharmony_ci	ele_d = rtl_get_bbreg(hw, ROFDM0_XATXIQIMBALANCE,  MASKDWORD) & MASKOFDM_D;
8458c2ecf20Sopenharmony_ci	for (i = 0; i < OFDM_TABLE_SIZE_92D; i++) {
8468c2ecf20Sopenharmony_ci		if (ele_d == (ofdmswing_table[i] & MASKOFDM_D)) {
8478c2ecf20Sopenharmony_ci			ofdm_index_old[0] = (u8)i;
8488c2ecf20Sopenharmony_ci
8498c2ecf20Sopenharmony_ci			rtl_dbg(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
8508c2ecf20Sopenharmony_ci				"Initial pathA ele_d reg0x%x = 0x%lx, ofdm_index=0x%x\n",
8518c2ecf20Sopenharmony_ci				ROFDM0_XATXIQIMBALANCE,
8528c2ecf20Sopenharmony_ci				ele_d, ofdm_index_old[0]);
8538c2ecf20Sopenharmony_ci			break;
8548c2ecf20Sopenharmony_ci		}
8558c2ecf20Sopenharmony_ci	}
8568c2ecf20Sopenharmony_ci	if (is2t) {
8578c2ecf20Sopenharmony_ci		ele_d = rtl_get_bbreg(hw, ROFDM0_XBTXIQIMBALANCE,
8588c2ecf20Sopenharmony_ci				      MASKDWORD) & MASKOFDM_D;
8598c2ecf20Sopenharmony_ci		for (i = 0; i < OFDM_TABLE_SIZE_92D; i++) {
8608c2ecf20Sopenharmony_ci			if (ele_d ==
8618c2ecf20Sopenharmony_ci			    (ofdmswing_table[i] & MASKOFDM_D)) {
8628c2ecf20Sopenharmony_ci				ofdm_index_old[1] = (u8)i;
8638c2ecf20Sopenharmony_ci				rtl_dbg(rtlpriv, COMP_POWER_TRACKING,
8648c2ecf20Sopenharmony_ci					DBG_LOUD,
8658c2ecf20Sopenharmony_ci					"Initial pathB ele_d reg 0x%x = 0x%lx, ofdm_index = 0x%x\n",
8668c2ecf20Sopenharmony_ci					ROFDM0_XBTXIQIMBALANCE, ele_d,
8678c2ecf20Sopenharmony_ci					ofdm_index_old[1]);
8688c2ecf20Sopenharmony_ci				break;
8698c2ecf20Sopenharmony_ci			}
8708c2ecf20Sopenharmony_ci		}
8718c2ecf20Sopenharmony_ci	}
8728c2ecf20Sopenharmony_ci	if (rtlhal->current_bandtype == BAND_ON_2_4G) {
8738c2ecf20Sopenharmony_ci		rtl92d_bandtype_2_4G(hw, &temp_cck, &cck_index_old);
8748c2ecf20Sopenharmony_ci	} else {
8758c2ecf20Sopenharmony_ci		temp_cck = 0x090e1317;
8768c2ecf20Sopenharmony_ci		cck_index_old = 12;
8778c2ecf20Sopenharmony_ci	}
8788c2ecf20Sopenharmony_ci
8798c2ecf20Sopenharmony_ci	if (!rtlpriv->dm.thermalvalue) {
8808c2ecf20Sopenharmony_ci		rtlpriv->dm.thermalvalue = rtlefuse->eeprom_thermalmeter;
8818c2ecf20Sopenharmony_ci		rtlpriv->dm.thermalvalue_lck = thermalvalue;
8828c2ecf20Sopenharmony_ci		rtlpriv->dm.thermalvalue_iqk = thermalvalue;
8838c2ecf20Sopenharmony_ci		rtlpriv->dm.thermalvalue_rxgain = rtlefuse->eeprom_thermalmeter;
8848c2ecf20Sopenharmony_ci		for (i = 0; i < rf; i++)
8858c2ecf20Sopenharmony_ci			rtlpriv->dm.ofdm_index[i] = ofdm_index_old[i];
8868c2ecf20Sopenharmony_ci		rtlpriv->dm.cck_index = cck_index_old;
8878c2ecf20Sopenharmony_ci	}
8888c2ecf20Sopenharmony_ci	if (rtlhal->reloadtxpowerindex) {
8898c2ecf20Sopenharmony_ci		for (i = 0; i < rf; i++)
8908c2ecf20Sopenharmony_ci			rtlpriv->dm.ofdm_index[i] = ofdm_index_old[i];
8918c2ecf20Sopenharmony_ci		rtlpriv->dm.cck_index = cck_index_old;
8928c2ecf20Sopenharmony_ci		rtl_dbg(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
8938c2ecf20Sopenharmony_ci			"reload ofdm index for band switch\n");
8948c2ecf20Sopenharmony_ci	}
8958c2ecf20Sopenharmony_ciold_index_done:
8968c2ecf20Sopenharmony_ci	for (i = 0; i < rf; i++)
8978c2ecf20Sopenharmony_ci		ofdm_index[i] = rtlpriv->dm.ofdm_index[i];
8988c2ecf20Sopenharmony_ci
8998c2ecf20Sopenharmony_ci	rtlpriv->dm.thermalvalue_avg
9008c2ecf20Sopenharmony_ci		    [rtlpriv->dm.thermalvalue_avg_index] = thermalvalue;
9018c2ecf20Sopenharmony_ci	rtlpriv->dm.thermalvalue_avg_index++;
9028c2ecf20Sopenharmony_ci	if (rtlpriv->dm.thermalvalue_avg_index == AVG_THERMAL_NUM)
9038c2ecf20Sopenharmony_ci		rtlpriv->dm.thermalvalue_avg_index = 0;
9048c2ecf20Sopenharmony_ci	for (i = 0; i < AVG_THERMAL_NUM; i++) {
9058c2ecf20Sopenharmony_ci		if (rtlpriv->dm.thermalvalue_avg[i]) {
9068c2ecf20Sopenharmony_ci			thermalvalue_avg += rtlpriv->dm.thermalvalue_avg[i];
9078c2ecf20Sopenharmony_ci			thermalvalue_avg_count++;
9088c2ecf20Sopenharmony_ci		}
9098c2ecf20Sopenharmony_ci	}
9108c2ecf20Sopenharmony_ci	if (thermalvalue_avg_count)
9118c2ecf20Sopenharmony_ci		thermalvalue = (u8)(thermalvalue_avg / thermalvalue_avg_count);
9128c2ecf20Sopenharmony_ci	if (rtlhal->reloadtxpowerindex) {
9138c2ecf20Sopenharmony_ci		delta = (thermalvalue > rtlefuse->eeprom_thermalmeter) ?
9148c2ecf20Sopenharmony_ci		    (thermalvalue - rtlefuse->eeprom_thermalmeter) :
9158c2ecf20Sopenharmony_ci		    (rtlefuse->eeprom_thermalmeter - thermalvalue);
9168c2ecf20Sopenharmony_ci		rtlhal->reloadtxpowerindex = false;
9178c2ecf20Sopenharmony_ci		rtlpriv->dm.done_txpower = false;
9188c2ecf20Sopenharmony_ci	} else if (rtlpriv->dm.done_txpower) {
9198c2ecf20Sopenharmony_ci		delta = (thermalvalue > rtlpriv->dm.thermalvalue) ?
9208c2ecf20Sopenharmony_ci		    (thermalvalue - rtlpriv->dm.thermalvalue) :
9218c2ecf20Sopenharmony_ci		    (rtlpriv->dm.thermalvalue - thermalvalue);
9228c2ecf20Sopenharmony_ci	} else {
9238c2ecf20Sopenharmony_ci		delta = (thermalvalue > rtlefuse->eeprom_thermalmeter) ?
9248c2ecf20Sopenharmony_ci		    (thermalvalue - rtlefuse->eeprom_thermalmeter) :
9258c2ecf20Sopenharmony_ci		    (rtlefuse->eeprom_thermalmeter - thermalvalue);
9268c2ecf20Sopenharmony_ci	}
9278c2ecf20Sopenharmony_ci	delta_lck = (thermalvalue > rtlpriv->dm.thermalvalue_lck) ?
9288c2ecf20Sopenharmony_ci	    (thermalvalue - rtlpriv->dm.thermalvalue_lck) :
9298c2ecf20Sopenharmony_ci	    (rtlpriv->dm.thermalvalue_lck - thermalvalue);
9308c2ecf20Sopenharmony_ci	delta_iqk = (thermalvalue > rtlpriv->dm.thermalvalue_iqk) ?
9318c2ecf20Sopenharmony_ci	    (thermalvalue - rtlpriv->dm.thermalvalue_iqk) :
9328c2ecf20Sopenharmony_ci	    (rtlpriv->dm.thermalvalue_iqk - thermalvalue);
9338c2ecf20Sopenharmony_ci	delta_rxgain =
9348c2ecf20Sopenharmony_ci		(thermalvalue > rtlpriv->dm.thermalvalue_rxgain) ?
9358c2ecf20Sopenharmony_ci		(thermalvalue - rtlpriv->dm.thermalvalue_rxgain) :
9368c2ecf20Sopenharmony_ci		(rtlpriv->dm.thermalvalue_rxgain - thermalvalue);
9378c2ecf20Sopenharmony_ci	rtl_dbg(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
9388c2ecf20Sopenharmony_ci		"Readback Thermal Meter = 0x%x pre thermal meter 0x%x eeprom_thermalmeter 0x%x delta 0x%x delta_lck 0x%x delta_iqk 0x%x\n",
9398c2ecf20Sopenharmony_ci		thermalvalue, rtlpriv->dm.thermalvalue,
9408c2ecf20Sopenharmony_ci		rtlefuse->eeprom_thermalmeter, delta, delta_lck,
9418c2ecf20Sopenharmony_ci		delta_iqk);
9428c2ecf20Sopenharmony_ci	if (delta_lck > rtlefuse->delta_lck && rtlefuse->delta_lck != 0) {
9438c2ecf20Sopenharmony_ci		rtlpriv->dm.thermalvalue_lck = thermalvalue;
9448c2ecf20Sopenharmony_ci		rtl92d_phy_lc_calibrate(hw);
9458c2ecf20Sopenharmony_ci	}
9468c2ecf20Sopenharmony_ci
9478c2ecf20Sopenharmony_ci	if (delta == 0 || !rtlpriv->dm.txpower_track_control)
9488c2ecf20Sopenharmony_ci		goto check_delta;
9498c2ecf20Sopenharmony_ci
9508c2ecf20Sopenharmony_ci	rtlpriv->dm.done_txpower = true;
9518c2ecf20Sopenharmony_ci	delta = (thermalvalue > rtlefuse->eeprom_thermalmeter) ?
9528c2ecf20Sopenharmony_ci	    (thermalvalue - rtlefuse->eeprom_thermalmeter) :
9538c2ecf20Sopenharmony_ci	    (rtlefuse->eeprom_thermalmeter - thermalvalue);
9548c2ecf20Sopenharmony_ci	if (rtlhal->current_bandtype == BAND_ON_2_4G) {
9558c2ecf20Sopenharmony_ci		offset = 4;
9568c2ecf20Sopenharmony_ci		if (delta > INDEX_MAPPING_NUM - 1)
9578c2ecf20Sopenharmony_ci			index = index_mapping[offset][INDEX_MAPPING_NUM - 1];
9588c2ecf20Sopenharmony_ci		else
9598c2ecf20Sopenharmony_ci			index = index_mapping[offset][delta];
9608c2ecf20Sopenharmony_ci		if (thermalvalue > rtlpriv->dm.thermalvalue) {
9618c2ecf20Sopenharmony_ci			for (i = 0; i < rf; i++)
9628c2ecf20Sopenharmony_ci				ofdm_index[i] -= delta;
9638c2ecf20Sopenharmony_ci			cck_index -= delta;
9648c2ecf20Sopenharmony_ci		} else {
9658c2ecf20Sopenharmony_ci			for (i = 0; i < rf; i++)
9668c2ecf20Sopenharmony_ci				ofdm_index[i] += index;
9678c2ecf20Sopenharmony_ci			cck_index += index;
9688c2ecf20Sopenharmony_ci		}
9698c2ecf20Sopenharmony_ci	} else if (rtlhal->current_bandtype == BAND_ON_5G) {
9708c2ecf20Sopenharmony_ci		rtl92d_bandtype_5G(rtlhal, ofdm_index,
9718c2ecf20Sopenharmony_ci				   &internal_pa, thermalvalue,
9728c2ecf20Sopenharmony_ci				   delta, rf, rtlefuse, rtlpriv,
9738c2ecf20Sopenharmony_ci				   rtlphy, index_mapping,
9748c2ecf20Sopenharmony_ci				   index_mapping_internal_pa);
9758c2ecf20Sopenharmony_ci	}
9768c2ecf20Sopenharmony_ci	if (is2t) {
9778c2ecf20Sopenharmony_ci		rtl_dbg(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
9788c2ecf20Sopenharmony_ci			"temp OFDM_A_index=0x%x, OFDM_B_index = 0x%x,cck_index=0x%x\n",
9798c2ecf20Sopenharmony_ci			rtlpriv->dm.ofdm_index[0],
9808c2ecf20Sopenharmony_ci			rtlpriv->dm.ofdm_index[1],
9818c2ecf20Sopenharmony_ci			rtlpriv->dm.cck_index);
9828c2ecf20Sopenharmony_ci	} else {
9838c2ecf20Sopenharmony_ci		rtl_dbg(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
9848c2ecf20Sopenharmony_ci			"temp OFDM_A_index=0x%x,cck_index = 0x%x\n",
9858c2ecf20Sopenharmony_ci			rtlpriv->dm.ofdm_index[0],
9868c2ecf20Sopenharmony_ci			rtlpriv->dm.cck_index);
9878c2ecf20Sopenharmony_ci	}
9888c2ecf20Sopenharmony_ci	for (i = 0; i < rf; i++) {
9898c2ecf20Sopenharmony_ci		if (ofdm_index[i] > OFDM_TABLE_SIZE_92D - 1)
9908c2ecf20Sopenharmony_ci			ofdm_index[i] = OFDM_TABLE_SIZE_92D - 1;
9918c2ecf20Sopenharmony_ci		else if (ofdm_index[i] < ofdm_min_index)
9928c2ecf20Sopenharmony_ci			ofdm_index[i] = ofdm_min_index;
9938c2ecf20Sopenharmony_ci	}
9948c2ecf20Sopenharmony_ci	if (rtlhal->current_bandtype == BAND_ON_2_4G) {
9958c2ecf20Sopenharmony_ci		if (cck_index > CCK_TABLE_SIZE - 1) {
9968c2ecf20Sopenharmony_ci			cck_index = CCK_TABLE_SIZE - 1;
9978c2ecf20Sopenharmony_ci		} else if (internal_pa ||
9988c2ecf20Sopenharmony_ci			   rtlhal->current_bandtype == BAND_ON_2_4G) {
9998c2ecf20Sopenharmony_ci			if (ofdm_index[i] < ofdm_min_index_internal_pa)
10008c2ecf20Sopenharmony_ci				ofdm_index[i] = ofdm_min_index_internal_pa;
10018c2ecf20Sopenharmony_ci		} else if (cck_index < 0) {
10028c2ecf20Sopenharmony_ci			cck_index = 0;
10038c2ecf20Sopenharmony_ci		}
10048c2ecf20Sopenharmony_ci	}
10058c2ecf20Sopenharmony_ci	if (is2t) {
10068c2ecf20Sopenharmony_ci		rtl_dbg(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
10078c2ecf20Sopenharmony_ci			"new OFDM_A_index=0x%x, OFDM_B_index = 0x%x, cck_index=0x%x\n",
10088c2ecf20Sopenharmony_ci			ofdm_index[0], ofdm_index[1],
10098c2ecf20Sopenharmony_ci			cck_index);
10108c2ecf20Sopenharmony_ci	} else {
10118c2ecf20Sopenharmony_ci		rtl_dbg(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
10128c2ecf20Sopenharmony_ci			"new OFDM_A_index=0x%x,cck_index = 0x%x\n",
10138c2ecf20Sopenharmony_ci			ofdm_index[0], cck_index);
10148c2ecf20Sopenharmony_ci	}
10158c2ecf20Sopenharmony_ci	ele_d = (ofdmswing_table[ofdm_index[0]] & 0xFFC00000) >> 22;
10168c2ecf20Sopenharmony_ci	val_x = rtlphy->iqk_matrix[indexforchannel].value[0][0];
10178c2ecf20Sopenharmony_ci	val_y = rtlphy->iqk_matrix[indexforchannel].value[0][1];
10188c2ecf20Sopenharmony_ci	if (val_x != 0) {
10198c2ecf20Sopenharmony_ci		if ((val_x & 0x00000200) != 0)
10208c2ecf20Sopenharmony_ci			val_x = val_x | 0xFFFFFC00;
10218c2ecf20Sopenharmony_ci		ele_a = ((val_x * ele_d) >> 8) & 0x000003FF;
10228c2ecf20Sopenharmony_ci
10238c2ecf20Sopenharmony_ci		/* new element C = element D x Y */
10248c2ecf20Sopenharmony_ci		if ((val_y & 0x00000200) != 0)
10258c2ecf20Sopenharmony_ci			val_y = val_y | 0xFFFFFC00;
10268c2ecf20Sopenharmony_ci		ele_c = ((val_y * ele_d) >> 8) & 0x000003FF;
10278c2ecf20Sopenharmony_ci
10288c2ecf20Sopenharmony_ci		/* write new elements A, C, D to regC80 and
10298c2ecf20Sopenharmony_ci		 * regC94, element B is always 0
10308c2ecf20Sopenharmony_ci		 */
10318c2ecf20Sopenharmony_ci		value32 = (ele_d << 22) | ((ele_c & 0x3F) << 16) | ele_a;
10328c2ecf20Sopenharmony_ci		rtl_set_bbreg(hw, ROFDM0_XATXIQIMBALANCE,
10338c2ecf20Sopenharmony_ci			      MASKDWORD, value32);
10348c2ecf20Sopenharmony_ci
10358c2ecf20Sopenharmony_ci		value32 = (ele_c & 0x000003C0) >> 6;
10368c2ecf20Sopenharmony_ci		rtl_set_bbreg(hw, ROFDM0_XCTXAFE, MASKH4BITS,
10378c2ecf20Sopenharmony_ci			      value32);
10388c2ecf20Sopenharmony_ci
10398c2ecf20Sopenharmony_ci		value32 = ((val_x * ele_d) >> 7) & 0x01;
10408c2ecf20Sopenharmony_ci		rtl_set_bbreg(hw, ROFDM0_ECCATHRESHOLD, BIT(24),
10418c2ecf20Sopenharmony_ci			      value32);
10428c2ecf20Sopenharmony_ci
10438c2ecf20Sopenharmony_ci	} else {
10448c2ecf20Sopenharmony_ci		rtl_set_bbreg(hw, ROFDM0_XATXIQIMBALANCE,
10458c2ecf20Sopenharmony_ci			      MASKDWORD,
10468c2ecf20Sopenharmony_ci			      ofdmswing_table[(u8)ofdm_index[0]]);
10478c2ecf20Sopenharmony_ci		rtl_set_bbreg(hw, ROFDM0_XCTXAFE, MASKH4BITS,
10488c2ecf20Sopenharmony_ci			      0x00);
10498c2ecf20Sopenharmony_ci		rtl_set_bbreg(hw, ROFDM0_ECCATHRESHOLD,
10508c2ecf20Sopenharmony_ci			      BIT(24), 0x00);
10518c2ecf20Sopenharmony_ci	}
10528c2ecf20Sopenharmony_ci
10538c2ecf20Sopenharmony_ci	rtl_dbg(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
10548c2ecf20Sopenharmony_ci		"TxPwrTracking for interface %d path A: X = 0x%lx, Y = 0x%lx ele_A = 0x%lx ele_C = 0x%lx ele_D = 0x%lx 0xe94 = 0x%lx 0xe9c = 0x%lx\n",
10558c2ecf20Sopenharmony_ci		rtlhal->interfaceindex,
10568c2ecf20Sopenharmony_ci		val_x, val_y, ele_a, ele_c, ele_d,
10578c2ecf20Sopenharmony_ci		val_x, val_y);
10588c2ecf20Sopenharmony_ci
10598c2ecf20Sopenharmony_ci	if (cck_index >= CCK_TABLE_SIZE)
10608c2ecf20Sopenharmony_ci		cck_index = CCK_TABLE_SIZE - 1;
10618c2ecf20Sopenharmony_ci	if (cck_index < 0)
10628c2ecf20Sopenharmony_ci		cck_index = 0;
10638c2ecf20Sopenharmony_ci	if (rtlhal->current_bandtype == BAND_ON_2_4G) {
10648c2ecf20Sopenharmony_ci		/* Adjust CCK according to IQK result */
10658c2ecf20Sopenharmony_ci		if (!rtlpriv->dm.cck_inch14) {
10668c2ecf20Sopenharmony_ci			rtl_write_byte(rtlpriv, 0xa22,
10678c2ecf20Sopenharmony_ci				       cckswing_table_ch1ch13[cck_index][0]);
10688c2ecf20Sopenharmony_ci			rtl_write_byte(rtlpriv, 0xa23,
10698c2ecf20Sopenharmony_ci				       cckswing_table_ch1ch13[cck_index][1]);
10708c2ecf20Sopenharmony_ci			rtl_write_byte(rtlpriv, 0xa24,
10718c2ecf20Sopenharmony_ci				       cckswing_table_ch1ch13[cck_index][2]);
10728c2ecf20Sopenharmony_ci			rtl_write_byte(rtlpriv, 0xa25,
10738c2ecf20Sopenharmony_ci				       cckswing_table_ch1ch13[cck_index][3]);
10748c2ecf20Sopenharmony_ci			rtl_write_byte(rtlpriv, 0xa26,
10758c2ecf20Sopenharmony_ci				       cckswing_table_ch1ch13[cck_index][4]);
10768c2ecf20Sopenharmony_ci			rtl_write_byte(rtlpriv, 0xa27,
10778c2ecf20Sopenharmony_ci				       cckswing_table_ch1ch13[cck_index][5]);
10788c2ecf20Sopenharmony_ci			rtl_write_byte(rtlpriv, 0xa28,
10798c2ecf20Sopenharmony_ci				       cckswing_table_ch1ch13[cck_index][6]);
10808c2ecf20Sopenharmony_ci			rtl_write_byte(rtlpriv, 0xa29,
10818c2ecf20Sopenharmony_ci				       cckswing_table_ch1ch13[cck_index][7]);
10828c2ecf20Sopenharmony_ci		} else {
10838c2ecf20Sopenharmony_ci			rtl_write_byte(rtlpriv, 0xa22,
10848c2ecf20Sopenharmony_ci				       cckswing_table_ch14[cck_index][0]);
10858c2ecf20Sopenharmony_ci			rtl_write_byte(rtlpriv, 0xa23,
10868c2ecf20Sopenharmony_ci				       cckswing_table_ch14[cck_index][1]);
10878c2ecf20Sopenharmony_ci			rtl_write_byte(rtlpriv, 0xa24,
10888c2ecf20Sopenharmony_ci				       cckswing_table_ch14[cck_index][2]);
10898c2ecf20Sopenharmony_ci			rtl_write_byte(rtlpriv, 0xa25,
10908c2ecf20Sopenharmony_ci				       cckswing_table_ch14[cck_index][3]);
10918c2ecf20Sopenharmony_ci			rtl_write_byte(rtlpriv, 0xa26,
10928c2ecf20Sopenharmony_ci				       cckswing_table_ch14[cck_index][4]);
10938c2ecf20Sopenharmony_ci			rtl_write_byte(rtlpriv, 0xa27,
10948c2ecf20Sopenharmony_ci				       cckswing_table_ch14[cck_index][5]);
10958c2ecf20Sopenharmony_ci			rtl_write_byte(rtlpriv, 0xa28,
10968c2ecf20Sopenharmony_ci				       cckswing_table_ch14[cck_index][6]);
10978c2ecf20Sopenharmony_ci			rtl_write_byte(rtlpriv, 0xa29,
10988c2ecf20Sopenharmony_ci				       cckswing_table_ch14[cck_index][7]);
10998c2ecf20Sopenharmony_ci		}
11008c2ecf20Sopenharmony_ci	}
11018c2ecf20Sopenharmony_ci	if (is2t) {
11028c2ecf20Sopenharmony_ci		ele_d = (ofdmswing_table[ofdm_index[1]] & 0xFFC00000) >> 22;
11038c2ecf20Sopenharmony_ci		val_x = rtlphy->iqk_matrix[indexforchannel].value[0][4];
11048c2ecf20Sopenharmony_ci		val_y = rtlphy->iqk_matrix[indexforchannel].value[0][5];
11058c2ecf20Sopenharmony_ci		if (val_x != 0) {
11068c2ecf20Sopenharmony_ci			if ((val_x & 0x00000200) != 0)
11078c2ecf20Sopenharmony_ci				/* consider minus */
11088c2ecf20Sopenharmony_ci				val_x = val_x | 0xFFFFFC00;
11098c2ecf20Sopenharmony_ci			ele_a = ((val_x * ele_d) >> 8) & 0x000003FF;
11108c2ecf20Sopenharmony_ci			/* new element C = element D x Y */
11118c2ecf20Sopenharmony_ci			if ((val_y & 0x00000200) != 0)
11128c2ecf20Sopenharmony_ci				val_y = val_y | 0xFFFFFC00;
11138c2ecf20Sopenharmony_ci			ele_c = ((val_y * ele_d) >> 8) & 0x00003FF;
11148c2ecf20Sopenharmony_ci			/* write new elements A, C, D to regC88
11158c2ecf20Sopenharmony_ci			 * and regC9C, element B is always 0
11168c2ecf20Sopenharmony_ci			 */
11178c2ecf20Sopenharmony_ci			value32 = (ele_d << 22) | ((ele_c & 0x3F) << 16) | ele_a;
11188c2ecf20Sopenharmony_ci			rtl_set_bbreg(hw,
11198c2ecf20Sopenharmony_ci				      ROFDM0_XBTXIQIMBALANCE,
11208c2ecf20Sopenharmony_ci				      MASKDWORD, value32);
11218c2ecf20Sopenharmony_ci			value32 = (ele_c & 0x000003C0) >> 6;
11228c2ecf20Sopenharmony_ci			rtl_set_bbreg(hw, ROFDM0_XDTXAFE,
11238c2ecf20Sopenharmony_ci				      MASKH4BITS, value32);
11248c2ecf20Sopenharmony_ci			value32 = ((val_x * ele_d) >> 7) & 0x01;
11258c2ecf20Sopenharmony_ci			rtl_set_bbreg(hw, ROFDM0_ECCATHRESHOLD,
11268c2ecf20Sopenharmony_ci				      BIT(28), value32);
11278c2ecf20Sopenharmony_ci		} else {
11288c2ecf20Sopenharmony_ci			rtl_set_bbreg(hw,
11298c2ecf20Sopenharmony_ci				      ROFDM0_XBTXIQIMBALANCE,
11308c2ecf20Sopenharmony_ci				      MASKDWORD,
11318c2ecf20Sopenharmony_ci				      ofdmswing_table[ofdm_index[1]]);
11328c2ecf20Sopenharmony_ci			rtl_set_bbreg(hw, ROFDM0_XDTXAFE,
11338c2ecf20Sopenharmony_ci				      MASKH4BITS, 0x00);
11348c2ecf20Sopenharmony_ci			rtl_set_bbreg(hw, ROFDM0_ECCATHRESHOLD,
11358c2ecf20Sopenharmony_ci				      BIT(28), 0x00);
11368c2ecf20Sopenharmony_ci		}
11378c2ecf20Sopenharmony_ci		rtl_dbg(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
11388c2ecf20Sopenharmony_ci			"TxPwrTracking path B: X = 0x%lx, Y = 0x%lx ele_A = 0x%lx ele_C = 0x%lx ele_D = 0x%lx 0xeb4 = 0x%lx 0xebc = 0x%lx\n",
11398c2ecf20Sopenharmony_ci			val_x, val_y, ele_a, ele_c,
11408c2ecf20Sopenharmony_ci			ele_d, val_x, val_y);
11418c2ecf20Sopenharmony_ci	}
11428c2ecf20Sopenharmony_ci	rtl_dbg(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
11438c2ecf20Sopenharmony_ci		"TxPwrTracking 0xc80 = 0x%x, 0xc94 = 0x%x RF 0x24 = 0x%x\n",
11448c2ecf20Sopenharmony_ci		rtl_get_bbreg(hw, 0xc80, MASKDWORD),
11458c2ecf20Sopenharmony_ci		rtl_get_bbreg(hw, 0xc94, MASKDWORD),
11468c2ecf20Sopenharmony_ci		rtl_get_rfreg(hw, RF90_PATH_A, 0x24,
11478c2ecf20Sopenharmony_ci			      RFREG_OFFSET_MASK));
11488c2ecf20Sopenharmony_ci
11498c2ecf20Sopenharmony_cicheck_delta:
11508c2ecf20Sopenharmony_ci	if (delta_iqk > rtlefuse->delta_iqk && rtlefuse->delta_iqk != 0) {
11518c2ecf20Sopenharmony_ci		rtl92d_phy_reset_iqk_result(hw);
11528c2ecf20Sopenharmony_ci		rtlpriv->dm.thermalvalue_iqk = thermalvalue;
11538c2ecf20Sopenharmony_ci		rtl92d_phy_iq_calibrate(hw);
11548c2ecf20Sopenharmony_ci	}
11558c2ecf20Sopenharmony_ci	if (delta_rxgain > 0 && rtlhal->current_bandtype == BAND_ON_5G &&
11568c2ecf20Sopenharmony_ci	    thermalvalue <= rtlefuse->eeprom_thermalmeter) {
11578c2ecf20Sopenharmony_ci		rtlpriv->dm.thermalvalue_rxgain = thermalvalue;
11588c2ecf20Sopenharmony_ci		rtl92d_dm_rxgain_tracking_thermalmeter(hw);
11598c2ecf20Sopenharmony_ci	}
11608c2ecf20Sopenharmony_ci	if (rtlpriv->dm.txpower_track_control)
11618c2ecf20Sopenharmony_ci		rtlpriv->dm.thermalvalue = thermalvalue;
11628c2ecf20Sopenharmony_ci
11638c2ecf20Sopenharmony_ciexit:
11648c2ecf20Sopenharmony_ci	rtl_dbg(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD, "<===\n");
11658c2ecf20Sopenharmony_ci}
11668c2ecf20Sopenharmony_ci
11678c2ecf20Sopenharmony_cistatic void rtl92d_dm_initialize_txpower_tracking(struct ieee80211_hw *hw)
11688c2ecf20Sopenharmony_ci{
11698c2ecf20Sopenharmony_ci	struct rtl_priv *rtlpriv = rtl_priv(hw);
11708c2ecf20Sopenharmony_ci
11718c2ecf20Sopenharmony_ci	rtlpriv->dm.txpower_tracking = true;
11728c2ecf20Sopenharmony_ci	rtlpriv->dm.txpower_trackinginit = false;
11738c2ecf20Sopenharmony_ci	rtlpriv->dm.txpower_track_control = true;
11748c2ecf20Sopenharmony_ci	rtl_dbg(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
11758c2ecf20Sopenharmony_ci		"pMgntInfo->txpower_tracking = %d\n",
11768c2ecf20Sopenharmony_ci		rtlpriv->dm.txpower_tracking);
11778c2ecf20Sopenharmony_ci}
11788c2ecf20Sopenharmony_ci
11798c2ecf20Sopenharmony_civoid rtl92d_dm_check_txpower_tracking_thermal_meter(struct ieee80211_hw *hw)
11808c2ecf20Sopenharmony_ci{
11818c2ecf20Sopenharmony_ci	struct rtl_priv *rtlpriv = rtl_priv(hw);
11828c2ecf20Sopenharmony_ci
11838c2ecf20Sopenharmony_ci	if (!rtlpriv->dm.txpower_tracking)
11848c2ecf20Sopenharmony_ci		return;
11858c2ecf20Sopenharmony_ci
11868c2ecf20Sopenharmony_ci	if (!rtlpriv->dm.tm_trigger) {
11878c2ecf20Sopenharmony_ci		rtl_set_rfreg(hw, RF90_PATH_A, RF_T_METER, BIT(17) |
11888c2ecf20Sopenharmony_ci			      BIT(16), 0x03);
11898c2ecf20Sopenharmony_ci		rtl_dbg(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
11908c2ecf20Sopenharmony_ci			"Trigger 92S Thermal Meter!!\n");
11918c2ecf20Sopenharmony_ci		rtlpriv->dm.tm_trigger = 1;
11928c2ecf20Sopenharmony_ci		return;
11938c2ecf20Sopenharmony_ci	} else {
11948c2ecf20Sopenharmony_ci		rtl_dbg(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
11958c2ecf20Sopenharmony_ci			"Schedule TxPowerTracking direct call!!\n");
11968c2ecf20Sopenharmony_ci		rtl92d_dm_txpower_tracking_callback_thermalmeter(hw);
11978c2ecf20Sopenharmony_ci		rtlpriv->dm.tm_trigger = 0;
11988c2ecf20Sopenharmony_ci	}
11998c2ecf20Sopenharmony_ci}
12008c2ecf20Sopenharmony_ci
12018c2ecf20Sopenharmony_civoid rtl92d_dm_init_rate_adaptive_mask(struct ieee80211_hw *hw)
12028c2ecf20Sopenharmony_ci{
12038c2ecf20Sopenharmony_ci	struct rtl_priv *rtlpriv = rtl_priv(hw);
12048c2ecf20Sopenharmony_ci	struct rate_adaptive *ra = &(rtlpriv->ra);
12058c2ecf20Sopenharmony_ci
12068c2ecf20Sopenharmony_ci	ra->ratr_state = DM_RATR_STA_INIT;
12078c2ecf20Sopenharmony_ci	ra->pre_ratr_state = DM_RATR_STA_INIT;
12088c2ecf20Sopenharmony_ci	if (rtlpriv->dm.dm_type == DM_TYPE_BYDRIVER)
12098c2ecf20Sopenharmony_ci		rtlpriv->dm.useramask = true;
12108c2ecf20Sopenharmony_ci	else
12118c2ecf20Sopenharmony_ci		rtlpriv->dm.useramask = false;
12128c2ecf20Sopenharmony_ci}
12138c2ecf20Sopenharmony_ci
12148c2ecf20Sopenharmony_civoid rtl92d_dm_init(struct ieee80211_hw *hw)
12158c2ecf20Sopenharmony_ci{
12168c2ecf20Sopenharmony_ci	struct rtl_priv *rtlpriv = rtl_priv(hw);
12178c2ecf20Sopenharmony_ci
12188c2ecf20Sopenharmony_ci	rtlpriv->dm.dm_type = DM_TYPE_BYDRIVER;
12198c2ecf20Sopenharmony_ci	rtl_dm_diginit(hw, 0x20);
12208c2ecf20Sopenharmony_ci	rtlpriv->dm_digtable.rx_gain_max = DM_DIG_FA_UPPER;
12218c2ecf20Sopenharmony_ci	rtlpriv->dm_digtable.rx_gain_min = DM_DIG_FA_LOWER;
12228c2ecf20Sopenharmony_ci	rtl92d_dm_init_dynamic_txpower(hw);
12238c2ecf20Sopenharmony_ci	rtl92d_dm_init_edca_turbo(hw);
12248c2ecf20Sopenharmony_ci	rtl92d_dm_init_rate_adaptive_mask(hw);
12258c2ecf20Sopenharmony_ci	rtl92d_dm_initialize_txpower_tracking(hw);
12268c2ecf20Sopenharmony_ci}
12278c2ecf20Sopenharmony_ci
12288c2ecf20Sopenharmony_civoid rtl92d_dm_watchdog(struct ieee80211_hw *hw)
12298c2ecf20Sopenharmony_ci{
12308c2ecf20Sopenharmony_ci	struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
12318c2ecf20Sopenharmony_ci	bool fw_current_inpsmode = false;
12328c2ecf20Sopenharmony_ci	bool fwps_awake = true;
12338c2ecf20Sopenharmony_ci
12348c2ecf20Sopenharmony_ci	/* 1. RF is OFF. (No need to do DM.)
12358c2ecf20Sopenharmony_ci	 * 2. Fw is under power saving mode for FwLPS.
12368c2ecf20Sopenharmony_ci	 *    (Prevent from SW/FW I/O racing.)
12378c2ecf20Sopenharmony_ci	 * 3. IPS workitem is scheduled. (Prevent from IPS sequence
12388c2ecf20Sopenharmony_ci	 *    to be swapped with DM.
12398c2ecf20Sopenharmony_ci	 * 4. RFChangeInProgress is TRUE.
12408c2ecf20Sopenharmony_ci	 *    (Prevent from broken by IPS/HW/SW Rf off.) */
12418c2ecf20Sopenharmony_ci
12428c2ecf20Sopenharmony_ci	if ((ppsc->rfpwr_state == ERFON) && ((!fw_current_inpsmode) &&
12438c2ecf20Sopenharmony_ci	    fwps_awake) && (!ppsc->rfchange_inprogress)) {
12448c2ecf20Sopenharmony_ci		rtl92d_dm_pwdb_monitor(hw);
12458c2ecf20Sopenharmony_ci		rtl92d_dm_false_alarm_counter_statistics(hw);
12468c2ecf20Sopenharmony_ci		rtl92d_dm_find_minimum_rssi(hw);
12478c2ecf20Sopenharmony_ci		rtl92d_dm_dig(hw);
12488c2ecf20Sopenharmony_ci		/* rtl92d_dm_dynamic_bb_powersaving(hw); */
12498c2ecf20Sopenharmony_ci		rtl92d_dm_dynamic_txpower(hw);
12508c2ecf20Sopenharmony_ci		/* rtl92d_dm_check_txpower_tracking_thermal_meter(hw); */
12518c2ecf20Sopenharmony_ci		/* rtl92d_dm_refresh_rate_adaptive_mask(hw); */
12528c2ecf20Sopenharmony_ci		/* rtl92d_dm_interrupt_migration(hw); */
12538c2ecf20Sopenharmony_ci		rtl92d_dm_check_edca_turbo(hw);
12548c2ecf20Sopenharmony_ci	}
12558c2ecf20Sopenharmony_ci}
1256