Path: blob/master/ALFA-W1F1/RTL8814AU/hal/phydm/phydm_dfs.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* ============================================================27* include files28* ============================================================29*/3031#include "mp_precomp.h"32#include "phydm_precomp.h"3334#if defined(CONFIG_PHYDM_DFS_MASTER)3536boolean phydm_dfs_is_meteorology_channel(void *dm_void)37{38struct dm_struct *dm = (struct dm_struct *)dm_void;3940u8 ch = *dm->channel;41u8 bw = *dm->band_width;4243return ((bw == CHANNEL_WIDTH_80 && (ch) >= 116 && (ch) <= 128) ||44(bw == CHANNEL_WIDTH_40 && (ch) >= 116 && (ch) <= 128) ||45(bw == CHANNEL_WIDTH_20 && (ch) >= 120 && (ch) <= 128));46}4748void phydm_dfs_segment_distinguish(void *dm_void, enum rf_syn syn_path)49{50struct dm_struct *dm = (struct dm_struct *)dm_void;5152if (!(dm->support_ic_type & (ODM_RTL8814B)))53return;54if (syn_path == RF_SYN1)55dm->seg1_dfs_flag = 1;56else57dm->seg1_dfs_flag = 0;58}5960void phydm_dfs_segment_flag_reset(void *dm_void)61{62struct dm_struct *dm = (struct dm_struct *)dm_void;6364if (!(dm->support_ic_type & (ODM_RTL8814B)))65return;66if (dm->seg1_dfs_flag)67dm->seg1_dfs_flag = 0;68}6970void phydm_radar_detect_reset(void *dm_void)71{72struct dm_struct *dm = (struct dm_struct *)dm_void;7374if (dm->support_ic_type & (ODM_RTL8198F | ODM_RTL8822C | ODM_RTL8812F |75ODM_RTL8197G)) {76odm_set_bb_reg(dm, R_0xa40, BIT(15), 0);77odm_set_bb_reg(dm, R_0xa40, BIT(15), 1);78#if (RTL8721D_SUPPORT)79} else if (dm->support_ic_type & (ODM_RTL8721D)) {80odm_set_bb_reg(dm, R_0xf58, BIT(29), 0);81odm_set_bb_reg(dm, R_0xf58, BIT(29), 1);82#endif83} else if (dm->support_ic_type & (ODM_RTL8814B)) {84if (dm->seg1_dfs_flag == 1) {85odm_set_bb_reg(dm, R_0xa6c, BIT(0), 0);86odm_set_bb_reg(dm, R_0xa6c, BIT(0), 1);87return;88}89odm_set_bb_reg(dm, R_0xa40, BIT(15), 0);90odm_set_bb_reg(dm, R_0xa40, BIT(15), 1);91} else {92odm_set_bb_reg(dm, R_0x924, BIT(15), 0);93odm_set_bb_reg(dm, R_0x924, BIT(15), 1);94}95}9697void phydm_radar_detect_disable(void *dm_void)98{99struct dm_struct *dm = (struct dm_struct *)dm_void;100101if (dm->support_ic_type & (ODM_RTL8198F | ODM_RTL8822C | ODM_RTL8812F |102ODM_RTL8197G))103odm_set_bb_reg(dm, R_0xa40, BIT(15), 0);104else if (dm->support_ic_type & (ODM_RTL8814B)) {105if (dm->seg1_dfs_flag == 1) {106odm_set_bb_reg(dm, R_0xa6c, BIT(0), 0);107dm->seg1_dfs_flag = 0;108return;109}110odm_set_bb_reg(dm, R_0xa40, BIT(15), 0);111}112#if (RTL8721D_SUPPORT)113else if (dm->support_ic_type & (ODM_RTL8721D))114odm_set_bb_reg(dm, R_0xf58, BIT(29), 0);115#endif116else117odm_set_bb_reg(dm, R_0x924, BIT(15), 0);118119PHYDM_DBG(dm, DBG_DFS, "\n");120}121122static void phydm_radar_detect_with_dbg_parm(void *dm_void)123{124struct dm_struct *dm = (struct dm_struct *)dm_void;125126if (dm->support_ic_type & ODM_RTL8721D) {127odm_set_bb_reg(dm, R_0xf54, MASKDWORD,128dm->radar_detect_reg_f54);129odm_set_bb_reg(dm, R_0xf58, MASKDWORD,130dm->radar_detect_reg_f58);131odm_set_bb_reg(dm, R_0xf5c, MASKDWORD,132dm->radar_detect_reg_f5c);133odm_set_bb_reg(dm, R_0xf70, MASKDWORD,134dm->radar_detect_reg_f70);135odm_set_bb_reg(dm, R_0xf74, MASKDWORD,136dm->radar_detect_reg_f74);137} else if (dm->support_ic_type & ODM_IC_JGR3_SERIES) {138odm_set_bb_reg(dm, R_0xa40, MASKDWORD,139dm->radar_detect_reg_a40);140odm_set_bb_reg(dm, R_0xa44, MASKDWORD,141dm->radar_detect_reg_a44);142odm_set_bb_reg(dm, R_0xa48, MASKDWORD,143dm->radar_detect_reg_a48);144odm_set_bb_reg(dm, R_0xa4c, MASKDWORD,145dm->radar_detect_reg_a4c);146odm_set_bb_reg(dm, R_0xa50, MASKDWORD,147dm->radar_detect_reg_a50);148odm_set_bb_reg(dm, R_0xa54, MASKDWORD,149dm->radar_detect_reg_a54);150} else {151odm_set_bb_reg(dm, R_0x918, MASKDWORD,152dm->radar_detect_reg_918);153odm_set_bb_reg(dm, R_0x91c, MASKDWORD,154dm->radar_detect_reg_91c);155odm_set_bb_reg(dm, R_0x920, MASKDWORD,156dm->radar_detect_reg_920);157odm_set_bb_reg(dm, R_0x924, MASKDWORD,158dm->radar_detect_reg_924);159}160}161162/* @Init radar detection parameters, called after ch, bw is set */163164void phydm_radar_detect_enable(void *dm_void)165{166struct dm_struct *dm = (struct dm_struct *)dm_void;167struct _DFS_STATISTICS *dfs = &dm->dfs;168u8 region_domain = dm->dfs_region_domain;169u8 c_channel = *dm->channel;170u8 band_width = *dm->band_width;171u8 enable = 0, i;172u8 short_pw_upperbound = 0;173174PHYDM_DBG(dm, DBG_DFS, "test, region_domain = %d\n", region_domain);175if (region_domain == PHYDM_DFS_DOMAIN_UNKNOWN) {176PHYDM_DBG(dm, DBG_DFS, "PHYDM_DFS_DOMAIN_UNKNOWN\n");177goto exit;178}179180if (dm->support_ic_type & (ODM_RTL8821 | ODM_RTL8812 | ODM_RTL8881A)) {181odm_set_bb_reg(dm, R_0x814, 0x3fffffff, 0x04cc4d10);182odm_set_bb_reg(dm, R_0x834, MASKBYTE0, 0x06);183184if (dm->radar_detect_dbg_parm_en) {185phydm_radar_detect_with_dbg_parm(dm);186enable = 1;187goto exit;188}189190if (region_domain == PHYDM_DFS_DOMAIN_ETSI) {191odm_set_bb_reg(dm, R_0x918, MASKDWORD, 0x1c17ecdf);192odm_set_bb_reg(dm, R_0x924, MASKDWORD, 0x01528500);193odm_set_bb_reg(dm, R_0x91c, MASKDWORD, 0x0fa21a20);194odm_set_bb_reg(dm, R_0x920, MASKDWORD, 0xe0f69204);195196} else if (region_domain == PHYDM_DFS_DOMAIN_MKK) {197odm_set_bb_reg(dm, R_0x924, MASKDWORD, 0x01528500);198odm_set_bb_reg(dm, R_0x920, MASKDWORD, 0xe0d67234);199200if (c_channel >= 52 && c_channel <= 64) {201odm_set_bb_reg(dm, R_0x918, MASKDWORD,2020x1c16ecdf);203odm_set_bb_reg(dm, R_0x91c, MASKDWORD,2040x0f141a20);205} else {206odm_set_bb_reg(dm, R_0x918, MASKDWORD,2070x1c16acdf);208if (band_width == CHANNEL_WIDTH_20)209odm_set_bb_reg(dm, R_0x91c, MASKDWORD,2100x64721a20);211else212odm_set_bb_reg(dm, R_0x91c, MASKDWORD,2130x68721a20);214}215216} else if (region_domain == PHYDM_DFS_DOMAIN_FCC) {217odm_set_bb_reg(dm, R_0x918, MASKDWORD, 0x1c16acdf);218odm_set_bb_reg(dm, R_0x924, MASKDWORD, 0x01528500);219odm_set_bb_reg(dm, R_0x920, MASKDWORD, 0xe0d67231);220if (band_width == CHANNEL_WIDTH_20)221odm_set_bb_reg(dm, R_0x91c, MASKDWORD,2220x64741a20);223else224odm_set_bb_reg(dm, R_0x91c, MASKDWORD,2250x68741a20);226227} else {228/* not supported */229PHYDM_DBG(dm, DBG_DFS,230"Unsupported dfs_region_domain:%d\n",231region_domain);232goto exit;233}234235} else if (dm->support_ic_type &236(ODM_RTL8814A | ODM_RTL8822B | ODM_RTL8821C)) {237238odm_set_bb_reg(dm, R_0x814, 0x3fffffff, 0x04cc4d10);239odm_set_bb_reg(dm, R_0x834, MASKBYTE0, 0x06);240241/* @8822B only, when BW = 20M, DFIR output is 40Mhz,242* but DFS input is 80MMHz, so it need to upgrade to 80MHz243*/244if (dm->support_ic_type & (ODM_RTL8822B | ODM_RTL8821C)) {245if (band_width == CHANNEL_WIDTH_20)246odm_set_bb_reg(dm, R_0x1984, BIT(26), 1);247else248odm_set_bb_reg(dm, R_0x1984, BIT(26), 0);249}250251if (dm->radar_detect_dbg_parm_en) {252phydm_radar_detect_with_dbg_parm(dm);253enable = 1;254goto exit;255}256257if (region_domain == PHYDM_DFS_DOMAIN_ETSI) {258odm_set_bb_reg(dm, R_0x918, MASKDWORD, 0x1c16acdf);259odm_set_bb_reg(dm, R_0x924, MASKDWORD, 0x095a8500);260odm_set_bb_reg(dm, R_0x91c, MASKDWORD, 0x0fc01a1f);261odm_set_bb_reg(dm, R_0x920, MASKDWORD, 0xe0f57204);262263} else if (region_domain == PHYDM_DFS_DOMAIN_MKK) {264odm_set_bb_reg(dm, R_0x924, MASKDWORD, 0x095a8500);265odm_set_bb_reg(dm, R_0x920, MASKDWORD, 0xe0d67234);266267if (c_channel >= 52 && c_channel <= 64) {268odm_set_bb_reg(dm, R_0x918, MASKDWORD,2690x1c16ecdf);270odm_set_bb_reg(dm, R_0x91c, MASKDWORD,2710x0f141a1f);272} else {273odm_set_bb_reg(dm, R_0x918, MASKDWORD,2740x1c166cdf);275if (band_width == CHANNEL_WIDTH_20)276odm_set_bb_reg(dm, R_0x91c, MASKDWORD,2770x64721a1f);278else279odm_set_bb_reg(dm, R_0x91c, MASKDWORD,2800x68721a1f);281}282283} else if (region_domain == PHYDM_DFS_DOMAIN_FCC) {284odm_set_bb_reg(dm, R_0x918, MASKDWORD, 0x1c176cdf);285odm_set_bb_reg(dm, R_0x924, MASKDWORD, 0x095a8400);286odm_set_bb_reg(dm, R_0x920, MASKDWORD, 0xe076d231);287if (band_width == CHANNEL_WIDTH_20)288odm_set_bb_reg(dm, R_0x91c, MASKDWORD,2890x64901a1f);290else291odm_set_bb_reg(dm, R_0x91c, MASKDWORD,2920x62901a1f);293294} else {295/* not supported */296PHYDM_DBG(dm, DBG_DFS,297"Unsupported dfs_region_domain:%d\n",298region_domain);299goto exit;300}301/*RXHP low corner will extend the pulse width,302*so we need to increase the upper bound.303*/304if (dm->support_ic_type & (ODM_RTL8822B | ODM_RTL8821C)) {305if (odm_get_bb_reg(dm, 0x8d8,306BIT28 | BIT27 | BIT26) == 0) {307short_pw_upperbound =308(u8)odm_get_bb_reg(dm, 0x91c,309BIT23 | BIT22 |310BIT21 | BIT20);311if ((short_pw_upperbound + 4) > 15)312odm_set_bb_reg(dm, 0x91c,313BIT23 | BIT22 |314BIT21 | BIT20, 15);315else316odm_set_bb_reg(dm, 0x91c,317BIT23 | BIT22 |318BIT21 | BIT20,319short_pw_upperbound + 4);320}321/*@if peak index -1~+1, use original NB method*/322odm_set_bb_reg(dm, 0x19e4, 0x003C0000, 13);323odm_set_bb_reg(dm, 0x924, 0x70000, 0);324}325326if (dm->support_ic_type & (ODM_RTL8881A))327odm_set_bb_reg(dm, 0xb00, 0xc0000000, 3);328329/*@for 8814 new dfs mechanism setting*/330if (dm->support_ic_type &331(ODM_RTL8814A | ODM_RTL8822B | ODM_RTL8821C)) {332/*Turn off dfs scaling factor*/333odm_set_bb_reg(dm, 0x19e4, 0x1fff, 0x0c00);334/*NonDC peak_th = 2times DC peak_th*/335odm_set_bb_reg(dm, 0x19e4, 0x30000, 1);336/*power for debug and auto test flow latch after ST*/337odm_set_bb_reg(dm, 0x9f8, 0xc0000000, 3);338339/*@low pulse width radar pattern will cause wrong drop*/340/*@disable peak index should the same341*during the same short pulse (new mechan)342*/343odm_set_bb_reg(dm, 0x9f4, 0x80000000, 0);344345/*@disable peak index should the same346*during the same short pulse (old mechan)347*/348odm_set_bb_reg(dm, 0x924, 0x20000000, 0);349350/*@if peak index diff >=2, then drop the result*/351odm_set_bb_reg(dm, 0x19e4, 0xe000, 2);352if (region_domain == 2) {353if ((c_channel >= 52) && (c_channel <= 64)) {354/*pulse width hist th setting*/355/*th1=2*04us*/356odm_set_bb_reg(dm, 0x19e4,3570xff000000, 2);358/*th2 = 3*0.4us, th3 = 4*0.4us359*th4 = 7*0.4, th5 = 34*0.4360*/361odm_set_bb_reg(dm, 0x19e8,362MASKDWORD, 0x22070403);363364/*PRI hist th setting*/365/*th1=42*32us*/366odm_set_bb_reg(dm, 0x19b8,3670x00007f80, 42);368/*th2=47*32us, th3=115*32us,369*th4=123*32us, th5=130*32us370*/371odm_set_bb_reg(dm, 0x19ec,372MASKDWORD, 0x827b732f);373} else {374/*pulse width hist th setting*/375/*th1=2*04us*/376odm_set_bb_reg(dm, 0x19e4,3770xff000000, 1);378/*th2 = 13*0.4us, th3 = 26*0.4us379*th4 = 75*0.4us, th5 = 255*0.4us380*/381odm_set_bb_reg(dm, 0x19e8,382MASKDWORD, 0xff4b1a0d);383/*PRI hist th setting*/384/*th1=4*32us*/385386odm_set_bb_reg(dm, 0x19b8,3870x00007f80, 4);388/*th2=8*32us, th3=16*32us,389*th4=32*32us, th5=128*32=4096us390*/391odm_set_bb_reg(dm, 0x19ec,392MASKDWORD, 0x80201008);393}394}395/*@ETSI*/396else if (region_domain == 3) {397/*pulse width hist th setting*/398/*th1=2*04us*/399odm_set_bb_reg(dm, 0x19e4, 0xff000000, 1);400odm_set_bb_reg(dm, 0x19e8,401MASKDWORD, 0x68260d06);402/*PRI hist th setting*/403/*th1=7*32us*/404odm_set_bb_reg(dm, 0x19b8, 0x00007f80, 7);405/*th2=40*32us, th3=80*32us,406*th4=110*32us, th5=157*32=5024407*/408odm_set_bb_reg(dm, 0x19ec,409MASKDWORD, 0xc06e2010);410}411/*@FCC*/412else if (region_domain == 1) {413/*pulse width hist th setting*/414/*th1=2*04us*/415odm_set_bb_reg(dm, 0x19e4, 0xff000000, 2);416/*th2 = 13*0.4us, th3 = 26*0.4us,417*th4 = 75*0.4us, th5 = 255*0.4us418*/419odm_set_bb_reg(dm, 0x19e8,420MASKDWORD, 0xff4b1a0d);421422/*PRI hist th setting*/423/*th1=4*32us*/424odm_set_bb_reg(dm, 0x19b8, 0x00007f80, 4);425/*th2=8*32us, th3=21*32us,426*th4=32*32us, th5=96*32=3072427*/428if (band_width == CHANNEL_WIDTH_20)429odm_set_bb_reg(dm, 0x19ec,430MASKDWORD, 0x60282010);431else432odm_set_bb_reg(dm, 0x19ec,433MASKDWORD, 0x60282420);434} else {435}436}437} else if (dm->support_ic_type &438ODM_IC_JGR3_SERIES) {439if (dm->radar_detect_dbg_parm_en) {440phydm_radar_detect_with_dbg_parm(dm);441enable = 1;442goto exit;443}444if (region_domain == PHYDM_DFS_DOMAIN_ETSI) {445odm_set_bb_reg(dm, R_0xa40, MASKDWORD, 0xb359c5bd);446if (dm->support_ic_type & (ODM_RTL8814B)) {447if (dm->seg1_dfs_flag == 1)448odm_set_bb_reg(dm, R_0xa6c, BIT(0), 1);449}450odm_set_bb_reg(dm, R_0xa44, MASKDWORD, 0x3033bebd);451odm_set_bb_reg(dm, R_0xa48, MASKDWORD, 0x2a521254);452odm_set_bb_reg(dm, R_0xa4c, MASKDWORD, 0xa2533345);453odm_set_bb_reg(dm, R_0xa50, MASKDWORD, 0x605be003);454odm_set_bb_reg(dm, R_0xa54, MASKDWORD, 0x500089e8);455} else if (region_domain == PHYDM_DFS_DOMAIN_MKK) {456odm_set_bb_reg(dm, R_0xa40, MASKDWORD, 0xb359c5bd);457if (dm->support_ic_type & (ODM_RTL8814B)) {458if (dm->seg1_dfs_flag == 1)459odm_set_bb_reg(dm, R_0xa6c, BIT(0), 1);460}461odm_set_bb_reg(dm, R_0xa44, MASKDWORD, 0x3033bebd);462odm_set_bb_reg(dm, R_0xa48, MASKDWORD, 0x2a521254);463odm_set_bb_reg(dm, R_0xa4c, MASKDWORD, 0xa2533345);464odm_set_bb_reg(dm, R_0xa50, MASKDWORD, 0x605be003);465odm_set_bb_reg(dm, R_0xa54, MASKDWORD, 0x500089e8);466} else if (region_domain == PHYDM_DFS_DOMAIN_FCC) {467odm_set_bb_reg(dm, R_0xa40, MASKDWORD, 0xb359c5bd);468if (dm->support_ic_type & (ODM_RTL8814B)) {469if (dm->seg1_dfs_flag == 1)470odm_set_bb_reg(dm, R_0xa6c, BIT(0), 1);471}472odm_set_bb_reg(dm, R_0xa44, MASKDWORD, 0x3033bebd);473odm_set_bb_reg(dm, R_0xa48, MASKDWORD, 0x2a521254);474odm_set_bb_reg(dm, R_0xa4c, MASKDWORD, 0xa2533345);475odm_set_bb_reg(dm, R_0xa50, MASKDWORD, 0x605be003);476odm_set_bb_reg(dm, R_0xa54, MASKDWORD, 0x500089e8);477} else {478/* not supported */479PHYDM_DBG(dm, DBG_DFS,480"Unsupported dfs_region_domain:%d\n",481region_domain);482goto exit;483}484#if (RTL8721D_SUPPORT)485} else if (dm->support_ic_type & ODM_RTL8721D) {486odm_set_bb_reg(dm, R_0x814, 0x3fffffff, 0x04cc4d10);487/*CCA MASK*/488odm_set_bb_reg(dm, R_0xc38, 0x07c00000, 0x06);489/*CCA Threshold*/490odm_set_bb_reg(dm, R_0xc3c, 0x00000007, 0x0);491492if (dm->radar_detect_dbg_parm_en) {493phydm_radar_detect_with_dbg_parm(dm);494enable = 1;495goto exit;496}497498if (region_domain == PHYDM_DFS_DOMAIN_ETSI) {499odm_set_bb_reg(dm, R_0xf54, MASKDWORD, 0x230006a8);500odm_set_bb_reg(dm, R_0xf58, MASKDWORD, 0x354cd7dd);501odm_set_bb_reg(dm, R_0xf5c, MASKDWORD, 0x9984ab25);502odm_set_bb_reg(dm, R_0xf70, MASKDWORD, 0xbd9fab98);503odm_set_bb_reg(dm, R_0xf74, MASKDWORD, 0xcc45029f);504505} else if (region_domain == PHYDM_DFS_DOMAIN_MKK) {506odm_set_bb_reg(dm, R_0xf54, MASKDWORD, 0x230006a8);507odm_set_bb_reg(dm, R_0xf5c, MASKDWORD, 0x9984ab25);508odm_set_bb_reg(dm, R_0xf70, MASKDWORD, 0xbd9fb398);509odm_set_bb_reg(dm, R_0xf74, MASKDWORD, 0xcc450e9d);510511if (c_channel >= 52 && c_channel <= 64) {512odm_set_bb_reg(dm, R_0xf58, MASKDWORD,5130x354cd7fd);514} else {515odm_set_bb_reg(dm, R_0xf58, MASKDWORD,5160x354cd7bd);517}518} else if (region_domain == PHYDM_DFS_DOMAIN_FCC) {519odm_set_bb_reg(dm, R_0xf54, MASKDWORD, 0x230006a8);520odm_set_bb_reg(dm, R_0xf58, MASKDWORD, 0x3558d7bd);521odm_set_bb_reg(dm, R_0xf5c, MASKDWORD, 0x9984ab35);522odm_set_bb_reg(dm, R_0xf70, MASKDWORD, 0xbd9fb398);523odm_set_bb_reg(dm, R_0xf74, MASKDWORD, 0xcc444e9d);524} else {525/* not supported */526PHYDM_DBG(dm, DBG_DFS,527"Unsupported dfs_region_domain:%d\n",528region_domain);529goto exit;530}531532/*if peak index -1~+1, use original NB method*/533odm_set_bb_reg(dm, R_0xf70, 0x00070000, 0x7);534odm_set_bb_reg(dm, R_0xf74, 0x000c0000, 0);535536/*Turn off dfs scaling factor*/537odm_set_bb_reg(dm, R_0xf70, 0x00080000, 0x0);538/*NonDC peak_th = 2times DC peak_th*/539odm_set_bb_reg(dm, R_0xf58, 0x00007800, 1);540541/*low pulse width radar pattern will cause wrong drop*/542/*disable peak index should the same*/543/*during the same short pulse (new mechan)*/544odm_set_bb_reg(dm, R_0xf70, 0x00100000, 0x0);545/*if peak index diff >=2, then drop the result*/546odm_set_bb_reg(dm, R_0xf70, 0x30000000, 0x2);547#endif548} else {549/*not supported IC type*/550PHYDM_DBG(dm, DBG_DFS, "Unsupported IC type:%d\n",551dm->support_ic_type);552goto exit;553}554555enable = 1;556557if (dm->support_ic_type & ODM_IC_JGR3_SERIES) {558dfs->st_l2h_cur = (u8)odm_get_bb_reg(dm, R_0xa40, 0x00007f00);559dfs->pwdb_th_cur = (u8)odm_get_bb_reg(dm, R_0xa50, 0x000000f0);560dfs->peak_th = (u8)odm_get_bb_reg(dm, R_0xa48, 0x00c00000);561dfs->short_pulse_cnt_th = (u8)odm_get_bb_reg(dm, R_0xa50,5620x00f00000);563dfs->long_pulse_cnt_th = (u8)odm_get_bb_reg(dm, R_0xa4c,5640xf0000000);565dfs->peak_window = (u8)odm_get_bb_reg(dm, R_0xa40, 0x00030000);566dfs->three_peak_opt = (u8)odm_get_bb_reg(dm, R_0xa40,5670x30000000);568dfs->three_peak_th2 = (u8)odm_get_bb_reg(dm, R_0xa44,5690x00000007);570#if (RTL8721D_SUPPORT)571} else if (dm->support_ic_type & (ODM_RTL8721D)) {572dfs->st_l2h_cur = (u8)odm_get_bb_reg(dm, R_0xf54,5730x0000001f) << 2);574dfs->st_l2h_cur += (u8)odm_get_bb_reg(dm, R_0xf58, 0xc0000000);575dfs->pwdb_th_cur = (u8)odm_get_bb_reg(dm, R_0xf70, 0x03c00000);576dfs->peak_th = (u8)odm_get_bb_reg(dm, R_0xf5c, 0x00000030);577dfs->short_pulse_cnt_th = (u8)odm_get_bb_reg(dm, R_0xf70,5780x00007800);579dfs->long_pulse_cnt_th = (u8)odm_get_bb_reg(dm, R_0xf74,5800x0000000f);581dfs->peak_window = (u8)odm_get_bb_reg(dm, R_0xf58, 0x18000000);582dfs->three_peak_opt = (u8)odm_get_bb_reg(dm, R_0xf58,5830x00030000);584dfs->three_peak_th2 = (u8)odm_get_bb_reg(dm,585R_0xf58, 0x00007c00);586#endif587} else {588dfs->st_l2h_cur = (u8)odm_get_bb_reg(dm, R_0x91c, 0x000000ff);589dfs->pwdb_th_cur = (u8)odm_get_bb_reg(dm, R_0x918, 0x00001f00);590dfs->peak_th = (u8)odm_get_bb_reg(dm, R_0x918, 0x00030000);591dfs->short_pulse_cnt_th = (u8)odm_get_bb_reg(dm, R_0x920,5920x000f0000);593dfs->long_pulse_cnt_th = (u8)odm_get_bb_reg(dm, R_0x920,5940x00f00000);595dfs->peak_window = (u8)odm_get_bb_reg(dm, R_0x920, 0x00000300);596dfs->three_peak_opt = (u8)odm_get_bb_reg(dm, 0x924, 0x00000180);597dfs->three_peak_th2 = (u8)odm_get_bb_reg(dm, 0x924, 0x00007000);598}599600phydm_dfs_parameter_init(dm);601602exit:603if (enable) {604phydm_radar_detect_reset(dm);605PHYDM_DBG(dm, DBG_DFS, "on cch:%u, bw:%u\n", c_channel,606band_width);607} else608phydm_radar_detect_disable(dm);609}610611void phydm_dfs_parameter_init(void *dm_void)612{613struct dm_struct *dm = (struct dm_struct *)dm_void;614struct _DFS_STATISTICS *dfs = &dm->dfs;615616u8 i;617for (i = 0; i < 5; i++) {618dfs->pulse_flag_hist[i] = 0;619dfs->pulse_type_hist[i] = 0;620dfs->radar_det_mask_hist[i] = 0;621dfs->fa_inc_hist[i] = 0;622}623624/*@for dfs mode*/625dfs->force_TP_mode = 0;626dfs->sw_trigger_mode = 0;627dfs->det_print = 0;628dfs->det_print2 = 0;629dfs->print_hist_rpt = 0;630if (dm->support_ic_type & (ODM_RTL8814A | ODM_RTL8822B | ODM_RTL8821C))631dfs->hist_cond_on = 1;632else633dfs->hist_cond_on = 0;634635/*@for dynamic dfs*/636dfs->pwdb_th = 8;637dfs->fa_mask_th = 30 * (dfs->dfs_polling_time / 100);638dfs->st_l2h_min = 0x20;639dfs->st_l2h_max = 0x4e;640dfs->pwdb_scalar_factor = 12;641642/*@for dfs histogram*/643dfs->pri_hist_th = 5;644dfs->pri_sum_g1_th = 9;645dfs->pri_sum_g5_th = 5;646dfs->pri_sum_g1_fcc_th = 4; /*@FCC Type6*/647dfs->pri_sum_g3_fcc_th = 6;648dfs->pri_sum_safe_th = 50;649dfs->pri_sum_safe_fcc_th = 110; /*@30 for AP*/650dfs->pri_sum_type4_th = 16;651dfs->pri_sum_type6_th = 12;652dfs->pri_sum_g5_under_g1_th = 4;653dfs->pri_pw_diff_th = 4;654dfs->pri_pw_diff_fcc_th = 8;655dfs->pri_pw_diff_fcc_idle_th = 2;656dfs->pri_pw_diff_w53_th = 10;657dfs->pw_std_th = 7; /*@FCC Type4*/658dfs->pw_std_idle_th = 10;659dfs->pri_std_th = 6; /*@FCC Type3,4,6*/660dfs->pri_std_idle_th = 10;661dfs->pri_type1_upp_fcc_th = 110;662dfs->pri_type1_low_fcc_th = 50;663dfs->pri_type1_cen_fcc_th = 70;664dfs->pw_g0_th = 8;665dfs->pw_long_lower_th = 6; /*@7->6*/666dfs->pri_long_upper_th = 30;667dfs->pw_long_lower_20m_th = 7; /*@7 for AP*/668dfs->pw_long_sum_upper_th = 60;669dfs->type4_pw_max_cnt = 7;670dfs->type4_safe_pri_sum_th = 5;671}672673void phydm_dfs_dynamic_setting(674void *dm_void)675{676struct dm_struct *dm = (struct dm_struct *)dm_void;677struct _DFS_STATISTICS *dfs = &dm->dfs;678679u8 peak_th_cur = 0, short_pulse_cnt_th_cur = 0;680u8 long_pulse_cnt_th_cur = 0, three_peak_opt_cur = 0;681u8 three_peak_th2_cur = 0;682u8 peak_window_cur = 0;683u8 region_domain = dm->dfs_region_domain;684u8 c_channel = *dm->channel;685686if (dm->rx_tp + dm->tx_tp <= 2) {687dfs->idle_mode = 1;688if (dfs->force_TP_mode)689dfs->idle_mode = 0;690} else {691dfs->idle_mode = 0;692}693694if (dfs->idle_mode == 1) { /*@idle (no traffic)*/695peak_th_cur = 3;696short_pulse_cnt_th_cur = 6;697long_pulse_cnt_th_cur = 9;698peak_window_cur = 2;699three_peak_opt_cur = 0;700three_peak_th2_cur = 2;701if (region_domain == PHYDM_DFS_DOMAIN_MKK) {702if (c_channel >= 52 && c_channel <= 64) {703short_pulse_cnt_th_cur = 14;704long_pulse_cnt_th_cur = 15;705three_peak_th2_cur = 0;706} else {707short_pulse_cnt_th_cur = 6;708three_peak_th2_cur = 0;709long_pulse_cnt_th_cur = 10;710}711} else if (region_domain == PHYDM_DFS_DOMAIN_FCC) {712three_peak_th2_cur = 0;713} else if (region_domain == PHYDM_DFS_DOMAIN_ETSI) {714long_pulse_cnt_th_cur = 15;715if (phydm_dfs_is_meteorology_channel(dm)) {716/*need to add check cac end condition*/717peak_th_cur = 2;718three_peak_opt_cur = 0;719three_peak_th2_cur = 0;720short_pulse_cnt_th_cur = 7;721} else {722three_peak_opt_cur = 0;723three_peak_th2_cur = 0;724short_pulse_cnt_th_cur = 7;725}726} else /*@default: FCC*/727three_peak_th2_cur = 0;728729} else { /*@in service (with TP)*/730peak_th_cur = 2;731short_pulse_cnt_th_cur = 6;732long_pulse_cnt_th_cur = 7;733peak_window_cur = 2;734three_peak_opt_cur = 0;735three_peak_th2_cur = 2;736if (region_domain == PHYDM_DFS_DOMAIN_MKK) {737if (c_channel >= 52 && c_channel <= 64) {738long_pulse_cnt_th_cur = 15;739/*@for high duty cycle*/740short_pulse_cnt_th_cur = 5;741three_peak_th2_cur = 0;742} else {743three_peak_opt_cur = 0;744three_peak_th2_cur = 0;745long_pulse_cnt_th_cur = 8;746}747} else if (region_domain == PHYDM_DFS_DOMAIN_FCC) {748long_pulse_cnt_th_cur = 5; /*for 80M FCC*/749short_pulse_cnt_th_cur = 5; /*for 80M FCC*/750} else if (region_domain == PHYDM_DFS_DOMAIN_ETSI) {751long_pulse_cnt_th_cur = 15;752short_pulse_cnt_th_cur = 5;753three_peak_opt_cur = 0;754}755}756757if (dm->support_ic_type & ODM_IC_JGR3_SERIES) {758if (dfs->peak_th != peak_th_cur)759odm_set_bb_reg(dm, R_0xa48, 0x00c00000, peak_th_cur);760if (dfs->short_pulse_cnt_th != short_pulse_cnt_th_cur)761odm_set_bb_reg(dm, R_0xa50, 0x00f00000,762short_pulse_cnt_th_cur);763if (dfs->long_pulse_cnt_th != long_pulse_cnt_th_cur)764odm_set_bb_reg(dm, R_0xa4c, 0xf0000000,765long_pulse_cnt_th_cur);766if (dfs->peak_window != peak_window_cur)767odm_set_bb_reg(dm, R_0xa40, 0x00030000,768peak_window_cur);769if (dfs->three_peak_opt != three_peak_opt_cur)770odm_set_bb_reg(dm, R_0xa40, 0x30000000,771three_peak_opt_cur);772if (dfs->three_peak_th2 != three_peak_th2_cur)773odm_set_bb_reg(dm, R_0xa44, 0x00000007,774three_peak_th2_cur);775#if (RTL8721D_SUPPORT)776} else if (dm->support_ic_type & (ODM_RTL8721D)) {777if (dfs->peak_th != peak_th_cur)778odm_set_bb_reg(dm, R_0xf5c, 0x00000030, peak_th_cur);779if (dfs->short_pulse_cnt_th != short_pulse_cnt_th_cur)780odm_set_bb_reg(dm, R_0xf70, 0x00007800,781short_pulse_cnt_th_cur);782if (dfs->long_pulse_cnt_th != long_pulse_cnt_th_cur)783odm_set_bb_reg(dm, R_0xf74, 0x0000000f,784long_pulse_cnt_th_cur);785if (dfs->peak_window != peak_window_cur)786odm_set_bb_reg(dm, R_0xf58, 0x18000000,787peak_window_cur);788if (dfs->three_peak_opt != three_peak_opt_cur)789odm_set_bb_reg(dm, R_0xf58, 0x00030000,790three_peak_opt_cur);791if (dfs->three_peak_th2 != three_peak_th2_cur)792odm_set_bb_reg(dm, R_0xf58, 0x00007c00,793three_peak_th2_cur);794#endif795} else {796if (dfs->peak_th != peak_th_cur)797odm_set_bb_reg(dm, R_0x918, 0x00030000, peak_th_cur);798if (dfs->short_pulse_cnt_th != short_pulse_cnt_th_cur)799odm_set_bb_reg(dm, R_0x920, 0x000f0000,800short_pulse_cnt_th_cur);801if (dfs->long_pulse_cnt_th != long_pulse_cnt_th_cur)802odm_set_bb_reg(dm, R_0x920, 0x00f00000,803long_pulse_cnt_th_cur);804if (dfs->peak_window != peak_window_cur)805odm_set_bb_reg(dm, R_0x920, 0x00000300,806peak_window_cur);807if (dfs->three_peak_opt != three_peak_opt_cur)808odm_set_bb_reg(dm, R_0x924, 0x00000180,809three_peak_opt_cur);810if (dfs->three_peak_th2 != three_peak_th2_cur)811odm_set_bb_reg(dm, R_0x924, 0x00007000,812three_peak_th2_cur);813}814815dfs->peak_th = peak_th_cur;816dfs->short_pulse_cnt_th = short_pulse_cnt_th_cur;817dfs->long_pulse_cnt_th = long_pulse_cnt_th_cur;818dfs->peak_window = peak_window_cur;819dfs->three_peak_opt = three_peak_opt_cur;820dfs->three_peak_th2 = three_peak_th2_cur;821}822823boolean824phydm_radar_detect_dm_check(825void *dm_void)826{827struct dm_struct *dm = (struct dm_struct *)dm_void;828struct _DFS_STATISTICS *dfs = &dm->dfs;829u8 region_domain = dm->dfs_region_domain, index = 0;830831u16 i = 0, j = 0, k = 0, fa_count_cur = 0, fa_count_inc = 0;832u16 total_fa_in_hist = 0, pre_post_now_acc_fa_in_hist = 0;833u16 max_fa_in_hist = 0, vht_crc_ok_cnt_cur = 0;834u16 vht_crc_ok_cnt_inc = 0, ht_crc_ok_cnt_cur = 0;835u16 ht_crc_ok_cnt_inc = 0, leg_crc_ok_cnt_cur = 0;836u16 leg_crc_ok_cnt_inc = 0;837u16 total_crc_ok_cnt_inc = 0, short_pulse_cnt_cur = 0;838u16 short_pulse_cnt_inc = 0, long_pulse_cnt_cur = 0;839u16 long_pulse_cnt_inc = 0, total_pulse_count_inc = 0;840u32 regf98_value = 0, reg918_value = 0, reg91c_value = 0;841u32 reg920_value = 0, reg924_value = 0, radar_rpt_reg_value = 0;842u32 regf54_value = 0, regf58_value = 0, regf5c_value = 0;843u32 regdf4_value = 0, regf70_value = 0, regf74_value = 0;844u32 rega40_value = 0, rega44_value = 0, rega48_value = 0;845u32 rega4c_value = 0, rega50_value = 0, rega54_value = 0;846#if (RTL8721D_SUPPORT)847u32 reg908_value = 0, regdf4_value = 0;848u32 regf54_value = 0, regf58_value = 0, regf5c_value = 0;849u32 regf70_value = 0, regf74_value = 0;850#endif851boolean tri_short_pulse = 0, tri_long_pulse = 0, radar_type = 0;852boolean fault_flag_det = 0, fault_flag_psd = 0, fa_flag = 0;853boolean radar_detected = 0;854u8 st_l2h_new = 0, fa_mask_th = 0, sum = 0;855u8 c_channel = *dm->channel;856857/*@Get FA count during past 100ms, R_0xf48 for AC series*/858if (dm->support_ic_type & ODM_IC_JGR3_SERIES)859fa_count_cur = (u16)odm_get_bb_reg(dm, R_0x2d00, MASKLWORD);860#if (RTL8721D_SUPPORT)861else if (dm->support_ic_type & (ODM_RTL8721D)) {862fa_count_cur = (u16)odm_get_bb_reg(dm,863ODM_REG_OFDM_FA_TYPE2_11N,864MASKHWORD);865fa_count_cur += (u16)odm_get_bb_reg(dm,866ODM_REG_OFDM_FA_TYPE3_11N,867MASKLWORD);868fa_count_cur += (u16)odm_get_bb_reg(dm,869ODM_REG_OFDM_FA_TYPE3_11N,870MASKHWORD);871fa_count_cur += (u16)odm_get_bb_reg(dm,872ODM_REG_OFDM_FA_TYPE4_11N,873MASKLWORD);874fa_count_cur += (u16)odm_get_bb_reg(dm,875ODM_REG_OFDM_FA_TYPE1_11N,876MASKLWORD);877fa_count_cur += (u16)odm_get_bb_reg(dm,878ODM_REG_OFDM_FA_TYPE1_11N,879MASKHWORD);880}881#endif882else883fa_count_cur = (u16)odm_get_bb_reg(dm, R_0xf48, 0x0000ffff);884885if (dfs->fa_count_pre == 0)886fa_count_inc = 0;887else if (fa_count_cur >= dfs->fa_count_pre)888fa_count_inc = fa_count_cur - dfs->fa_count_pre;889else890fa_count_inc = fa_count_cur;891dfs->fa_count_pre = fa_count_cur;892893dfs->fa_inc_hist[dfs->mask_idx] = fa_count_inc;894895for (i = 0; i < 5; i++) {896total_fa_in_hist = total_fa_in_hist + dfs->fa_inc_hist[i];897if (dfs->fa_inc_hist[i] > max_fa_in_hist)898max_fa_in_hist = dfs->fa_inc_hist[i];899}900if (dfs->mask_idx >= 2)901index = dfs->mask_idx - 2;902else903index = 5 + dfs->mask_idx - 2;904if (index == 0) {905pre_post_now_acc_fa_in_hist = dfs->fa_inc_hist[index] +906dfs->fa_inc_hist[index + 1] +907dfs->fa_inc_hist[4];908} else if (index == 4) {909pre_post_now_acc_fa_in_hist = dfs->fa_inc_hist[index] +910dfs->fa_inc_hist[0] +911dfs->fa_inc_hist[index - 1];912} else {913pre_post_now_acc_fa_in_hist = dfs->fa_inc_hist[index] +914dfs->fa_inc_hist[index + 1] +915dfs->fa_inc_hist[index - 1];916}917918/*@Get VHT CRC32 ok count during past 100ms*/919if (dm->support_ic_type & ODM_IC_JGR3_SERIES)920vht_crc_ok_cnt_cur = (u16)odm_get_bb_reg(dm, R_0x2c0c, 0xffff);921#if (RTL8721D_SUPPORT)922else if (dm->support_ic_type & ODM_RTL8721D)923vht_crc_ok_cnt_cur = 0;924#endif925else926vht_crc_ok_cnt_cur = (u16)odm_get_bb_reg(dm, R_0xf0c,9270x00003fff);928929if (vht_crc_ok_cnt_cur >= dfs->vht_crc_ok_cnt_pre) {930vht_crc_ok_cnt_inc = vht_crc_ok_cnt_cur -931dfs->vht_crc_ok_cnt_pre;932} else {933vht_crc_ok_cnt_inc = vht_crc_ok_cnt_cur;934}935dfs->vht_crc_ok_cnt_pre = vht_crc_ok_cnt_cur;936937/*@Get HT CRC32 ok count during past 100ms*/938if (dm->support_ic_type & ODM_IC_JGR3_SERIES)939ht_crc_ok_cnt_cur = (u16)odm_get_bb_reg(dm, R_0x2c10, 0xffff);940#if (RTL8721D_SUPPORT)941else if (dm->support_ic_type & (ODM_RTL8721D))942ht_crc_ok_cnt_cur = (u16)odm_get_bb_reg(dm, R_0xf90, MASKLWORD);943#endif944else945ht_crc_ok_cnt_cur = (u16)odm_get_bb_reg(dm, R_0xf10,9460x00003fff);947948if (ht_crc_ok_cnt_cur >= dfs->ht_crc_ok_cnt_pre)949ht_crc_ok_cnt_inc = ht_crc_ok_cnt_cur - dfs->ht_crc_ok_cnt_pre;950else951ht_crc_ok_cnt_inc = ht_crc_ok_cnt_cur;952dfs->ht_crc_ok_cnt_pre = ht_crc_ok_cnt_cur;953954/*@Get Legacy CRC32 ok count during past 100ms*/955if (dm->support_ic_type & ODM_IC_JGR3_SERIES)956leg_crc_ok_cnt_cur = (u16)odm_get_bb_reg(dm, R_0x2c14, 0xffff);957#if (RTL8721D_SUPPORT)958else if (dm->support_ic_type & ODM_RTL8721D)959leg_crc_ok_cnt_cur = (u16)odm_get_bb_reg(dm,960R_0xf94, MASKLWORD);961#endif962else963leg_crc_ok_cnt_cur = (u16)odm_get_bb_reg(dm, R_0xf14,9640x00003fff);965966if (leg_crc_ok_cnt_cur >= dfs->leg_crc_ok_cnt_pre)967leg_crc_ok_cnt_inc = leg_crc_ok_cnt_cur - dfs->leg_crc_ok_cnt_pre;968else969leg_crc_ok_cnt_inc = leg_crc_ok_cnt_cur;970dfs->leg_crc_ok_cnt_pre = leg_crc_ok_cnt_cur;971972if (dm->support_ic_type & ODM_IC_JGR3_SERIES) {973if (vht_crc_ok_cnt_cur == 0xffff ||974ht_crc_ok_cnt_cur == 0xffff ||975leg_crc_ok_cnt_cur == 0xffff) {976phydm_reset_bb_hw_cnt(dm);977}978#if (RTL8721D_SUPPORT)979} else if (dm->support_ic_type & (ODM_RTL8721D)) {980if (ht_crc_ok_cnt_cur == 0xffff ||981leg_crc_ok_cnt_cur == 0xffff) {982odm_set_bb_reg(dm, R_0xf14, BIT(16), 1);983odm_set_bb_reg(dm, R_0xf14, BIT(16), 0);984}985#endif986} else {987if (vht_crc_ok_cnt_cur == 0x3fff ||988ht_crc_ok_cnt_cur == 0x3fff ||989leg_crc_ok_cnt_cur == 0x3fff) {990phydm_reset_bb_hw_cnt(dm);991}992}993994total_crc_ok_cnt_inc = vht_crc_ok_cnt_inc +995ht_crc_ok_cnt_inc +996leg_crc_ok_cnt_inc;997998if (dm->support_ic_type & (ODM_RTL8198F | ODM_RTL8822C | ODM_RTL8812F |999ODM_RTL8197G)) {1000/* if (phydm_set_bb_dbg_port(dm, DBGPORT_PRI_2, 0x3b0)) {1001* odm_set_bb_reg(dm, 0x1e28, 0x03c00000, 8);1002* dbgport2dbc_value = phydm_get_bb_dbg_port_val(dm);1003* phydm_release_bb_dbg_port(dm); }1004*/1005radar_rpt_reg_value = odm_get_bb_reg(dm, R_0x2e00, 0xffffffff);1006short_pulse_cnt_cur = (u16)((radar_rpt_reg_value & 0x000ff800)1007>> 11);1008long_pulse_cnt_cur = (u16)((radar_rpt_reg_value & 0x0fc00000)1009>> 22);1010#if (RTL8721D_SUPPORT)1011} else if (dm->support_ic_type & (ODM_RTL8721D)) {1012reg908_value = (u32)odm_get_bb_reg(dm, R_0x908, MASKDWORD);1013odm_set_bb_reg(dm, R_0x908, MASKDWORD, 0x254);1014regdf4_value = odm_get_bb_reg(dm, R_0xdf4, MASKDWORD);1015short_pulse_cnt_cur = (u16)((regdf4_value & 0x000ff000) >> 12);1016long_pulse_cnt_cur = (u16)((regdf4_value & 0x0fc00000) >> 22);10171018tri_short_pulse = (regdf4_value & BIT(20)) ? 1 : 0;1019tri_long_pulse = (regdf4_value & BIT(28)) ? 1 : 0;1020if (tri_short_pulse || tri_long_pulse) {1021odm_set_bb_reg(dm, R_0xf58, BIT(29), 0);1022odm_set_bb_reg(dm, R_0xf58, BIT(29), 1);1023}1024#endif1025} else if (dm->support_ic_type & (ODM_RTL8814B)) {1026if (dm->seg1_dfs_flag == 1)1027radar_rpt_reg_value = odm_get_bb_reg(dm, R_0x2e20,10280xffffffff);1029else1030radar_rpt_reg_value = odm_get_bb_reg(dm, R_0x2e00,10310xffffffff);1032short_pulse_cnt_cur = (u16)((radar_rpt_reg_value & 0x000ff800)1033>> 11);1034long_pulse_cnt_cur = (u16)((radar_rpt_reg_value & 0x0fc00000)1035>> 22);1036} else {1037regf98_value = odm_get_bb_reg(dm, R_0xf98, 0xffffffff);1038short_pulse_cnt_cur = (u16)(regf98_value & 0x000000ff);1039long_pulse_cnt_cur = (u16)((regf98_value & 0x0000ff00) >> 8);1040}10411042/*@Get short pulse count, need carefully handle the counter overflow*/10431044if (short_pulse_cnt_cur >= dfs->short_pulse_cnt_pre) {1045short_pulse_cnt_inc = short_pulse_cnt_cur -1046dfs->short_pulse_cnt_pre;1047} else {1048short_pulse_cnt_inc = short_pulse_cnt_cur;1049}1050dfs->short_pulse_cnt_pre = short_pulse_cnt_cur;10511052/*@Get long pulse count, need carefully handle the counter overflow*/10531054if (long_pulse_cnt_cur >= dfs->long_pulse_cnt_pre) {1055long_pulse_cnt_inc = long_pulse_cnt_cur -1056dfs->long_pulse_cnt_pre;1057} else {1058long_pulse_cnt_inc = long_pulse_cnt_cur;1059}1060dfs->long_pulse_cnt_pre = long_pulse_cnt_cur;10611062total_pulse_count_inc = short_pulse_cnt_inc + long_pulse_cnt_inc;10631064if (dfs->det_print) {1065PHYDM_DBG(dm, DBG_DFS,1066"===============================================\n");1067PHYDM_DBG(dm, DBG_DFS,1068"Total_CRC_OK_cnt_inc[%d] VHT_CRC_ok_cnt_inc[%d] HT_CRC_ok_cnt_inc[%d] LEG_CRC_ok_cnt_inc[%d] FA_count_inc[%d]\n",1069total_crc_ok_cnt_inc, vht_crc_ok_cnt_inc,1070ht_crc_ok_cnt_inc, leg_crc_ok_cnt_inc, fa_count_inc);1071if (dm->support_ic_type & (ODM_RTL8721D)) {1072PHYDM_DBG(dm, DBG_DFS,1073"Init_Gain[%x] st_l2h_cur[%x] 0xdf4[%08x] short_pulse_cnt_inc[%d] long_pulse_cnt_inc[%d]\n",1074dfs->igi_cur, dfs->st_l2h_cur, regdf4_value,1075short_pulse_cnt_inc, long_pulse_cnt_inc);1076regf54_value = odm_get_bb_reg(dm, R_0xf54, MASKDWORD);1077regf58_value = odm_get_bb_reg(dm, R_0xf58, MASKDWORD);1078regf5c_value = odm_get_bb_reg(dm, R_0xf5c, MASKDWORD);1079regf70_value = odm_get_bb_reg(dm, R_0xf70, MASKDWORD);1080regf74_value = odm_get_bb_reg(dm, R_0xf74, MASKDWORD);1081PHYDM_DBG(dm, DBG_DFS,1082"0xf54[%08x] 0xf58[%08x] 0xf5c[%08x] 0xf70[%08x] 0xf74[%08x]\n",1083regf54_value, regf58_value, regf5c_value,1084regf70_value, regf74_value);1085} else if (dm->support_ic_type & ODM_IC_JGR3_SERIES) {1086PHYDM_DBG(dm, DBG_DFS,1087"Init_Gain[%x] st_l2h_cur[%x] 0x2dbc[%08x] short_pulse_cnt_inc[%d] long_pulse_cnt_inc[%d]\n",1088dfs->igi_cur, dfs->st_l2h_cur,1089radar_rpt_reg_value, short_pulse_cnt_inc,1090long_pulse_cnt_inc);1091rega40_value = odm_get_bb_reg(dm, R_0xa40, MASKDWORD);1092rega44_value = odm_get_bb_reg(dm, R_0xa44, MASKDWORD);1093rega48_value = odm_get_bb_reg(dm, R_0xa48, MASKDWORD);1094rega4c_value = odm_get_bb_reg(dm, R_0xa4c, MASKDWORD);1095rega50_value = odm_get_bb_reg(dm, R_0xa50, MASKDWORD);1096rega54_value = odm_get_bb_reg(dm, R_0xa54, MASKDWORD);1097PHYDM_DBG(dm, DBG_DFS,1098"0xa40[%08x] 0xa44[%08x] 0xa48[%08x] 0xa4c[%08x] 0xa50[%08x] 0xa54[%08x]\n",1099rega40_value, rega44_value, rega48_value,1100rega4c_value, rega50_value, rega54_value);1101} else {1102PHYDM_DBG(dm, DBG_DFS,1103"Init_Gain[%x] 0x91c[%x] 0xf98[%08x] short_pulse_cnt_inc[%d] long_pulse_cnt_inc[%d]\n",1104dfs->igi_cur, dfs->st_l2h_cur, regf98_value,1105short_pulse_cnt_inc, long_pulse_cnt_inc);1106reg918_value = odm_get_bb_reg(dm, R_0x918,11070xffffffff);1108reg91c_value = odm_get_bb_reg(dm, R_0x91c,11090xffffffff);1110reg920_value = odm_get_bb_reg(dm, R_0x920,11110xffffffff);1112reg924_value = odm_get_bb_reg(dm, R_0x924,11130xffffffff);1114PHYDM_DBG(dm, DBG_DFS,1115"0x918[%08x] 0x91c[%08x] 0x920[%08x] 0x924[%08x]\n",1116reg918_value, reg91c_value,1117reg920_value, reg924_value);1118}1119PHYDM_DBG(dm, DBG_DFS, "Throughput: %dMbps\n",1120(dm->rx_tp + dm->tx_tp));11211122PHYDM_DBG(dm, DBG_DFS,1123"dfs_regdomain = %d, dbg_mode = %d, idle_mode = %d, print_hist_rpt = %d, hist_cond_on = %d\n",1124region_domain, dfs->dbg_mode,1125dfs->idle_mode, dfs->print_hist_rpt,1126dfs->hist_cond_on);1127}1128if (dm->support_ic_type & ODM_IC_JGR3_SERIES) {1129tri_short_pulse = (radar_rpt_reg_value & BIT(20)) ? 1 : 0;1130tri_long_pulse = (radar_rpt_reg_value & BIT(28)) ? 1 : 0;1131} else {1132tri_short_pulse = (regf98_value & BIT(17)) ? 1 : 0;1133tri_long_pulse = (regf98_value & BIT(19)) ? 1 : 0;1134}11351136if (tri_short_pulse) {1137phydm_radar_detect_reset(dm);1138}1139if (tri_long_pulse) {1140phydm_radar_detect_reset(dm);1141if (region_domain == PHYDM_DFS_DOMAIN_MKK) {1142if (c_channel >= 52 && c_channel <= 64) {1143tri_long_pulse = 0;1144}1145}1146if (region_domain == PHYDM_DFS_DOMAIN_ETSI) {1147tri_long_pulse = 0;1148}1149}11501151st_l2h_new = dfs->st_l2h_cur;1152dfs->pulse_flag_hist[dfs->mask_idx] = tri_short_pulse | tri_long_pulse;1153dfs->pulse_type_hist[dfs->mask_idx] = (tri_long_pulse) ? 1 : 0;11541155/* PSD(not ready) */11561157fault_flag_det = 0;1158fault_flag_psd = 0;1159fa_flag = 0;1160if (region_domain == PHYDM_DFS_DOMAIN_ETSI) {1161fa_mask_th = dfs->fa_mask_th + 20;1162} else {1163fa_mask_th = dfs->fa_mask_th;1164}1165if (max_fa_in_hist >= fa_mask_th ||1166total_fa_in_hist >= fa_mask_th ||1167pre_post_now_acc_fa_in_hist >= fa_mask_th ||1168dfs->igi_cur >= 0x30) {1169st_l2h_new = dfs->st_l2h_max;1170dfs->radar_det_mask_hist[index] = 1;1171if (dfs->pulse_flag_hist[index] == 1) {1172dfs->pulse_flag_hist[index] = 0;1173if (dfs->det_print2) {1174PHYDM_DBG(dm, DBG_DFS,1175"Radar is masked : FA mask\n");1176}1177}1178fa_flag = 1;1179} else {1180dfs->radar_det_mask_hist[index] = 0;1181}11821183if (dfs->det_print) {1184PHYDM_DBG(dm, DBG_DFS, "mask_idx: %d\n", dfs->mask_idx);1185PHYDM_DBG(dm, DBG_DFS, "radar_det_mask_hist: ");1186for (i = 0; i < 5; i++)1187PHYDM_DBG(dm, DBG_DFS, "%d ",1188dfs->radar_det_mask_hist[i]);1189PHYDM_DBG(dm, DBG_DFS, "pulse_flag_hist: ");1190for (i = 0; i < 5; i++)1191PHYDM_DBG(dm, DBG_DFS, "%d ", dfs->pulse_flag_hist[i]);1192PHYDM_DBG(dm, DBG_DFS, "fa_inc_hist: ");1193for (i = 0; i < 5; i++)1194PHYDM_DBG(dm, DBG_DFS, "%d ", dfs->fa_inc_hist[i]);1195PHYDM_DBG(dm, DBG_DFS,1196"\nfa_mask_th: %d max_fa_in_hist: %d total_fa_in_hist: %d pre_post_now_acc_fa_in_hist: %d ",1197fa_mask_th, max_fa_in_hist, total_fa_in_hist,1198pre_post_now_acc_fa_in_hist);1199}12001201sum = 0;1202for (k = 0; k < 5; k++) {1203if (dfs->radar_det_mask_hist[k] == 1)1204sum++;1205}12061207if (dfs->mask_hist_checked <= 5)1208dfs->mask_hist_checked++;12091210if (dfs->mask_hist_checked >= 5 && dfs->pulse_flag_hist[index]) {1211if (sum <= 2) {1212if (dfs->hist_cond_on) {1213/*return the value from hist_radar_detected*/1214radar_detected = phydm_dfs_hist_log(dm, index);1215} else {1216if (dfs->pulse_type_hist[index] == 0)1217dfs->radar_type = 0;1218else if (dfs->pulse_type_hist[index] == 1)1219dfs->radar_type = 1;1220radar_detected = 1;1221PHYDM_DBG(dm, DBG_DFS,1222"Detected type %d radar signal!\n",1223dfs->radar_type);1224}1225} else {1226fault_flag_det = 1;1227if (dfs->det_print2) {1228PHYDM_DBG(dm, DBG_DFS,1229"Radar is masked : mask_hist large than thd\n");1230}1231}1232}12331234dfs->mask_idx++;1235if (dfs->mask_idx == 5)1236dfs->mask_idx = 0;12371238if (fault_flag_det == 0 && fault_flag_psd == 0 && fa_flag == 0) {1239if (dfs->igi_cur < 0x30) {1240st_l2h_new = dfs->st_l2h_min;1241}1242}12431244if (st_l2h_new != dfs->st_l2h_cur) {1245if (st_l2h_new < dfs->st_l2h_min) {1246dfs->st_l2h_cur = dfs->st_l2h_min;1247} else if (st_l2h_new > dfs->st_l2h_max)1248dfs->st_l2h_cur = dfs->st_l2h_max;1249else1250dfs->st_l2h_cur = st_l2h_new;1251/*odm_set_bb_reg(dm, R_0x91c, 0xff, dfs->st_l2h_cur);*/12521253dfs->pwdb_th_cur = ((int)dfs->st_l2h_cur - (int)dfs->igi_cur)1254/ 2 + dfs->pwdb_scalar_factor;12551256/*@limit the pwdb value to absolute lower bound 8*/1257dfs->pwdb_th_cur = MAX_2(dfs->pwdb_th_cur, (int)dfs->pwdb_th);12581259/*@limit the pwdb value to absolute upper bound 0x1f*/1260dfs->pwdb_th_cur = MIN_2(dfs->pwdb_th_cur, 0x1f);12611262if (dm->support_ic_type & ODM_IC_JGR3_SERIES)1263odm_set_bb_reg(dm, R_0xa50, 0x000000f0,1264dfs->pwdb_th_cur);1265#if (RTL8721D_SUPPORT)1266else if (dm->support_ic_type & ODM_RTL8721D) {1267odm_set_bb_reg(dm, R_0xf54, 0x0000001f,1268((dfs->st_l2h_cur & 0x0000007c) >> 2));1269odm_set_bb_reg(dm, R_0xf58, 0xc0000000,1270(dfs->st_l2h_cur & 0x00000003));1271odm_set_bb_reg(dm, R_0xf70, 0x03c00000,1272dfs->pwdb_th_cur);1273}1274#endif1275else1276odm_set_bb_reg(dm, R_0x918, 0x00001f00,1277dfs->pwdb_th_cur);1278}12791280if (dfs->det_print) {1281PHYDM_DBG(dm, DBG_DFS,1282"fault_flag_det[%d], fault_flag_psd[%d], DFS_detected [%d]\n",1283fault_flag_det, fault_flag_psd, radar_detected);1284}1285#if (RTL8721D_SUPPORT)1286if (dm->support_ic_type & (ODM_RTL8721D))1287odm_set_bb_reg(dm, R_0x908, MASKDWORD, reg908_value);1288#endif12891290return radar_detected;1291}12921293void phydm_dfs_histogram_radar_distinguish(1294void *dm_void)1295{1296struct dm_struct *dm = (struct dm_struct *)dm_void;1297struct _DFS_STATISTICS *dfs = &dm->dfs;1298u8 region_domain = dm->dfs_region_domain;1299u8 c_channel = *dm->channel;1300u8 band_width = *dm->band_width;13011302u8 dfs_pw_thd1 = 0, dfs_pw_thd2 = 0, dfs_pw_thd3 = 0;1303u8 dfs_pw_thd4 = 0, dfs_pw_thd5 = 0;1304u8 dfs_pri_thd1 = 0, dfs_pri_thd2 = 0, dfs_pri_thd3 = 0;1305u8 dfs_pri_thd4 = 0, dfs_pri_thd5 = 0;1306u8 pri_th = 0, i = 0;1307u8 max_pri_idx = 0, max_pw_idx = 0, max_pri_cnt_th = 0;1308u8 max_pri_cnt_fcc_g1_th = 0, max_pri_cnt_fcc_g3_th = 0;1309u8 safe_pri_pw_diff_th = 0, safe_pri_pw_diff_fcc_th = 0;1310u8 safe_pri_pw_diff_w53_th = 0, safe_pri_pw_diff_fcc_idle_th = 0;1311u16 j = 0;1312u32 dfs_hist1_peak_index = 0, dfs_hist2_peak_index = 0;1313u32 dfs_hist1_pw = 0, dfs_hist2_pw = 0, g_pw[6] = {0};1314u32 g_peakindex[16] = {0}, g_mask_32 = 0, false_peak_hist1 = 0;1315u32 false_peak_hist2_above10 = 0, false_peak_hist2_above0 = 0;1316u32 dfs_hist1_pri = 0, dfs_hist2_pri = 0, g_pri[6] = {0};1317u32 pw_sum_g0g5 = 0, pw_sum_g1g2g3g4 = 0;1318u32 pri_sum_g0g5 = 0, pri_sum_g1g2g3g4 = 0;1319u32 pw_sum_ss_g1g2g3g4 = 0, pri_sum_ss_g1g2g3g4 = 0;1320u32 max_pri_cnt = 0, max_pw_cnt = 0;1321#if (RTL8721D_SUPPORT)1322if (dm->support_ic_type & (ODM_RTL8721D))1323return;1324#endif13251326/*read peak index hist report*/1327odm_set_bb_reg(dm, 0x19e4, BIT(22) | BIT(23), 0x0);1328dfs_hist1_peak_index = odm_get_bb_reg(dm, 0xf5c, 0xffffffff);1329dfs_hist2_peak_index = odm_get_bb_reg(dm, 0xf74, 0xffffffff);13301331g_peakindex[15] = ((dfs_hist1_peak_index & 0x0000000f) >> 0);1332g_peakindex[14] = ((dfs_hist1_peak_index & 0x000000f0) >> 4);1333g_peakindex[13] = ((dfs_hist1_peak_index & 0x00000f00) >> 8);1334g_peakindex[12] = ((dfs_hist1_peak_index & 0x0000f000) >> 12);1335g_peakindex[11] = ((dfs_hist1_peak_index & 0x000f0000) >> 16);1336g_peakindex[10] = ((dfs_hist1_peak_index & 0x00f00000) >> 20);1337g_peakindex[9] = ((dfs_hist1_peak_index & 0x0f000000) >> 24);1338g_peakindex[8] = ((dfs_hist1_peak_index & 0xf0000000) >> 28);1339g_peakindex[7] = ((dfs_hist2_peak_index & 0x0000000f) >> 0);1340g_peakindex[6] = ((dfs_hist2_peak_index & 0x000000f0) >> 4);1341g_peakindex[5] = ((dfs_hist2_peak_index & 0x00000f00) >> 8);1342g_peakindex[4] = ((dfs_hist2_peak_index & 0x0000f000) >> 12);1343g_peakindex[3] = ((dfs_hist2_peak_index & 0x000f0000) >> 16);1344g_peakindex[2] = ((dfs_hist2_peak_index & 0x00f00000) >> 20);1345g_peakindex[1] = ((dfs_hist2_peak_index & 0x0f000000) >> 24);1346g_peakindex[0] = ((dfs_hist2_peak_index & 0xf0000000) >> 28);13471348/*read pulse width hist report*/1349odm_set_bb_reg(dm, 0x19e4, BIT(22) | BIT(23), 0x1);1350dfs_hist1_pw = odm_get_bb_reg(dm, 0xf5c, 0xffffffff);1351dfs_hist2_pw = odm_get_bb_reg(dm, 0xf74, 0xffffffff);13521353g_pw[0] = (unsigned int)((dfs_hist2_pw & 0xff000000) >> 24);1354g_pw[1] = (unsigned int)((dfs_hist2_pw & 0x00ff0000) >> 16);1355g_pw[2] = (unsigned int)((dfs_hist2_pw & 0x0000ff00) >> 8);1356g_pw[3] = (unsigned int)dfs_hist2_pw & 0x000000ff;1357g_pw[4] = (unsigned int)((dfs_hist1_pw & 0xff000000) >> 24);1358g_pw[5] = (unsigned int)((dfs_hist1_pw & 0x00ff0000) >> 16);13591360/*read pulse repetition interval hist report*/1361odm_set_bb_reg(dm, 0x19e4, BIT(22) | BIT(23), 0x3);1362dfs_hist1_pri = odm_get_bb_reg(dm, 0xf5c, 0xffffffff);1363dfs_hist2_pri = odm_get_bb_reg(dm, 0xf74, 0xffffffff);1364odm_set_bb_reg(dm, 0x19b4, 0x10000000, 1); /*reset histo report*/1365odm_set_bb_reg(dm, 0x19b4, 0x10000000, 0); /*@continue histo report*/13661367g_pri[0] = (unsigned int)((dfs_hist2_pri & 0xff000000) >> 24);1368g_pri[1] = (unsigned int)((dfs_hist2_pri & 0x00ff0000) >> 16);1369g_pri[2] = (unsigned int)((dfs_hist2_pri & 0x0000ff00) >> 8);1370g_pri[3] = (unsigned int)dfs_hist2_pri & 0x000000ff;1371g_pri[4] = (unsigned int)((dfs_hist1_pri & 0xff000000) >> 24);1372g_pri[5] = (unsigned int)((dfs_hist1_pri & 0x00ff0000) >> 16);13731374dfs->pri_cond1 = 0;1375dfs->pri_cond2 = 0;1376dfs->pri_cond3 = 0;1377dfs->pri_cond4 = 0;1378dfs->pri_cond5 = 0;1379dfs->pw_cond1 = 0;1380dfs->pw_cond2 = 0;1381dfs->pw_cond3 = 0;1382dfs->pri_type3_4_cond1 = 0; /*@for ETSI*/1383dfs->pri_type3_4_cond2 = 0; /*@for ETSI*/1384dfs->pw_long_cond1 = 0; /*@for long radar*/1385dfs->pw_long_cond2 = 0; /*@for long radar*/1386dfs->pri_long_cond1 = 0; /*@for long radar*/1387dfs->pw_flag = 0;1388dfs->pri_flag = 0;1389dfs->pri_type3_4_flag = 0; /*@for ETSI*/1390dfs->long_radar_flag = 0;1391dfs->pw_std = 0; /*The std(var) of reasonable num of pw group*/1392dfs->pri_std = 0; /*The std(var) of reasonable num of pri group*/13931394for (i = 0; i < 6; i++) {1395dfs->pw_hold_sum[i] = 0;1396dfs->pri_hold_sum[i] = 0;1397dfs->pw_long_hold_sum[i] = 0;1398dfs->pri_long_hold_sum[i] = 0;1399}14001401if (dfs->idle_mode == 1)1402pri_th = dfs->pri_hist_th;1403else1404pri_th = dfs->pri_hist_th - 1;14051406for (i = 0; i < 6; i++) {1407dfs->pw_hold[dfs->hist_idx][i] = (u8)g_pw[i];1408dfs->pri_hold[dfs->hist_idx][i] = (u8)g_pri[i];1409/*@collect whole histogram report may take some time1410*so we add the counter of 2 time slots in FCC and ETSI1411*/1412if (region_domain == 1 || region_domain == 3) {1413dfs->pw_hold_sum[i] = dfs->pw_hold_sum[i] +1414dfs->pw_hold[(dfs->hist_idx + 1) % 3][i] +1415dfs->pw_hold[(dfs->hist_idx + 2) % 3][i];1416dfs->pri_hold_sum[i] = dfs->pri_hold_sum[i] +1417dfs->pri_hold[(dfs->hist_idx + 1) % 3][i] +1418dfs->pri_hold[(dfs->hist_idx + 2) % 3][i];1419} else{1420/*@collect whole histogram report may take some time,1421*so we add the counter of 3 time slots in MKK or else1422*/1423dfs->pw_hold_sum[i] = dfs->pw_hold_sum[i] +1424dfs->pw_hold[(dfs->hist_idx + 1) % 4][i] +1425dfs->pw_hold[(dfs->hist_idx + 2) % 4][i] +1426dfs->pw_hold[(dfs->hist_idx + 3) % 4][i];1427dfs->pri_hold_sum[i] = dfs->pri_hold_sum[i] +1428dfs->pri_hold[(dfs->hist_idx + 1) % 4][i] +1429dfs->pri_hold[(dfs->hist_idx + 2) % 4][i] +1430dfs->pri_hold[(dfs->hist_idx + 3) % 4][i];1431}1432}1433/*@For long radar type*/1434for (i = 0; i < 6; i++) {1435dfs->pw_long_hold[dfs->hist_long_idx][i] = (u8)g_pw[i];1436dfs->pri_long_hold[dfs->hist_long_idx][i] = (u8)g_pri[i];1437/*@collect whole histogram report may take some time,1438*so we add the counter of 299 time slots for long radar1439*/1440for (j = 1; j < 300; j++) {1441dfs->pw_long_hold_sum[i] = dfs->pw_long_hold_sum[i] +1442dfs->pw_long_hold[(dfs->hist_long_idx + j) % 300][i];1443dfs->pri_long_hold_sum[i] = dfs->pri_long_hold_sum[i] +1444dfs->pri_long_hold[(dfs->hist_long_idx + j) % 300][i];1445}1446}1447dfs->hist_idx++;1448dfs->hist_long_idx++;1449if (dfs->hist_long_idx == 300)1450dfs->hist_long_idx = 0;1451if (region_domain == 1 || region_domain == 3) {1452if (dfs->hist_idx == 3)1453dfs->hist_idx = 0;1454} else if (dfs->hist_idx == 4) {1455dfs->hist_idx = 0;1456}14571458max_pri_cnt = 0;1459max_pri_idx = 0;1460max_pw_cnt = 0;1461max_pw_idx = 0;1462max_pri_cnt_th = dfs->pri_sum_g1_th;1463max_pri_cnt_fcc_g1_th = dfs->pri_sum_g1_fcc_th;1464max_pri_cnt_fcc_g3_th = dfs->pri_sum_g3_fcc_th;1465safe_pri_pw_diff_th = dfs->pri_pw_diff_th;1466safe_pri_pw_diff_fcc_th = dfs->pri_pw_diff_fcc_th;1467safe_pri_pw_diff_fcc_idle_th = dfs->pri_pw_diff_fcc_idle_th;1468safe_pri_pw_diff_w53_th = dfs->pri_pw_diff_w53_th;14691470/*@g1 to g4 is the reseasonable range of pri and pw*/1471for (i = 1; i <= 4; i++) {1472if (dfs->pri_hold_sum[i] > max_pri_cnt) {1473max_pri_cnt = dfs->pri_hold_sum[i];1474max_pri_idx = i;1475}1476if (dfs->pw_hold_sum[i] > max_pw_cnt) {1477max_pw_cnt = dfs->pw_hold_sum[i];1478max_pw_idx = i;1479}1480if (dfs->pri_hold_sum[i] >= pri_th)1481dfs->pri_cond1 = 1;1482}14831484pri_sum_g0g5 = dfs->pri_hold_sum[0];1485if (pri_sum_g0g5 == 0)1486pri_sum_g0g5 = 1;1487pri_sum_g1g2g3g4 = dfs->pri_hold_sum[1] + dfs->pri_hold_sum[2]1488+ dfs->pri_hold_sum[3] + dfs->pri_hold_sum[4];14891490/*pw will reduce because of dc, so we do not treat g0 as illegal group*/1491pw_sum_g0g5 = dfs->pw_hold_sum[5];1492if (pw_sum_g0g5 == 0)1493pw_sum_g0g5 = 1;1494pw_sum_g1g2g3g4 = dfs->pw_hold_sum[1] + dfs->pw_hold_sum[2] +1495dfs->pw_hold_sum[3] + dfs->pw_hold_sum[4];14961497/*@Calculate the variation from g1 to g4*/1498for (i = 1; i < 5; i++) {1499/*Sum of square*/1500pw_sum_ss_g1g2g3g4 = pw_sum_ss_g1g2g3g4 +1501(dfs->pw_hold_sum[i] - (pw_sum_g1g2g3g4 / 4)) *1502(dfs->pw_hold_sum[i] - (pw_sum_g1g2g3g4 / 4));1503pri_sum_ss_g1g2g3g4 = pri_sum_ss_g1g2g3g4 +1504(dfs->pri_hold_sum[i] - (pri_sum_g1g2g3g4 / 4)) *1505(dfs->pri_hold_sum[i] - (pri_sum_g1g2g3g4 / 4));1506}1507/*The value may less than the normal variance,1508*since the variable type is int (not float)1509*/1510dfs->pw_std = (u16)(pw_sum_ss_g1g2g3g4 / 4);1511dfs->pri_std = (u16)(pri_sum_ss_g1g2g3g4 / 4);15121513if (region_domain == 1) {1514dfs->pri_type3_4_flag = 1; /*@ETSI flag*/15151516/*PRI judgment conditions for short radar type*/1517/*ratio of reasonable group and illegal group &&1518*pri variation of short radar should be large (=6)1519*/1520if (max_pri_idx != 4 && dfs->pri_hold_sum[5] > 0)1521dfs->pri_cond2 = 0;1522else1523dfs->pri_cond2 = 1;15241525/*reasonable group shouldn't large*/1526if ((pri_sum_g0g5 + pri_sum_g1g2g3g4) / pri_sum_g0g5 > 2 &&1527pri_sum_g1g2g3g4 <= dfs->pri_sum_safe_fcc_th)1528dfs->pri_cond3 = 1;15291530/*@Cancel the condition that the abs between pri and pw*/1531if (dfs->pri_std >= dfs->pri_std_th)1532dfs->pri_cond4 = 1;1533else if (max_pri_idx == 1 &&1534max_pri_cnt >= max_pri_cnt_fcc_g1_th)1535dfs->pri_cond4 = 1;15361537/*we set threshold = 7 (>4) for distinguishing type 3,4 (g3)*/1538if (max_pri_idx == 1 && dfs->pri_hold_sum[3] +1539dfs->pri_hold_sum[4] + dfs->pri_hold_sum[5] > 0)1540dfs->pri_cond5 = 0;1541else1542dfs->pri_cond5 = 1;15431544if (dfs->pri_cond1 && dfs->pri_cond2 && dfs->pri_cond3 &&1545dfs->pri_cond4 && dfs->pri_cond5)1546dfs->pri_flag = 1;15471548/* PW judgment conditions for short radar type */1549/*ratio of reasonable and illegal group && g5 should be zero*/1550if (((pw_sum_g0g5 + pw_sum_g1g2g3g4) / pw_sum_g0g5 > 2) &&1551(dfs->pw_hold_sum[5] <= 1))1552dfs->pw_cond1 = 1;1553/*unreasonable group*/1554if (dfs->pw_hold_sum[4] == 0 && dfs->pw_hold_sum[5] == 0)1555dfs->pw_cond2 = 1;1556/*pw's std (short radar) should be large(=7)*/1557if (dfs->pw_std >= dfs->pw_std_th)1558dfs->pw_cond3 = 1;1559if (dfs->pw_cond1 && dfs->pw_cond2 && dfs->pw_cond3)1560dfs->pw_flag = 1;15611562/* @Judgment conditions of long radar type */1563if (band_width == CHANNEL_WIDTH_20) {1564if (dfs->pw_long_hold_sum[4] >=1565dfs->pw_long_lower_20m_th)1566dfs->pw_long_cond1 = 1;1567} else{1568if (dfs->pw_long_hold_sum[4] >= dfs->pw_long_lower_th)1569dfs->pw_long_cond1 = 1;1570}1571/* @Disable the condition that dfs->pw_long_hold_sum[1] */1572if (dfs->pw_long_hold_sum[2] + dfs->pw_long_hold_sum[3] +1573dfs->pw_long_hold_sum[4] <= dfs->pw_long_sum_upper_th &&1574dfs->pw_long_hold_sum[2] <= dfs->pw_long_hold_sum[4] &&1575dfs->pw_long_hold_sum[3] <= dfs->pw_long_hold_sum[4])1576dfs->pw_long_cond2 = 1;1577/*@g4 should be large for long radar*/1578if (dfs->pri_long_hold_sum[4] <= dfs->pri_long_upper_th)1579dfs->pri_long_cond1 = 1;1580if (dfs->pw_long_cond1 && dfs->pw_long_cond2 &&1581dfs->pri_long_cond1)1582dfs->long_radar_flag = 1;1583} else if (region_domain == 2) {1584dfs->pri_type3_4_flag = 1; /*@ETSI flag*/15851586/*PRI judgment conditions for short radar type*/1587if ((pri_sum_g0g5 + pri_sum_g1g2g3g4) / pri_sum_g0g5 > 2)1588dfs->pri_cond2 = 1;15891590/*reasonable group shouldn't too large*/1591if (pri_sum_g1g2g3g4 <= dfs->pri_sum_safe_fcc_th)1592dfs->pri_cond3 = 1;15931594/*Cancel the abs diff between pri and pw for idle mode (thr=2)*/1595dfs->pri_cond4 = 1;15961597if (dfs->idle_mode == 1) {1598if (dfs->pri_std >= dfs->pri_std_idle_th) {1599if (max_pw_idx == 3 &&1600pri_sum_g1g2g3g4 <= dfs->pri_sum_type4_th){1601/*To distinguish between type 4 radar and false detection*/1602dfs->pri_cond5 = 1;1603} else if (max_pw_idx == 1 &&1604pri_sum_g1g2g3g4 >=1605dfs->pri_sum_type6_th) {1606/*To distinguish between type 6 radar and false detection*/1607dfs->pri_cond5 = 1;1608} else {1609/*pri variation of short radar should be large (idle mode)*/1610dfs->pri_cond5 = 1;1611}1612}1613} else {1614/*pri variation of short radar should be large (TP mode)*/1615if (dfs->pri_std >= dfs->pri_std_th)1616dfs->pri_cond5 = 1;1617}16181619if (dfs->pri_cond1 && dfs->pri_cond2 && dfs->pri_cond3 &&1620dfs->pri_cond4 && dfs->pri_cond5)1621dfs->pri_flag = 1;16221623/* PW judgment conditions for short radar type */1624if (((pw_sum_g0g5 + pw_sum_g1g2g3g4) / pw_sum_g0g5 > 2) &&1625(dfs->pw_hold_sum[5] <= 1))1626/*ratio of reasonable and illegal group && g5 should be zero*/1627dfs->pw_cond1 = 1;16281629if ((c_channel >= 52) && (c_channel <= 64))1630dfs->pw_cond2 = 1;1631/*unreasonable group shouldn't too large*/1632else if (dfs->pw_hold_sum[0] <= dfs->pw_g0_th)1633dfs->pw_cond2 = 1;16341635if (dfs->idle_mode == 1) {1636/*pw variation of short radar should be large (idle mode)*/1637if (dfs->pw_std >= dfs->pw_std_idle_th)1638dfs->pw_cond3 = 1;1639} else {1640/*pw variation of short radar should be large (TP mode)*/1641if (dfs->pw_std >= dfs->pw_std_th)1642dfs->pw_cond3 = 1;1643}1644if (dfs->pw_cond1 && dfs->pw_cond2 && dfs->pw_cond3)1645dfs->pw_flag = 1;16461647/* @Judgment conditions of long radar type */1648if (band_width == CHANNEL_WIDTH_20) {1649if (dfs->pw_long_hold_sum[4] >=1650dfs->pw_long_lower_20m_th)1651dfs->pw_long_cond1 = 1;1652} else{1653if (dfs->pw_long_hold_sum[4] >= dfs->pw_long_lower_th)1654dfs->pw_long_cond1 = 1;1655}1656if (dfs->pw_long_hold_sum[1] + dfs->pw_long_hold_sum[2] +1657dfs->pw_long_hold_sum[3] + dfs->pw_long_hold_sum[4]1658<= dfs->pw_long_sum_upper_th)1659dfs->pw_long_cond2 = 1;1660/*@g4 should be large for long radar*/1661if (dfs->pri_long_hold_sum[4] <= dfs->pri_long_upper_th)1662dfs->pri_long_cond1 = 1;1663if (dfs->pw_long_cond1 &&1664dfs->pw_long_cond2 && dfs->pri_long_cond1)1665dfs->long_radar_flag = 1;1666} else if (region_domain == 3) {1667/*ratio of reasonable group and illegal group */1668if ((pri_sum_g0g5 + pri_sum_g1g2g3g4) / pri_sum_g0g5 > 2)1669dfs->pri_cond2 = 1;16701671if (pri_sum_g1g2g3g4 <= dfs->pri_sum_safe_th)1672dfs->pri_cond3 = 1;16731674/*@Cancel the condition that the abs between pri and pw*/1675dfs->pri_cond4 = 1;16761677if (dfs->pri_hold_sum[5] <= dfs->pri_sum_g5_th)1678dfs->pri_cond5 = 1;16791680if (band_width == CHANNEL_WIDTH_40) {1681if (max_pw_idx == 4) {1682if (max_pw_cnt >= dfs->type4_pw_max_cnt &&1683pri_sum_g1g2g3g4 >=1684dfs->type4_safe_pri_sum_th) {1685dfs->pri_cond1 = 1;1686dfs->pri_cond4 = 1;1687dfs->pri_type3_4_cond1 = 1;1688}1689}1690}16911692if (dfs->pri_cond1 && dfs->pri_cond2 &&1693dfs->pri_cond3 && dfs->pri_cond4 && dfs->pri_cond5)1694dfs->pri_flag = 1;16951696if (((pw_sum_g0g5 + pw_sum_g1g2g3g4) / pw_sum_g0g5 > 2))1697dfs->pw_flag = 1;16981699/*@max num pri group is g1 means radar type3 or type4*/1700if (max_pri_idx == 1) {1701if (max_pri_cnt >= max_pri_cnt_th)1702dfs->pri_type3_4_cond1 = 1;1703if (dfs->pri_hold_sum[4] <=1704dfs->pri_sum_g5_under_g1_th &&1705dfs->pri_hold_sum[5] <= dfs->pri_sum_g5_under_g1_th)1706dfs->pri_type3_4_cond2 = 1;1707} else {1708dfs->pri_type3_4_cond1 = 1;1709dfs->pri_type3_4_cond2 = 1;1710}1711if (dfs->pri_type3_4_cond1 && dfs->pri_type3_4_cond2)1712dfs->pri_type3_4_flag = 1;1713} else {1714}17151716if (dfs->print_hist_rpt) {1717dfs_pw_thd1 = (u8)odm_get_bb_reg(dm, 0x19e4, 0xff000000);1718dfs_pw_thd2 = (u8)odm_get_bb_reg(dm, 0x19e8, 0x000000ff);1719dfs_pw_thd3 = (u8)odm_get_bb_reg(dm, 0x19e8, 0x0000ff00);1720dfs_pw_thd4 = (u8)odm_get_bb_reg(dm, 0x19e8, 0x00ff0000);1721dfs_pw_thd5 = (u8)odm_get_bb_reg(dm, 0x19e8, 0xff000000);17221723dfs_pri_thd1 = (u8)odm_get_bb_reg(dm, 0x19b8, 0x7F80);1724dfs_pri_thd2 = (u8)odm_get_bb_reg(dm, 0x19ec, 0x000000ff);1725dfs_pri_thd3 = (u8)odm_get_bb_reg(dm, 0x19ec, 0x0000ff00);1726dfs_pri_thd4 = (u8)odm_get_bb_reg(dm, 0x19ec, 0x00ff0000);1727dfs_pri_thd5 = (u8)odm_get_bb_reg(dm, 0x19ec, 0xff000000);17281729PHYDM_DBG(dm, DBG_DFS, "peak index hist\n");1730PHYDM_DBG(dm, DBG_DFS, "dfs_hist_peak_index=%x %x\n",1731dfs_hist1_peak_index, dfs_hist2_peak_index);1732PHYDM_DBG(dm, DBG_DFS, "g_peak_index_hist = ");1733for (i = 0; i < 16; i++)1734PHYDM_DBG(dm, DBG_DFS, " %x", g_peakindex[i]);1735PHYDM_DBG(dm, DBG_DFS, "\ndfs_pw_thd=%d %d %d %d %d\n",1736dfs_pw_thd1, dfs_pw_thd2, dfs_pw_thd3,1737dfs_pw_thd4, dfs_pw_thd5);1738PHYDM_DBG(dm, DBG_DFS, "-----pulse width hist-----\n");1739PHYDM_DBG(dm, DBG_DFS, "dfs_hist_pw=%x %x\n",1740dfs_hist1_pw, dfs_hist2_pw);1741PHYDM_DBG(dm, DBG_DFS, "g_pw_hist = %x %x %x %x %x %x\n",1742g_pw[0], g_pw[1], g_pw[2], g_pw[3],1743g_pw[4], g_pw[5]);1744PHYDM_DBG(dm, DBG_DFS, "dfs_pri_thd=%d %d %d %d %d\n",1745dfs_pri_thd1, dfs_pri_thd2, dfs_pri_thd3,1746dfs_pri_thd4, dfs_pri_thd5);1747PHYDM_DBG(dm, DBG_DFS, "-----pulse interval hist-----\n");1748PHYDM_DBG(dm, DBG_DFS, "dfs_hist_pri=%x %x\n",1749dfs_hist1_pri, dfs_hist2_pri);1750PHYDM_DBG(dm, DBG_DFS,1751"g_pri_hist = %x %x %x %x %x %x, pw_flag = %d, pri_flag = %d\n",1752g_pri[0], g_pri[1], g_pri[2], g_pri[3], g_pri[4],1753g_pri[5], dfs->pw_flag, dfs->pri_flag);1754if (region_domain == 1 || region_domain == 3) {1755PHYDM_DBG(dm, DBG_DFS, "hist_idx= %d\n",1756(dfs->hist_idx + 2) % 3);1757} else {1758PHYDM_DBG(dm, DBG_DFS, "hist_idx= %d\n",1759(dfs->hist_idx + 3) % 4);1760}1761PHYDM_DBG(dm, DBG_DFS, "hist_long_idx= %d\n",1762(dfs->hist_long_idx + 299) % 300);1763PHYDM_DBG(dm, DBG_DFS,1764"pw_sum_g0g5 = %d, pw_sum_g1g2g3g4 = %d\n",1765pw_sum_g0g5, pw_sum_g1g2g3g4);1766PHYDM_DBG(dm, DBG_DFS,1767"pri_sum_g0g5 = %d, pri_sum_g1g2g3g4 = %d\n",1768pri_sum_g0g5, pri_sum_g1g2g3g4);1769PHYDM_DBG(dm, DBG_DFS, "pw_hold_sum = %d %d %d %d %d %d\n",1770dfs->pw_hold_sum[0], dfs->pw_hold_sum[1],1771dfs->pw_hold_sum[2], dfs->pw_hold_sum[3],1772dfs->pw_hold_sum[4], dfs->pw_hold_sum[5]);1773PHYDM_DBG(dm, DBG_DFS, "pri_hold_sum = %d %d %d %d %d %d\n",1774dfs->pri_hold_sum[0], dfs->pri_hold_sum[1],1775dfs->pri_hold_sum[2], dfs->pri_hold_sum[3],1776dfs->pri_hold_sum[4], dfs->pri_hold_sum[5]);1777PHYDM_DBG(dm, DBG_DFS, "pw_long_hold_sum = %d %d %d %d %d %d\n",1778dfs->pw_long_hold_sum[0], dfs->pw_long_hold_sum[1],1779dfs->pw_long_hold_sum[2], dfs->pw_long_hold_sum[3],1780dfs->pw_long_hold_sum[4], dfs->pw_long_hold_sum[5]);1781PHYDM_DBG(dm, DBG_DFS,1782"pri_long_hold_sum = %d %d %d %d %d %d\n",1783dfs->pri_long_hold_sum[0], dfs->pri_long_hold_sum[1],1784dfs->pri_long_hold_sum[2], dfs->pri_long_hold_sum[3],1785dfs->pri_long_hold_sum[4], dfs->pri_long_hold_sum[5]);1786PHYDM_DBG(dm, DBG_DFS, "idle_mode = %d\n", dfs->idle_mode);1787PHYDM_DBG(dm, DBG_DFS, "pw_standard = %d\n", dfs->pw_std);1788PHYDM_DBG(dm, DBG_DFS, "pri_standard = %d\n", dfs->pri_std);1789for (j = 0; j < 4; j++) {1790for (i = 0; i < 6; i++) {1791PHYDM_DBG(dm, DBG_DFS, "pri_hold = %d ",1792dfs->pri_hold[j][i]);1793}1794PHYDM_DBG(dm, DBG_DFS, "\n");1795}1796PHYDM_DBG(dm, DBG_DFS, "\n");1797PHYDM_DBG(dm, DBG_DFS,1798"pri_cond1 = %d, pri_cond2 = %d, pri_cond3 = %d, pri_cond4 = %d, pri_cond5 = %d\n",1799dfs->pri_cond1, dfs->pri_cond2, dfs->pri_cond3,1800dfs->pri_cond4, dfs->pri_cond5);1801PHYDM_DBG(dm, DBG_DFS,1802"bandwidth = %d, pri_th = %d, max_pri_cnt_th = %d, safe_pri_pw_diff_th = %d\n",1803band_width, pri_th, max_pri_cnt_th,1804safe_pri_pw_diff_th);1805}1806}18071808boolean phydm_dfs_hist_log(void *dm_void, u8 index)1809{1810struct dm_struct *dm = (struct dm_struct *)dm_void;1811struct _DFS_STATISTICS *dfs = &dm->dfs;1812u8 i = 0, j = 0;1813boolean hist_radar_detected = 0;18141815if (dfs->pulse_type_hist[index] == 0) {1816dfs->radar_type = 0;1817if (dfs->pw_flag && dfs->pri_flag &&1818dfs->pri_type3_4_flag) {1819hist_radar_detected = 1;1820PHYDM_DBG(dm, DBG_DFS,1821"Detected type %d radar signal!\n",1822dfs->radar_type);1823if (dfs->det_print2) {1824PHYDM_DBG(dm, DBG_DFS,1825"hist_idx= %d\n",1826(dfs->hist_idx + 3) % 4);1827for (j = 0; j < 4; j++) {1828for (i = 0; i < 6; i++) {1829PHYDM_DBG(dm, DBG_DFS,1830"pri_hold = %d ",1831dfs->pri_hold[j][i]);1832}1833PHYDM_DBG(dm, DBG_DFS, "\n");1834}1835PHYDM_DBG(dm, DBG_DFS, "\n");1836for (j = 0; j < 4; j++) {1837for (i = 0; i < 6; i++) {1838PHYDM_DBG(dm, DBG_DFS, "pw_hold = %d ",1839dfs->pw_hold[j][i]);1840}1841PHYDM_DBG(dm, DBG_DFS, "\n");1842}1843PHYDM_DBG(dm, DBG_DFS, "\n");1844PHYDM_DBG(dm, DBG_DFS, "idle_mode = %d\n",1845dfs->idle_mode);1846PHYDM_DBG(dm, DBG_DFS,1847"pw_hold_sum = %d %d %d %d %d %d\n",1848dfs->pw_hold_sum[0],1849dfs->pw_hold_sum[1],1850dfs->pw_hold_sum[2],1851dfs->pw_hold_sum[3],1852dfs->pw_hold_sum[4],1853dfs->pw_hold_sum[5]);1854PHYDM_DBG(dm, DBG_DFS,1855"pri_hold_sum = %d %d %d %d %d %d\n",1856dfs->pri_hold_sum[0],1857dfs->pri_hold_sum[1],1858dfs->pri_hold_sum[2],1859dfs->pri_hold_sum[3],1860dfs->pri_hold_sum[4],1861dfs->pri_hold_sum[5]);1862}1863} else {1864if (dfs->det_print2) {1865if (dfs->pulse_flag_hist[index] &&1866dfs->pri_flag == 0) {1867PHYDM_DBG(dm, DBG_DFS, "pri_variation = %d\n",1868dfs->pri_std);1869PHYDM_DBG(dm, DBG_DFS,1870"PRI criterion is not satisfied!\n");1871if (dfs->pri_cond1 == 0)1872PHYDM_DBG(dm, DBG_DFS,1873"pri_cond1 is not satisfied!\n");1874if (dfs->pri_cond2 == 0)1875PHYDM_DBG(dm, DBG_DFS,1876"pri_cond2 is not satisfied!\n");1877if (dfs->pri_cond3 == 0)1878PHYDM_DBG(dm, DBG_DFS,1879"pri_cond3 is not satisfied!\n");1880if (dfs->pri_cond4 == 0)1881PHYDM_DBG(dm, DBG_DFS,1882"pri_cond4 is not satisfied!\n");1883if (dfs->pri_cond5 == 0)1884PHYDM_DBG(dm, DBG_DFS,1885"pri_cond5 is not satisfied!\n");1886}1887if (dfs->pulse_flag_hist[index] &&1888dfs->pw_flag == 0) {1889PHYDM_DBG(dm, DBG_DFS, "pw_variation = %d\n",1890dfs->pw_std);1891PHYDM_DBG(dm, DBG_DFS,1892"PW criterion is not satisfied!\n");1893if (dfs->pw_cond1 == 0)1894PHYDM_DBG(dm, DBG_DFS,1895"pw_cond1 is not satisfied!\n");1896if (dfs->pw_cond2 == 0)1897PHYDM_DBG(dm, DBG_DFS,1898"pw_cond2 is not satisfied!\n");1899if (dfs->pw_cond3 == 0)1900PHYDM_DBG(dm, DBG_DFS,1901"pw_cond3 is not satisfied!\n");1902}1903if (dfs->pulse_flag_hist[index] &&1904(dfs->pri_type3_4_flag == 0)) {1905PHYDM_DBG(dm, DBG_DFS,1906"pri_type3_4 criterion is not satisfied!\n");1907if (dfs->pri_type3_4_cond1 == 0)1908PHYDM_DBG(dm, DBG_DFS,1909"pri_type3_4_cond1 is not satisfied!\n");1910if (dfs->pri_type3_4_cond2 == 0)1911PHYDM_DBG(dm, DBG_DFS,1912"pri_type3_4_cond2 is not satisfied!\n");1913}1914PHYDM_DBG(dm, DBG_DFS, "hist_idx= %d\n",1915(dfs->hist_idx + 3) % 4);1916for (j = 0; j < 4; j++) {1917for (i = 0; i < 6; i++) {1918PHYDM_DBG(dm, DBG_DFS,1919"pri_hold = %d ",1920dfs->pri_hold[j][i]);1921}1922PHYDM_DBG(dm, DBG_DFS, "\n");1923}1924PHYDM_DBG(dm, DBG_DFS, "\n");1925for (j = 0; j < 4; j++) {1926for (i = 0; i < 6; i++)1927PHYDM_DBG(dm, DBG_DFS,1928"pw_hold = %d ",1929dfs->pw_hold[j][i]);1930PHYDM_DBG(dm, DBG_DFS, "\n");1931}1932PHYDM_DBG(dm, DBG_DFS, "\n");1933PHYDM_DBG(dm, DBG_DFS, "idle_mode = %d\n",1934dfs->idle_mode);1935PHYDM_DBG(dm, DBG_DFS,1936"pw_hold_sum = %d %d %d %d %d %d\n",1937dfs->pw_hold_sum[0], dfs->pw_hold_sum[1],1938dfs->pw_hold_sum[2], dfs->pw_hold_sum[3],1939dfs->pw_hold_sum[4], dfs->pw_hold_sum[5]);1940PHYDM_DBG(dm, DBG_DFS,1941"pri_hold_sum = %d %d %d %d %d %d\n",1942dfs->pri_hold_sum[0], dfs->pri_hold_sum[1],1943dfs->pri_hold_sum[2], dfs->pri_hold_sum[3],1944dfs->pri_hold_sum[4], dfs->pri_hold_sum[5]);1945}1946}1947} else {1948dfs->radar_type = 1;1949if (dfs->det_print2) {1950PHYDM_DBG(dm, DBG_DFS, "\n");1951PHYDM_DBG(dm, DBG_DFS, "idle_mode = %d\n",1952dfs->idle_mode);1953PHYDM_DBG(dm, DBG_DFS,1954"long_radar_pw_hold_sum = %d %d %d %d %d %d\n",1955dfs->pw_long_hold_sum[0],1956dfs->pw_long_hold_sum[1],1957dfs->pw_long_hold_sum[2],1958dfs->pw_long_hold_sum[3],1959dfs->pw_long_hold_sum[4],1960dfs->pw_long_hold_sum[5]);1961PHYDM_DBG(dm, DBG_DFS,1962"long_radar_pri_hold_sum = %d %d %d %d %d %d\n",1963dfs->pri_long_hold_sum[0],1964dfs->pri_long_hold_sum[1],1965dfs->pri_long_hold_sum[2],1966dfs->pri_long_hold_sum[3],1967dfs->pri_long_hold_sum[4],1968dfs->pri_long_hold_sum[5]);1969}1970/* @Long radar should satisfy three conditions */1971if (dfs->long_radar_flag == 1) {1972hist_radar_detected = 1;1973PHYDM_DBG(dm, DBG_DFS,1974"Detected type %d radar signal!\n",1975dfs->radar_type);1976} else {1977if (dfs->det_print2) {1978if (dfs->pw_long_cond1 == 0)1979PHYDM_DBG(dm, DBG_DFS,1980"--pw_long_cond1 is not satisfied!--\n");1981if (dfs->pw_long_cond2 == 0)1982PHYDM_DBG(dm, DBG_DFS,1983"--pw_long_cond2 is not satisfied!--\n");1984if (dfs->pri_long_cond1 == 0)1985PHYDM_DBG(dm, DBG_DFS,1986"--pri_long_cond1 is not satisfied!--\n");1987}1988}1989}1990return hist_radar_detected;1991}19921993boolean phydm_radar_detect(void *dm_void)1994{1995struct dm_struct *dm = (struct dm_struct *)dm_void;1996struct _DFS_STATISTICS *dfs = &dm->dfs;1997boolean enable_DFS = false;1998boolean radar_detected = false;19992000if (dm->support_ic_type & ODM_IC_JGR3_SERIES) {2001dfs->igi_cur = (u8)odm_get_bb_reg(dm, R_0x1d70, 0x0000007f);2002dfs->st_l2h_cur = (u8)odm_get_bb_reg(dm, R_0xa40, 0x00007f00);2003#if (RTL8721D_SUPPORT)2004} else if (dm->support_ic_type & (ODM_RTL8721D)) {2005dfs->st_l2h_cur = (u8)(odm_get_bb_reg(dm, R_0xf54,20060x0000001f) << 2);2007dfs->st_l2h_cur += (u8)odm_get_bb_reg(dm, R_0xf58, 0xc0000000);2008#endif2009} else {2010dfs->igi_cur = (u8)odm_get_bb_reg(dm, R_0xc50, 0x0000007f);2011dfs->st_l2h_cur = (u8)odm_get_bb_reg(dm, R_0x91c, 0x000000ff);2012}20132014/* @dynamic pwdb calibration */2015if (dfs->igi_pre != dfs->igi_cur) {2016dfs->pwdb_th_cur = ((int)dfs->st_l2h_cur - (int)dfs->igi_cur)2017/ 2 + dfs->pwdb_scalar_factor;20182019/* @limit the pwdb value to absolute lower bound 0xa */2020dfs->pwdb_th_cur = MAX_2(dfs->pwdb_th_cur, (int)dfs->pwdb_th);2021/* @limit the pwdb value to absolute upper bound 0x1f */2022dfs->pwdb_th_cur = MIN_2(dfs->pwdb_th_cur, 0x1f);20232024if (dm->support_ic_type & ODM_IC_JGR3_SERIES)2025odm_set_bb_reg(dm, R_0xa50, 0x000000f0,2026dfs->pwdb_th_cur);2027#if (RTL8721D_SUPPORT)2028else if (dm->support_ic_type & (ODM_RTL8721D))2029odm_set_bb_reg(dm, R_0xf70, 0x03c00000,2030dfs->pwdb_th_cur);2031#endif2032else2033odm_set_bb_reg(dm, R_0x918, 0x00001f00,2034dfs->pwdb_th_cur);2035}20362037dfs->igi_pre = dfs->igi_cur;20382039phydm_dfs_dynamic_setting(dm);2040if (dm->support_ic_type & (ODM_RTL8814A | ODM_RTL8822B | ODM_RTL8821C))2041phydm_dfs_histogram_radar_distinguish(dm);2042radar_detected = phydm_radar_detect_dm_check(dm);20432044if (dm->support_ic_type & (ODM_RTL8198F | ODM_RTL8822C | ODM_RTL8812F |2045ODM_RTL8197G)) {2046if (odm_get_bb_reg(dm, R_0xa40, BIT(15)))2047enable_DFS = true;2048#if (RTL8721D_SUPPORT)2049} else if (dm->support_ic_type & (ODM_RTL8721D)) {2050if (odm_get_bb_reg(dm, R_0xf58, BIT(29)))2051enable_DFS = true;2052#endif2053} else if (dm->support_ic_type & (ODM_RTL8814B)) {2054if (dm->seg1_dfs_flag == 1) {2055if (odm_get_bb_reg(dm, R_0xa6c, BIT(15)))2056enable_DFS = true;2057} else if (odm_get_bb_reg(dm, R_0xa40, BIT(15)))2058enable_DFS = true;2059} else {2060if (odm_get_bb_reg(dm, R_0x924, BIT(15)))2061enable_DFS = true;2062}20632064if (enable_DFS && radar_detected) {2065PHYDM_DBG(dm, DBG_DFS,2066"Radar detect: enable_DFS:%d, radar_detected:%d\n",2067enable_DFS, radar_detected);2068phydm_radar_detect_reset(dm);2069if (dfs->dbg_mode == 1) {2070PHYDM_DBG(dm, DBG_DFS,2071"Radar is detected in DFS dbg mode.\n");2072radar_detected = 0;2073}2074}20752076if (enable_DFS && dfs->sw_trigger_mode == 1) {2077radar_detected = 1;2078PHYDM_DBG(dm, DBG_DFS,2079"Radar is detected in DFS SW trigger mode.\n");2080}20812082return enable_DFS && radar_detected;2083}20842085void phydm_dfs_hist_dbg(void *dm_void, char input[][16], u32 *_used,2086char *output, u32 *_out_len)2087{2088struct dm_struct *dm = (struct dm_struct *)dm_void;2089struct _DFS_STATISTICS *dfs = &dm->dfs;2090char help[] = "-h";2091u32 argv[30] = {0};2092u32 used = *_used;2093u32 out_len = *_out_len;2094u8 i;20952096if ((strcmp(input[1], help) == 0)) {2097PDM_SNPF(out_len, used, output + used, out_len - used,2098"{0} pri_hist_th = %d\n", dfs->pri_hist_th);2099PDM_SNPF(out_len, used, output + used, out_len - used,2100"{1} pri_sum_g1_th = %d\n", dfs->pri_sum_g1_th);2101PDM_SNPF(out_len, used, output + used, out_len - used,2102"{2} pri_sum_g5_th = %d\n", dfs->pri_sum_g5_th);2103PDM_SNPF(out_len, used, output + used, out_len - used,2104"{3} pri_sum_g1_fcc_th = %d\n",2105dfs->pri_sum_g1_fcc_th);2106PDM_SNPF(out_len, used, output + used, out_len - used,2107"{4} pri_sum_g3_fcc_th = %d\n",2108dfs->pri_sum_g3_fcc_th);2109PDM_SNPF(out_len, used, output + used, out_len - used,2110"{5} pri_sum_safe_fcc_th = %d\n",2111dfs->pri_sum_safe_fcc_th);2112PDM_SNPF(out_len, used, output + used, out_len - used,2113"{6} pri_sum_type4_th = %d\n", dfs->pri_sum_type4_th);2114PDM_SNPF(out_len, used, output + used, out_len - used,2115"{7} pri_sum_type6_th = %d\n", dfs->pri_sum_type6_th);2116PDM_SNPF(out_len, used, output + used, out_len - used,2117"{8} pri_sum_safe_th = %d\n", dfs->pri_sum_safe_th);2118PDM_SNPF(out_len, used, output + used, out_len - used,2119"{9} pri_sum_g5_under_g1_th = %d\n",2120dfs->pri_sum_g5_under_g1_th);2121PDM_SNPF(out_len, used, output + used, out_len - used,2122"{10} pri_pw_diff_th = %d\n", dfs->pri_pw_diff_th);2123PDM_SNPF(out_len, used, output + used, out_len - used,2124"{11} pri_pw_diff_fcc_th = %d\n",2125dfs->pri_pw_diff_fcc_th);2126PDM_SNPF(out_len, used, output + used, out_len - used,2127"{12} pri_pw_diff_fcc_idle_th = %d\n",2128dfs->pri_pw_diff_fcc_idle_th);2129PDM_SNPF(out_len, used, output + used, out_len - used,2130"{13} pri_pw_diff_w53_th = %d\n",2131dfs->pri_pw_diff_w53_th);2132PDM_SNPF(out_len, used, output + used, out_len - used,2133"{14} pri_type1_low_fcc_th = %d\n",2134dfs->pri_type1_low_fcc_th);2135PDM_SNPF(out_len, used, output + used, out_len - used,2136"{15} pri_type1_upp_fcc_th = %d\n",2137dfs->pri_type1_upp_fcc_th);2138PDM_SNPF(out_len, used, output + used, out_len - used,2139"{16} pri_type1_cen_fcc_th = %d\n",2140dfs->pri_type1_cen_fcc_th);2141PDM_SNPF(out_len, used, output + used, out_len - used,2142"{17} pw_g0_th = %d\n", dfs->pw_g0_th);2143PDM_SNPF(out_len, used, output + used, out_len - used,2144"{18} pw_long_lower_20m_th = %d\n",2145dfs->pw_long_lower_20m_th);2146PDM_SNPF(out_len, used, output + used, out_len - used,2147"{19} pw_long_lower_th = %d\n",2148dfs->pw_long_lower_th);2149PDM_SNPF(out_len, used, output + used, out_len - used,2150"{20} pri_long_upper_th = %d\n",2151dfs->pri_long_upper_th);2152PDM_SNPF(out_len, used, output + used, out_len - used,2153"{21} pw_long_sum_upper_th = %d\n",2154dfs->pw_long_sum_upper_th);2155PDM_SNPF(out_len, used, output + used, out_len - used,2156"{22} pw_std_th = %d\n", dfs->pw_std_th);2157PDM_SNPF(out_len, used, output + used, out_len - used,2158"{23} pw_std_idle_th = %d\n", dfs->pw_std_idle_th);2159PDM_SNPF(out_len, used, output + used, out_len - used,2160"{24} pri_std_th = %d\n", dfs->pri_std_th);2161PDM_SNPF(out_len, used, output + used, out_len - used,2162"{25} pri_std_idle_th = %d\n", dfs->pri_std_idle_th);2163PDM_SNPF(out_len, used, output + used, out_len - used,2164"{26} type4_pw_max_cnt = %d\n", dfs->type4_pw_max_cnt);2165PDM_SNPF(out_len, used, output + used, out_len - used,2166"{27} type4_safe_pri_sum_th = %d\n",2167dfs->type4_safe_pri_sum_th);2168} else {2169PHYDM_SSCANF(input[1], DCMD_DECIMAL, &argv[0]);21702171for (i = 1; i < 30; i++) {2172if (input[i + 1])2173PHYDM_SSCANF(input[i + 1], DCMD_DECIMAL,2174&argv[i]);2175}2176if (argv[0] == 0) {2177dfs->pri_hist_th = (u8)argv[1];2178PDM_SNPF(out_len, used, output + used, out_len - used,2179"pri_hist_th = %d\n",2180dfs->pri_hist_th);2181} else if (argv[0] == 1) {2182dfs->pri_sum_g1_th = (u8)argv[1];2183PDM_SNPF(out_len, used, output + used, out_len - used,2184"pri_sum_g1_th = %d\n",2185dfs->pri_sum_g1_th);2186} else if (argv[0] == 2) {2187dfs->pri_sum_g5_th = (u8)argv[1];2188PDM_SNPF(out_len, used, output + used, out_len - used,2189"pri_sum_g5_th = %d\n",2190dfs->pri_sum_g5_th);2191} else if (argv[0] == 3) {2192dfs->pri_sum_g1_fcc_th = (u8)argv[1];2193PDM_SNPF(out_len, used, output + used, out_len - used,2194"pri_sum_g1_fcc_th = %d\n",2195dfs->pri_sum_g1_fcc_th);2196} else if (argv[0] == 4) {2197dfs->pri_sum_g3_fcc_th = (u8)argv[1];2198PDM_SNPF(out_len, used, output + used, out_len - used,2199"pri_sum_g3_fcc_th = %d\n",2200dfs->pri_sum_g3_fcc_th);2201} else if (argv[0] == 5) {2202dfs->pri_sum_safe_fcc_th = (u8)argv[1];2203PDM_SNPF(out_len, used, output + used, out_len - used,2204"pri_sum_safe_fcc_th = %d\n",2205dfs->pri_sum_safe_fcc_th);2206} else if (argv[0] == 6) {2207dfs->pri_sum_type4_th = (u8)argv[1];2208PDM_SNPF(out_len, used, output + used, out_len - used,2209"pri_sum_type4_th = %d\n",2210dfs->pri_sum_type4_th);2211} else if (argv[0] == 7) {2212dfs->pri_sum_type6_th = (u8)argv[1];2213PDM_SNPF(out_len, used, output + used, out_len - used,2214"pri_sum_type6_th = %d\n",2215dfs->pri_sum_type6_th);2216} else if (argv[0] == 8) {2217dfs->pri_sum_safe_th = (u8)argv[1];2218PDM_SNPF(out_len, used, output + used, out_len - used,2219"pri_sum_safe_th = %d\n",2220dfs->pri_sum_safe_th);2221} else if (argv[0] == 9) {2222dfs->pri_sum_g5_under_g1_th = (u8)argv[1];2223PDM_SNPF(out_len, used, output + used, out_len - used,2224"pri_sum_g5_under_g1_th = %d\n",2225dfs->pri_sum_g5_under_g1_th);2226} else if (argv[0] == 10) {2227dfs->pri_pw_diff_th = (u8)argv[1];2228PDM_SNPF(out_len, used, output + used, out_len - used,2229"pri_pw_diff_th = %d\n",2230dfs->pri_pw_diff_th);2231} else if (argv[0] == 11) {2232dfs->pri_pw_diff_fcc_th = (u8)argv[1];2233PDM_SNPF(out_len, used, output + used, out_len - used,2234"pri_pw_diff_fcc_th = %d\n",2235dfs->pri_pw_diff_fcc_th);2236} else if (argv[0] == 12) {2237dfs->pri_pw_diff_fcc_idle_th = (u8)argv[1];2238PDM_SNPF(out_len, used, output + used, out_len - used,2239"pri_pw_diff_fcc_idle_th = %d\n",2240dfs->pri_pw_diff_fcc_idle_th);2241} else if (argv[0] == 13) {2242dfs->pri_pw_diff_w53_th = (u8)argv[1];2243PDM_SNPF(out_len, used, output + used, out_len - used,2244"pri_pw_diff_w53_th = %d\n",2245dfs->pri_pw_diff_w53_th);2246} else if (argv[0] == 14) {2247dfs->pri_type1_low_fcc_th = (u8)argv[1];2248PDM_SNPF(out_len, used, output + used, out_len - used,2249"pri_type1_low_fcc_th = %d\n",2250dfs->pri_type1_low_fcc_th);2251} else if (argv[0] == 15) {2252dfs->pri_type1_upp_fcc_th = (u8)argv[1];2253PDM_SNPF(out_len, used, output + used, out_len - used,2254"pri_type1_upp_fcc_th = %d\n",2255dfs->pri_type1_upp_fcc_th);2256} else if (argv[0] == 16) {2257dfs->pri_type1_cen_fcc_th = (u8)argv[1];2258PDM_SNPF(out_len, used, output + used, out_len - used,2259"pri_type1_cen_fcc_th = %d\n",2260dfs->pri_type1_cen_fcc_th);2261} else if (argv[0] == 17) {2262dfs->pw_g0_th = (u8)argv[1];2263PDM_SNPF(out_len, used, output + used, out_len - used,2264"pw_g0_th = %d\n",2265dfs->pw_g0_th);2266} else if (argv[0] == 18) {2267dfs->pw_long_lower_20m_th = (u8)argv[1];2268PDM_SNPF(out_len, used, output + used, out_len - used,2269"pw_long_lower_20m_th = %d\n",2270dfs->pw_long_lower_20m_th);2271} else if (argv[0] == 19) {2272dfs->pw_long_lower_th = (u8)argv[1];2273PDM_SNPF(out_len, used, output + used, out_len - used,2274"pw_long_lower_th = %d\n",2275dfs->pw_long_lower_th);2276} else if (argv[0] == 20) {2277dfs->pri_long_upper_th = (u8)argv[1];2278PDM_SNPF(out_len, used, output + used, out_len - used,2279"pri_long_upper_th = %d\n",2280dfs->pri_long_upper_th);2281} else if (argv[0] == 21) {2282dfs->pw_long_sum_upper_th = (u8)argv[1];2283PDM_SNPF(out_len, used, output + used, out_len - used,2284"pw_long_sum_upper_th = %d\n",2285dfs->pw_long_sum_upper_th);2286} else if (argv[0] == 22) {2287dfs->pw_std_th = (u8)argv[1];2288PDM_SNPF(out_len, used, output + used, out_len - used,2289"pw_std_th = %d\n",2290dfs->pw_std_th);2291} else if (argv[0] == 23) {2292dfs->pw_std_idle_th = (u8)argv[1];2293PDM_SNPF(out_len, used, output + used, out_len - used,2294"pw_std_idle_th = %d\n",2295dfs->pw_std_idle_th);2296} else if (argv[0] == 24) {2297dfs->pri_std_th = (u8)argv[1];2298PDM_SNPF(out_len, used, output + used, out_len - used,2299"pri_std_th = %d\n",2300dfs->pri_std_th);2301} else if (argv[0] == 25) {2302dfs->pri_std_idle_th = (u8)argv[1];2303PDM_SNPF(out_len, used, output + used, out_len - used,2304"pri_std_idle_th = %d\n",2305dfs->pri_std_idle_th);2306} else if (argv[0] == 26) {2307dfs->type4_pw_max_cnt = (u8)argv[1];2308PDM_SNPF(out_len, used, output + used, out_len - used,2309"type4_pw_max_cnt = %d\n",2310dfs->type4_pw_max_cnt);2311} else if (argv[0] == 27) {2312dfs->type4_safe_pri_sum_th = (u8)argv[1];2313PDM_SNPF(out_len, used, output + used, out_len - used,2314"type4_safe_pri_sum_th = %d\n",2315dfs->type4_safe_pri_sum_th);2316}2317}2318*_used = used;2319*_out_len = out_len;2320}23212322void phydm_dfs_debug(void *dm_void, char input[][16], u32 *_used,2323char *output, u32 *_out_len)2324{2325struct dm_struct *dm = (struct dm_struct *)dm_void;2326struct _DFS_STATISTICS *dfs = &dm->dfs;2327u32 used = *_used;2328u32 out_len = *_out_len;2329u32 argv[10] = {0};2330u8 i, input_idx = 0;23312332for (i = 0; i < 7; i++) {2333if (input[i + 1]) {2334PHYDM_SSCANF(input[i + 1], DCMD_HEX, &argv[i]);2335input_idx++;2336}2337}23382339if (input_idx == 0)2340return;23412342dfs->dbg_mode = (boolean)argv[0];2343dfs->sw_trigger_mode = (boolean)argv[1];2344dfs->force_TP_mode = (boolean)argv[2];2345dfs->det_print = (boolean)argv[3];2346dfs->det_print2 = (boolean)argv[4];2347dfs->print_hist_rpt = (boolean)argv[5];2348dfs->hist_cond_on = (boolean)argv[6];23492350PDM_SNPF(out_len, used, output + used, out_len - used,2351"dbg_mode: %d, sw_trigger_mode: %d, force_TP_mode: %d, det_print: %d,det_print2: %d, print_hist_rpt: %d, hist_cond_on: %d\n",2352dfs->dbg_mode, dfs->sw_trigger_mode, dfs->force_TP_mode,2353dfs->det_print, dfs->det_print2, dfs->print_hist_rpt,2354dfs->hist_cond_on);23552356/*switch (argv[0]) {2357case 1:2358#if defined(CONFIG_PHYDM_DFS_MASTER)2359set dbg parameters for radar detection instead of the default value2360if (argv[1] == 1) {2361dm->radar_detect_reg_918 = argv[2];2362dm->radar_detect_reg_91c = argv[3];2363dm->radar_detect_reg_920 = argv[4];2364dm->radar_detect_reg_924 = argv[5];2365dm->radar_detect_dbg_parm_en = 1;23662367PDM_SNPF((output + used, out_len - used, "Radar detection with dbg parameter\n"));2368PDM_SNPF((output + used, out_len - used, "reg918:0x%08X\n", dm->radar_detect_reg_918));2369PDM_SNPF((output + used, out_len - used, "reg91c:0x%08X\n", dm->radar_detect_reg_91c));2370PDM_SNPF((output + used, out_len - used, "reg920:0x%08X\n", dm->radar_detect_reg_920));2371PDM_SNPF((output + used, out_len - used, "reg924:0x%08X\n", dm->radar_detect_reg_924));2372} else {2373dm->radar_detect_dbg_parm_en = 0;2374PDM_SNPF((output + used, out_len - used, "Radar detection with default parameter\n"));2375}2376phydm_radar_detect_enable(dm);2377#endif defined(CONFIG_PHYDM_DFS_MASTER)23782379break;2380default:2381break;2382}*/2383}23842385u8 phydm_dfs_polling_time(void *dm_void)2386{2387struct dm_struct *dm = (struct dm_struct *)dm_void;2388struct _DFS_STATISTICS *dfs = &dm->dfs;23892390if (dm->support_ic_type & (ODM_RTL8814A | ODM_RTL8822B | ODM_RTL8821C))2391dfs->dfs_polling_time = 40;2392else2393dfs->dfs_polling_time = 100;23942395return dfs->dfs_polling_time;2396}23972398#endif /* @defined(CONFIG_PHYDM_DFS_MASTER) */23992400boolean2401phydm_is_dfs_band(void *dm_void)2402{2403struct dm_struct *dm = (struct dm_struct *)dm_void;24042405if (((*dm->channel >= 52) && (*dm->channel <= 64)) ||2406((*dm->channel >= 100) && (*dm->channel <= 144)))2407return true;2408else2409return false;2410}24112412boolean2413phydm_dfs_master_enabled(void *dm_void)2414{2415#ifdef CONFIG_PHYDM_DFS_MASTER2416struct dm_struct *dm = (struct dm_struct *)dm_void;2417boolean ret_val = false;24182419if (dm->dfs_master_enabled) /*pointer protection*/2420ret_val = *dm->dfs_master_enabled ? true : false;24212422return ret_val;2423#else2424return false;2425#endif2426}24272428#if (DM_ODM_SUPPORT_TYPE & ODM_WIN)2429#ifdef PHYDM_IC_JGR3_SERIES_SUPPORT2430void phydm_dfs_ap_reset_radar_detect_counter_and_flag(void *dm_void)2431{2432struct dm_struct *dm = (struct dm_struct *)dm_void;24332434/* @Clear Radar Counter and Radar flag */2435odm_set_bb_reg(dm, R_0xa40, BIT(15), 0);2436odm_set_bb_reg(dm, R_0xa40, BIT(15), 1);24372438/* RT_TRACE(COMP_DFS, DBG_LOUD, ("[DFS], After reset radar counter, 0xcf8 = 0x%x, 0xcf4 = 0x%x\n", */2439/* PHY_QueryBBReg(Adapter, 0xcf8, bMaskDWord), */2440/* PHY_QueryBBReg(Adapter, 0xcf4, bMaskDWord))); */2441}2442#endif2443#endif244424452446