Path: blob/master/ALFA-W1F1/RTL8814AU/hal/phydm/phydm_adaptivity.c
1307 views
/******************************************************************************1*2* Copyright(c) 2007 - 2017 Realtek Corporation.3*4* This program is free software; you can redistribute it and/or modify it5* under the terms of version 2 of the GNU General Public License as6* published by the Free Software Foundation.7*8* This program is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for11* more details.12*13* The full GNU General Public License is included in this distribution in the14* file called LICENSE.15*16* Contact Information:17* wlanfae <[email protected]>18* Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,19* Hsinchu 300, Taiwan.20*21* Larry Finger <[email protected]>22*23*****************************************************************************/2425/*@************************************************************26* include files27************************************************************/28#include "mp_precomp.h"29#include "phydm_precomp.h"3031#if (DM_ODM_SUPPORT_TYPE & ODM_WIN)32#if WPP_SOFTWARE_TRACE33#include "PhyDM_Adaptivity.tmh"34#endif35#endif36#ifdef PHYDM_SUPPORT_ADAPTIVITY37#if (DM_ODM_SUPPORT_TYPE == ODM_WIN)38boolean39phydm_check_channel_plan(void *dm_void)40{41struct dm_struct *dm = (struct dm_struct *)dm_void;42struct phydm_adaptivity_struct *adapt = &dm->adaptivity;43void *adapter = dm->adapter;44PMGNT_INFO mgnt_info = &((PADAPTER)adapter)->MgntInfo;4546if (mgnt_info->RegEnableAdaptivity != 2)47return false;4849if (!dm->carrier_sense_enable) { /*@check domain Code for adaptivity or CarrierSense*/50if ((*dm->band_type == ODM_BAND_5G) &&51!(adapt->regulation_5g == REGULATION_ETSI || adapt->regulation_5g == REGULATION_WW)) {52PHYDM_DBG(dm, DBG_ADPTVTY,53"adaptivity skip 5G domain code : %d\n",54adapt->regulation_5g);55return true;56} else if ((*dm->band_type == ODM_BAND_2_4G) &&57!(adapt->regulation_2g == REGULATION_ETSI || adapt->regulation_2g == REGULATION_WW)) {58PHYDM_DBG(dm, DBG_ADPTVTY,59"adaptivity skip 2.4G domain code : %d\n",60adapt->regulation_2g);61return true;62} else if ((*dm->band_type != ODM_BAND_2_4G) && (*dm->band_type != ODM_BAND_5G)) {63PHYDM_DBG(dm, DBG_ADPTVTY,64"adaptivity neither 2G nor 5G band, return\n");65return true;66}67} else {68if ((*dm->band_type == ODM_BAND_5G) &&69!(adapt->regulation_5g == REGULATION_MKK || adapt->regulation_5g == REGULATION_WW)) {70PHYDM_DBG(dm, DBG_ADPTVTY,71"CarrierSense skip 5G domain code : %d\n",72adapt->regulation_5g);73return true;74} else if ((*dm->band_type == ODM_BAND_2_4G) &&75!(adapt->regulation_2g == REGULATION_MKK || adapt->regulation_2g == REGULATION_WW)) {76PHYDM_DBG(dm, DBG_ADPTVTY,77"CarrierSense skip 2.4G domain code : %d\n",78adapt->regulation_2g);79return true;80} else if ((*dm->band_type != ODM_BAND_2_4G) && (*dm->band_type != ODM_BAND_5G)) {81PHYDM_DBG(dm, DBG_ADPTVTY,82"CarrierSense neither 2G nor 5G band, return\n");83return true;84}85}8687return false;88}8990boolean91phydm_soft_ap_special_set(void *dm_void)92{93struct dm_struct *dm = (struct dm_struct *)dm_void;94struct phydm_adaptivity_struct *adapt = &dm->adaptivity;95boolean disable_ap_adapt_setting = false;9697if (dm->soft_ap_mode != NULL) {98if (*dm->soft_ap_mode != 0 &&99(dm->soft_ap_special_setting & BIT(0)))100disable_ap_adapt_setting = true;101else102disable_ap_adapt_setting = false;103PHYDM_DBG(dm, DBG_ADPTVTY,104"soft_ap_setting = %x, soft_ap = %d, dis_ap_adapt = %d\n",105dm->soft_ap_special_setting, *dm->soft_ap_mode,106disable_ap_adapt_setting);107}108109return disable_ap_adapt_setting;110}111112boolean113phydm_ap_num_check(void *dm_void)114{115struct dm_struct *dm = (struct dm_struct *)dm_void;116struct phydm_adaptivity_struct *adapt = &dm->adaptivity;117boolean dis_adapt = false;118119if (dm->ap_total_num > adapt->ap_num_th)120dis_adapt = true;121else122dis_adapt = false;123124PHYDM_DBG(dm, DBG_ADPTVTY, "AP total num = %d, AP num threshold = %d\n",125dm->ap_total_num, adapt->ap_num_th);126return dis_adapt;127}128129void phydm_check_adaptivity(void *dm_void)130{131struct dm_struct *dm = (struct dm_struct *)dm_void;132struct phydm_adaptivity_struct *adapt = &dm->adaptivity;133boolean disable_adapt = false;134135if (!adapt->mode_cvrt_en)136return;137138if (phydm_check_channel_plan(dm) || phydm_ap_num_check(dm) ||139phydm_soft_ap_special_set(dm))140disable_adapt = true;141142if (*dm->edcca_mode == PHYDM_EDCCA_ADAPT_MODE && disable_adapt)143*dm->edcca_mode = PHYDM_EDCCA_NORMAL_MODE;144else if (*dm->edcca_mode == PHYDM_EDCCA_NORMAL_MODE && !disable_adapt)145*dm->edcca_mode = PHYDM_EDCCA_ADAPT_MODE;146}147148#endif149150void phydm_dig_up_bound_lmt_en(void *dm_void)151{152struct dm_struct *dm = (struct dm_struct *)dm_void;153struct phydm_adaptivity_struct *adapt = &dm->adaptivity;154155if (*dm->edcca_mode != PHYDM_EDCCA_ADAPT_MODE ||156!dm->is_linked) {157adapt->igi_up_bound_lmt_cnt = 0;158adapt->igi_lmt_en = false;159return;160}161162if (dm->total_tp > 1) {163adapt->igi_lmt_en = true;164adapt->igi_up_bound_lmt_cnt = adapt->igi_up_bound_lmt_val;165PHYDM_DBG(dm, DBG_ADPTVTY,166"TP >1, Start limit IGI upper bound\n");167} else {168if (adapt->igi_up_bound_lmt_cnt == 0)169adapt->igi_lmt_en = false;170else171adapt->igi_up_bound_lmt_cnt--;172}173174PHYDM_DBG(dm, DBG_ADPTVTY, "IGI_lmt_cnt = %d\n",175adapt->igi_up_bound_lmt_cnt);176}177178void phydm_set_edcca_threshold(void *dm_void, s8 H2L, s8 L2H)179{180struct dm_struct *dm = (struct dm_struct *)dm_void;181182if (dm->support_ic_type & ODM_IC_JGR3_SERIES) {183odm_set_bb_reg(dm, R_0x84c, MASKBYTE2, (u8)L2H + 0x80);184odm_set_bb_reg(dm, R_0x84c, MASKBYTE3, (u8)H2L + 0x80);185} else if (dm->support_ic_type & ODM_IC_11N_SERIES) {186odm_set_bb_reg(dm, R_0xc4c, MASKBYTE0, (u8)L2H);187odm_set_bb_reg(dm, R_0xc4c, MASKBYTE2, (u8)H2L);188} else if (dm->support_ic_type & ODM_IC_11AC_SERIES) {189odm_set_bb_reg(dm, R_0x8a4, MASKBYTE0, (u8)L2H);190odm_set_bb_reg(dm, R_0x8a4, MASKBYTE1, (u8)H2L);191}192}193194void phydm_mac_edcca_state(void *dm_void, enum phydm_mac_edcca_type state)195{196struct dm_struct *dm = (struct dm_struct *)dm_void;197198if (state == PHYDM_IGNORE_EDCCA) {199/*@ignore EDCCA*/200odm_set_mac_reg(dm, R_0x520, BIT(15), 1);201/*@enable EDCCA count down*/202odm_set_mac_reg(dm, R_0x524, BIT(11), 0);203} else { /*@don't set MAC ignore EDCCA signal*/204/*@don't ignore EDCCA*/205odm_set_mac_reg(dm, R_0x520, BIT(15), 0);206/*@disable EDCCA count down*/207odm_set_mac_reg(dm, R_0x524, BIT(11), 1);208}209PHYDM_DBG(dm, DBG_ADPTVTY, "EDCCA enable state = %d\n", state);210}211212void phydm_search_pwdb_lower_bound(void *dm_void)213{214struct dm_struct *dm = (struct dm_struct *)dm_void;215struct phydm_adaptivity_struct *adapt = &dm->adaptivity;216u32 value32 = 0, reg_value32 = 0;217u8 cnt = 0, try_count = 0;218u8 tx_edcca1 = 0;219boolean is_adjust = true;220s8 th_l2h, th_h2l, igi_target_dc = 0x32;221s8 diff = 0;222s8 IGI = adapt->igi_base + 30 + dm->th_l2h_ini - dm->th_edcca_hl_diff;223224halrf_rf_lna_setting(dm, HALRF_LNA_DISABLE);225diff = igi_target_dc - IGI;226th_l2h = dm->th_l2h_ini + diff;227if (th_l2h > 10)228th_l2h = 10;229230th_h2l = th_l2h - dm->th_edcca_hl_diff;231phydm_set_edcca_threshold(dm, th_h2l, th_l2h);232ODM_delay_ms(30);233234while (is_adjust) {235/*@check CCA status*/236/*set debug port to 0x0*/237if (phydm_set_bb_dbg_port(dm, DBGPORT_PRI_1, 0x0)) {238reg_value32 = phydm_get_bb_dbg_port_val(dm);239240while (reg_value32 & BIT(3) && try_count < 3) {241ODM_delay_ms(3);242try_count = try_count + 1;243reg_value32 = phydm_get_bb_dbg_port_val(dm);244}245phydm_release_bb_dbg_port(dm);246try_count = 0;247}248249/*@count EDCCA signal = 1 times*/250for (cnt = 0; cnt < 20; cnt++) {251if (phydm_set_bb_dbg_port(dm, DBGPORT_PRI_1,252adapt->adaptivity_dbg_port)) {253value32 = phydm_get_bb_dbg_port_val(dm);254phydm_release_bb_dbg_port(dm);255}256257if (value32 & BIT(30) && dm->support_ic_type &258(ODM_RTL8723B | ODM_RTL8188E))259tx_edcca1 = tx_edcca1 + 1;260else if (value32 & BIT(29))261tx_edcca1 = tx_edcca1 + 1;262}263264if (tx_edcca1 > 1) {265IGI = IGI - 1;266th_l2h = th_l2h + 1;267if (th_l2h > 10)268th_l2h = 10;269270th_h2l = th_l2h - dm->th_edcca_hl_diff;271phydm_set_edcca_threshold(dm, th_h2l, th_l2h);272tx_edcca1 = 0;273if (th_l2h == 10)274is_adjust = false;275276} else {277is_adjust = false;278}279}280281adapt->adapt_igi_up = IGI - ADAPT_DC_BACKOFF;282adapt->h2l_lb = th_h2l + ADAPT_DC_BACKOFF;283adapt->l2h_lb = th_l2h + ADAPT_DC_BACKOFF;284285halrf_rf_lna_setting(dm, HALRF_LNA_ENABLE);286phydm_set_edcca_threshold(dm, 0x7f, 0x7f); /*resume to no link state*/287}288289boolean phydm_re_search_condition(void *dm_void)290{291struct dm_struct *dm = (struct dm_struct *)dm_void;292struct phydm_adaptivity_struct *adaptivity = &dm->adaptivity;293u8 adaptivity_igi_upper = adaptivity->adapt_igi_up + ADAPT_DC_BACKOFF;294295if (adaptivity_igi_upper <= 0x26)296return true;297else298return false;299}300301void phydm_set_l2h_th_ini(void *dm_void)302{303struct dm_struct *dm = (struct dm_struct *)dm_void;304305/*@ [New Format: JGR3]IGI-idx:45 = RSSI:35 = -65dBm*/306if (dm->support_ic_type & ODM_IC_JGR3_SERIES) {307if (dm->support_ic_type & ODM_RTL8822C)308dm->th_l2h_ini = 45;309else if (dm->support_ic_type & ODM_RTL8814B)310dm->th_l2h_ini = 49;311} else if (dm->support_ic_type & ODM_IC_11AC_SERIES) {312/*@ [Old Format] -11+base(50) = IGI_idx:39 = RSSI:29 = -71dBm*/313if (dm->support_ic_type & (ODM_RTL8821 | ODM_RTL8812))314dm->th_l2h_ini = -17;315else316dm->th_l2h_ini = -14;317} else { /*ODM_IC_11N_SERIES*/318if (dm->support_ic_type & ODM_RTL8721D)319dm->th_l2h_ini = -14;320else321dm->th_l2h_ini = -11;322}323}324325void phydm_set_l2h_th_ini_carrier_sense(void *dm_void)326{327struct dm_struct *dm = (struct dm_struct *)dm_void;328329if (dm->support_ic_type & ODM_IC_JGR3_SERIES)330dm->th_l2h_ini = 60; /*@ -50dBm*/331else332dm->th_l2h_ini = 10; /*@ -50dBm*/333}334335void phydm_set_forgetting_factor(void *dm_void)336{337struct dm_struct *dm = (struct dm_struct *)dm_void;338339if (*dm->edcca_mode != PHYDM_EDCCA_ADAPT_MODE)340return;341342if (dm->support_ic_type & (ODM_RTL8821C | ODM_RTL8822B | ODM_RTL8814A |343ODM_RTL8195B))344odm_set_bb_reg(dm, R_0x8a0, BIT(1) | BIT(0), 0);345}346347void phydm_edcca_decision_opt(void *dm_void)348{349struct dm_struct *dm = (struct dm_struct *)dm_void;350351if (*dm->edcca_mode != PHYDM_EDCCA_ADAPT_MODE)352return;353354if (dm->support_ic_type & ODM_RTL8822B)355odm_set_bb_reg(dm, R_0x8dc, BIT(5), 0x1);356else if (dm->support_ic_type & (ODM_RTL8197F | ODM_RTL8192F))357odm_set_bb_reg(dm, R_0xce8, BIT(13), 0x1);358else if (dm->support_ic_type & ODM_IC_JGR3_SERIES)359odm_set_bb_reg(dm, R_0x844, BIT(30) | BIT(29), 0x0);360}361362void phydm_adaptivity_debug(void *dm_void, char input[][16], u32 *_used,363char *output, u32 *_out_len)364{365struct dm_struct *dm = (struct dm_struct *)dm_void;366struct phydm_adaptivity_struct *adaptivity = &dm->adaptivity;367u32 used = *_used;368u32 out_len = *_out_len;369char help[] = "-h";370u32 dm_value[10] = {0};371u8 i = 0, input_idx = 0;372u32 reg_value32 = 0;373s8 h2l_diff = 0;374375for (i = 0; i < 5; i++) {376if (input[i + 1]) {377PHYDM_SSCANF(input[i + 1], DCMD_HEX, &dm_value[i]);378input_idx++;379}380}381if (strcmp(input[1], help) == 0) {382PDM_SNPF(out_len, used, output + used, out_len - used,383"Show adaptivity message: {0}\n");384PDM_SNPF(out_len, used, output + used, out_len - used,385"Enter debug mode: {1} {th_l2h_ini} {th_edcca_hl_diff}\n");386PDM_SNPF(out_len, used, output + used, out_len - used,387"Leave debug mode: {2}\n");388goto out;389}390391if (input_idx == 0)392return;393394if (dm_value[0] == PHYDM_ADAPT_DEBUG) {395adaptivity->debug_mode = true;396if (dm_value[1] != 0)397dm->th_l2h_ini = (s8)dm_value[1];398if (dm_value[2] != 0)399dm->th_edcca_hl_diff = (s8)dm_value[2];400PDM_SNPF(out_len, used, output + used, out_len - used,401"th_l2h_ini = %d, th_edcca_hl_diff = %d\n",402dm->th_l2h_ini, dm->th_edcca_hl_diff);403} else if (dm_value[0] == PHYDM_ADAPT_RESUME) {404adaptivity->debug_mode = false;405dm->th_l2h_ini = adaptivity->th_l2h_ini_backup;406dm->th_edcca_hl_diff = adaptivity->th_edcca_hl_diff_backup;407} else if (dm_value[0] == PHYDM_ADAPT_MSG) {408PDM_SNPF(out_len, used, output + used, out_len - used,409"debug_mode = %s, th_l2h_ini = %d\n",410(adaptivity->debug_mode ? "TRUE" : "FALSE"),411dm->th_l2h_ini);412if (dm->support_ic_type & ODM_IC_JGR3_SERIES) {413reg_value32 = odm_get_bb_reg(dm, R_0x84c, MASKDWORD);414h2l_diff = (s8)((0x00ff0000 & reg_value32) >> 16) -415(s8)((0xff000000 & reg_value32) >> 24);416} else if (dm->support_ic_type & ODM_IC_11N_SERIES) {417reg_value32 = odm_get_bb_reg(dm, R_0xc4c, MASKDWORD);418h2l_diff = (s8)(0x000000ff & reg_value32) -419(s8)((0x00ff0000 & reg_value32) >> 16);420} else if (dm->support_ic_type & ODM_IC_11AC_SERIES) {421reg_value32 = odm_get_bb_reg(dm, R_0x8a4, MASKDWORD);422h2l_diff = (s8)(0x000000ff & reg_value32) -423(s8)((0x0000ff00 & reg_value32) >> 8);424}425426if (h2l_diff == 7)427PDM_SNPF(out_len, used, output + used, out_len - used,428"adaptivity enable\n");429else430PDM_SNPF(out_len, used, output + used, out_len - used,431"adaptivity disable\n");432}433434out:435*_used = used;436*_out_len = out_len;437}438439void phydm_set_edcca_val(void *dm_void, u32 *val_buf, u8 val_len)440{441struct dm_struct *dm = (struct dm_struct *)dm_void;442443if (val_len != 2) {444PHYDM_DBG(dm, ODM_COMP_API,445"[Error][adaptivity]Need val_len = 2\n");446return;447}448phydm_set_edcca_threshold(dm, (s8)val_buf[1], (s8)val_buf[0]);449}450451boolean phydm_edcca_abort(void *dm_void)452{453struct dm_struct *dm = (struct dm_struct *)dm_void;454struct phydm_adaptivity_struct *adapt = &dm->adaptivity;455#if (DM_ODM_SUPPORT_TYPE == ODM_WIN)456void *adapter = dm->adapter;457u32 is_fw_in_psmode = false;458#endif459460if (!(dm->support_ability & ODM_BB_ADAPTIVITY)) {461PHYDM_DBG(dm, DBG_ADPTVTY, "adaptivity disable\n");462return true;463}464465if (dm->pause_ability & ODM_BB_ADAPTIVITY) {466PHYDM_DBG(dm, DBG_ADPTVTY, "Return: Pause ADPTVTY in LV=%d\n",467dm->pause_lv_table.lv_adapt);468return true;469}470471#if (DM_ODM_SUPPORT_TYPE == ODM_WIN)472((PADAPTER)adapter)->HalFunc.GetHwRegHandler(adapter,473HW_VAR_FW_PSMODE_STATUS,474(u8 *)(&is_fw_in_psmode));475476/*@Disable EDCCA while under LPS mode, added by Roger, 2012.09.14.*/477if (is_fw_in_psmode)478return true;479#endif480481return false;482}483484void phydm_edcca_thre_calc_jgr3(void *dm_void)485{486struct dm_struct *dm = (struct dm_struct *)dm_void;487struct phydm_dig_struct *dig_t = &dm->dm_dig_table;488struct phydm_adaptivity_struct *adapt = &dm->adaptivity;489u8 igi = dig_t->cur_ig_value;490s8 th_l2h = 0, th_h2l = 0;491492if (*dm->edcca_mode == PHYDM_EDCCA_ADAPT_MODE) {493/*prevent pwdB clipping and result in Miss Detection*/494adapt->l2h_dyn_min = (u8)(dm->th_l2h_ini - ADC_BACKOFF);495496if (igi < adapt->l2h_dyn_min)497th_l2h = igi + ADC_BACKOFF;498else499th_l2h = dm->th_l2h_ini;500501th_h2l = th_l2h - dm->th_edcca_hl_diff;502} else {503th_l2h = MAX_2(igi + TH_L2H_DIFF_IGI, EDCCA_TH_L2H_LB);504th_h2l = th_l2h - EDCCA_HL_DIFF_NORMAL;505}506adapt->th_l2h = th_l2h;507adapt->th_h2l = th_h2l;508509phydm_set_edcca_threshold(dm, adapt->th_h2l, adapt->th_l2h);510}511512void phydm_edcca_thre_calc(void *dm_void)513{514struct dm_struct *dm = (struct dm_struct *)dm_void;515struct phydm_dig_struct *dig_t = &dm->dm_dig_table;516struct phydm_adaptivity_struct *adapt = &dm->adaptivity;517u8 igi = dig_t->cur_ig_value;518s8 th_l2h = 0, th_h2l = 0;519s8 diff = 0, igi_target = adapt->igi_base;520521if (dm->support_ic_type & ODM_IC_PWDB_EDCCA) {522/*@fix EDCCA hang issue*/523if (dm->support_ic_type & ODM_RTL8812) {524/*@ADC_mask disable*/525odm_set_bb_reg(dm, R_0x800, BIT(10), 1);526/*@ADC_mask enable*/527odm_set_bb_reg(dm, R_0x800, BIT(10), 0);528}529530if (*dm->edcca_mode == PHYDM_EDCCA_ADAPT_MODE) {531/*@Limit IGI upper bound for adaptivity*/532phydm_dig_up_bound_lmt_en(dm);533diff = igi_target - (s8)igi;534th_l2h = dm->th_l2h_ini + diff;535if (th_l2h > 10)536th_l2h = 10;537538th_h2l = th_l2h - dm->th_edcca_hl_diff;539} else {540th_l2h = 70 - igi;541th_h2l = th_l2h - EDCCA_HL_DIFF_NORMAL;542}543/*replace lower bound to prevent EDCCA always equal 1*/544if (th_h2l < adapt->h2l_lb)545th_h2l = adapt->h2l_lb;546if (th_l2h < adapt->l2h_lb)547th_l2h = adapt->l2h_lb;548PHYDM_DBG(dm, DBG_ADPTVTY,549"adapt_igi_up=0x%x, l2h_lb = %d dBm, h2l_lb = %d dBm\n",550adapt->adapt_igi_up,551IGI_2_DBM(adapt->l2h_lb + adapt->adapt_igi_up),552IGI_2_DBM(adapt->h2l_lb + adapt->adapt_igi_up));553} else { /* < JGR2 & N*/554if (*dm->edcca_mode == PHYDM_EDCCA_ADAPT_MODE) {555/*need to consider PwdB upper bound for 8814 later IC*/556adapt->l2h_dyn_min = (u8)(dm->th_l2h_ini + igi_target);557558if (igi < adapt->l2h_dyn_min)559th_l2h = igi;560else561th_l2h = adapt->l2h_dyn_min;562563th_h2l = th_l2h - dm->th_edcca_hl_diff;564} else {565th_l2h = MAX_2(igi + TH_L2H_DIFF_IGI, EDCCA_TH_L2H_LB);566th_h2l = th_l2h - EDCCA_HL_DIFF_NORMAL;567}568}569570adapt->th_l2h = th_l2h;571adapt->th_h2l = th_h2l;572573phydm_set_edcca_threshold(dm, adapt->th_h2l, adapt->th_l2h);574}575#endif576577void phydm_set_edcca_threshold_api(void *dm_void)578{579#ifdef PHYDM_SUPPORT_ADAPTIVITY580struct dm_struct *dm = (struct dm_struct *)dm_void;581struct phydm_adaptivity_struct *adapt = &dm->adaptivity;582583if (*dm->edcca_mode != PHYDM_EDCCA_ADAPT_MODE)584return;585586if (dm->support_ic_type & ODM_IC_JGR3_SERIES)587phydm_edcca_thre_calc_jgr3(dm);588else589phydm_edcca_thre_calc(dm);590591PHYDM_DBG(dm, DBG_ADPTVTY,592"API :IGI = 0x%x, th_l2h = %d, th_h2l = %d\n",593dm->dm_dig_table.cur_ig_value, adapt->th_l2h, adapt->th_h2l);594#endif595}596597void phydm_adaptivity_info_init(void *dm_void, enum phydm_adapinfo cmn_info,598u32 value)599{600struct dm_struct *dm = (struct dm_struct *)dm_void;601struct phydm_adaptivity_struct *adaptivity = &dm->adaptivity;602603switch (cmn_info) {604case PHYDM_ADAPINFO_CARRIER_SENSE_ENABLE:605dm->carrier_sense_enable = (boolean)value;606break;607case PHYDM_ADAPINFO_TH_L2H_INI:608dm->th_l2h_ini = (s8)value;609break;610case PHYDM_ADAPINFO_TH_EDCCA_HL_DIFF:611dm->th_edcca_hl_diff = (s8)value;612break;613case PHYDM_ADAPINFO_AP_NUM_TH:614adaptivity->ap_num_th = (u8)value;615break;616default:617break;618}619}620621void phydm_adaptivity_info_update(void *dm_void, enum phydm_adapinfo cmn_info,622u32 value)623{624struct dm_struct *dm = (struct dm_struct *)dm_void;625struct phydm_adaptivity_struct *adapt = &dm->adaptivity;626627/*This init variable may be changed in run time.*/628switch (cmn_info) {629case PHYDM_ADAPINFO_DOMAIN_CODE_2G:630adapt->regulation_2g = (u8)value;631break;632case PHYDM_ADAPINFO_DOMAIN_CODE_5G:633adapt->regulation_5g = (u8)value;634break;635default:636break;637}638}639640void phydm_adaptivity_init(void *dm_void)641{642#ifdef PHYDM_SUPPORT_ADAPTIVITY643struct dm_struct *dm = (struct dm_struct *)dm_void;644struct phydm_adaptivity_struct *adaptivity = &dm->adaptivity;645646/* @[Config Adaptivity]*/647if (!dm->edcca_mode) {648pr_debug("[%s] warning!\n", __func__);649dm->edcca_mode = &dm->u8_dummy;650dm->support_ability &= ~ODM_BB_ADAPTIVITY;651return;652}653654#if (DM_ODM_SUPPORT_TYPE & ODM_WIN)655if (!dm->carrier_sense_enable) {656if (dm->th_l2h_ini == 0)657phydm_set_l2h_th_ini(dm);658} else {659phydm_set_l2h_th_ini_carrier_sense(dm);660}661662if (dm->th_edcca_hl_diff == 0)663dm->th_edcca_hl_diff = 7;664665if (dm->wifi_test & RT_WIFI_LOGO)666dm->support_ability &= ~ODM_BB_ADAPTIVITY;667668if (*dm->edcca_mode == PHYDM_EDCCA_ADAPT_MODE)669adaptivity->mode_cvrt_en = true;670else671adaptivity->mode_cvrt_en = false;672#elif (DM_ODM_SUPPORT_TYPE & ODM_CE)673if (!dm->carrier_sense_enable) {674if (dm->th_l2h_ini == 0)675phydm_set_l2h_th_ini(dm);676} else {677phydm_set_l2h_th_ini_carrier_sense(dm);678}679680if (dm->th_edcca_hl_diff == 0)681dm->th_edcca_hl_diff = 7;682683if (dm->wifi_test || *dm->mp_mode)684dm->support_ability &= ~ODM_BB_ADAPTIVITY;685#elif (DM_ODM_SUPPORT_TYPE & ODM_AP)686if (dm->carrier_sense_enable) {687phydm_set_l2h_th_ini_carrier_sense(dm);688dm->th_edcca_hl_diff = 7;689} else {690dm->th_l2h_ini = dm->TH_L2H_default; /*set by mib*/691dm->th_edcca_hl_diff = dm->th_edcca_hl_diff_default;692}693#elif (DM_ODM_SUPPORT_TYPE & ODM_IOT)694if (!dm->carrier_sense_enable) {695if (dm->th_l2h_ini == 0)696phydm_set_l2h_th_ini(dm);697} else {698phydm_set_l2h_th_ini_carrier_sense(dm);699}700701if (dm->th_edcca_hl_diff == 0)702dm->th_edcca_hl_diff = 7;703#endif704705adaptivity->debug_mode = false;706adaptivity->th_l2h_ini_backup = dm->th_l2h_ini;707adaptivity->th_edcca_hl_diff_backup = dm->th_edcca_hl_diff;708adaptivity->igi_base = 0x32;709adaptivity->adapt_igi_up = 0;710adaptivity->h2l_lb = 0;711adaptivity->l2h_lb = 0;712adaptivity->l2h_dyn_min = 0;713adaptivity->th_l2h = 0x7f;714adaptivity->th_h2l = 0x7f;715716if (dm->support_ic_type & ODM_IC_11N_SERIES)717adaptivity->adaptivity_dbg_port = 0x208;718else if (dm->support_ic_type & ODM_IC_11AC_SERIES)719adaptivity->adaptivity_dbg_port = 0x209;720721if (dm->support_ic_type & ODM_IC_11N_SERIES &&722!(dm->support_ic_type & ODM_IC_PWDB_EDCCA)) {723if (dm->support_ic_type & (ODM_RTL8197F | ODM_RTL8192F)) {724/*set to page B1*/725odm_set_bb_reg(dm, R_0xe28, BIT(30), 0x1);726/*@0:rx_dfir, 1: dcnf_out, 2 :rx_iq, 3: rx_nbi_nf_out*/727odm_set_bb_reg(dm, R_0xbc0, BIT(27) | BIT(26), 0x1);728odm_set_bb_reg(dm, R_0xe28, BIT(30), 0x0);729} else {730/*@0:rx_dfir, 1: dcnf_out, 2 :rx_iq, 3: rx_nbi_nf_out*/731odm_set_bb_reg(dm, R_0xe24, BIT(21) | BIT(20), 0x1);732}733} else if (dm->support_ic_type & ODM_IC_11AC_SERIES &&734!(dm->support_ic_type & ODM_IC_PWDB_EDCCA)) {735/*@0:rx_dfir, 1: dcnf_out, 2 :rx_iq, 3: rx_nbi_nf_out*/736odm_set_bb_reg(dm, R_0x944, BIT(29) | BIT(28), 0x1);737}738739if (dm->support_ic_type & ODM_IC_PWDB_EDCCA) {740phydm_search_pwdb_lower_bound(dm);741if (phydm_re_search_condition(dm))742phydm_search_pwdb_lower_bound(dm);743} else {744/*resume to no link state*/745phydm_set_edcca_threshold(dm, 0x7f, 0x7f);746}747748/*@whether to ignore EDCCA*/749phydm_mac_edcca_state(dm, PHYDM_DONT_IGNORE_EDCCA);750751/*@forgetting factor setting*/752phydm_set_forgetting_factor(dm);753754/*@EDCCA behavior based on maximum or mean power*/755phydm_edcca_decision_opt(dm);756757#if (DM_ODM_SUPPORT_TYPE == ODM_AP)758adaptivity->igi_up_bound_lmt_val = 180;759#else760adaptivity->igi_up_bound_lmt_val = 90;761#endif762adaptivity->igi_up_bound_lmt_cnt = 0;763adaptivity->igi_lmt_en = false;764#endif765}766767void phydm_adaptivity(void *dm_void)768{769#ifdef PHYDM_SUPPORT_ADAPTIVITY770struct dm_struct *dm = (struct dm_struct *)dm_void;771struct phydm_adaptivity_struct *adapt = &dm->adaptivity;772struct phydm_dig_struct *dig_t = &dm->dm_dig_table;773774if (phydm_edcca_abort(dm))775return;776777#if (DM_ODM_SUPPORT_TYPE == ODM_WIN)778phydm_check_adaptivity(dm); /*@Check adaptivity enable*/779#endif780781PHYDM_DBG(dm, DBG_ADPTVTY, "%s ====>\n", __func__);782PHYDM_DBG(dm, DBG_ADPTVTY, "mode = %s, debug_mode = %d\n",783(*dm->edcca_mode ?784(dm->carrier_sense_enable ?785"CARRIER SENSE" :786"ADAPTIVITY") :787"NORMAL"),788adapt->debug_mode);789790if (dm->support_ic_type & ODM_IC_JGR3_SERIES)791phydm_edcca_thre_calc_jgr3(dm);792else793phydm_edcca_thre_calc(dm);794795if (*dm->edcca_mode == PHYDM_EDCCA_ADAPT_MODE)796PHYDM_DBG(dm, DBG_ADPTVTY,797"th_l2h_ini = %d, th_edcca_hl_diff = %d\n",798dm->th_l2h_ini, dm->th_edcca_hl_diff);799if (dm->support_ic_type & ODM_IC_PWDB_EDCCA)800PHYDM_DBG(dm, DBG_ADPTVTY,801"IGI = 0x%x, th_l2h = %d dBm, th_h2l = %d dBm\n",802dig_t->cur_ig_value,803IGI_2_DBM(adapt->th_l2h + dig_t->cur_ig_value),804IGI_2_DBM(adapt->th_h2l + dig_t->cur_ig_value));805else806PHYDM_DBG(dm, DBG_ADPTVTY,807"IGI = 0x%x, th_l2h = %d dBm, th_h2l = %d dBm\n",808dig_t->cur_ig_value,809IGI_2_DBM(adapt->th_l2h),810IGI_2_DBM(adapt->th_h2l));811#endif812}813814815816