phydm_dfs.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of version 2 of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  17. *
  18. *
  19. ******************************************************************************/
  20. /*
  21. ============================================================
  22. include files
  23. ============================================================
  24. */
  25. #include "mp_precomp.h"
  26. #include "phydm_precomp.h"
  27. #if defined(CONFIG_PHYDM_DFS_MASTER)
  28. boolean phydm_dfs_is_meteorology_channel(void *p_dm_void){
  29. struct PHY_DM_STRUCT *p_dm_odm = (struct PHY_DM_STRUCT *)p_dm_void;
  30. u8 c_channel = *(p_dm_odm->p_channel);
  31. u8 band_width = *(p_dm_odm->p_band_width);
  32. return ( (band_width == CHANNEL_WIDTH_80 && (c_channel) >= 116 && (c_channel) <= 128) ||
  33. (band_width == CHANNEL_WIDTH_40 && (c_channel) >= 116 && (c_channel) <= 128) ||
  34. (band_width == CHANNEL_WIDTH_20 && (c_channel) >= 120 && (c_channel) <= 128) );
  35. }
  36. void phydm_radar_detect_reset(void *p_dm_void)
  37. {
  38. struct PHY_DM_STRUCT *p_dm_odm = (struct PHY_DM_STRUCT *)p_dm_void;
  39. odm_set_bb_reg(p_dm_odm, 0x924, BIT(15), 0);
  40. odm_set_bb_reg(p_dm_odm, 0x924, BIT(15), 1);
  41. }
  42. void phydm_radar_detect_disable(void *p_dm_void)
  43. {
  44. struct PHY_DM_STRUCT *p_dm_odm = (struct PHY_DM_STRUCT *)p_dm_void;
  45. odm_set_bb_reg(p_dm_odm, 0x924, BIT(15), 0);
  46. ODM_RT_TRACE(p_dm_odm, ODM_COMP_DFS, ODM_DBG_LOUD, ("\n"));
  47. }
  48. static void phydm_radar_detect_with_dbg_parm(void *p_dm_void)
  49. {
  50. struct PHY_DM_STRUCT *p_dm_odm = (struct PHY_DM_STRUCT *)p_dm_void;
  51. odm_set_bb_reg(p_dm_odm, 0x918, MASKDWORD, p_dm_odm->radar_detect_reg_918);
  52. odm_set_bb_reg(p_dm_odm, 0x91c, MASKDWORD, p_dm_odm->radar_detect_reg_91c);
  53. odm_set_bb_reg(p_dm_odm, 0x920, MASKDWORD, p_dm_odm->radar_detect_reg_920);
  54. odm_set_bb_reg(p_dm_odm, 0x924, MASKDWORD, p_dm_odm->radar_detect_reg_924);
  55. }
  56. /* Init radar detection parameters, called after ch, bw is set */
  57. void phydm_radar_detect_enable(void *p_dm_void)
  58. {
  59. struct PHY_DM_STRUCT *p_dm_odm = (struct PHY_DM_STRUCT *)p_dm_void;
  60. struct _DFS_STATISTICS *p_dfs = (struct _DFS_STATISTICS *)phydm_get_structure(p_dm_odm, PHYDM_DFS);
  61. u8 region_domain = p_dm_odm->dfs_region_domain;
  62. u8 c_channel = *(p_dm_odm->p_channel);
  63. u8 band_width = *(p_dm_odm->p_band_width);
  64. u8 enable = 0;
  65. ODM_RT_TRACE(p_dm_odm, ODM_COMP_DFS, ODM_DBG_LOUD, ("test, region_domain = %d\n", region_domain));
  66. if (region_domain == PHYDM_DFS_DOMAIN_UNKNOWN) {
  67. ODM_RT_TRACE(p_dm_odm, ODM_COMP_DFS, ODM_DBG_LOUD, ("PHYDM_DFS_DOMAIN_UNKNOWN\n"));
  68. goto exit;
  69. }
  70. if (p_dm_odm->support_ic_type & (ODM_RTL8821 | ODM_RTL8812 | ODM_RTL8881A)) {
  71. odm_set_bb_reg(p_dm_odm, 0x814, 0x3fffffff, 0x04cc4d10);
  72. odm_set_bb_reg(p_dm_odm, 0x834, MASKBYTE0, 0x06);
  73. if (p_dm_odm->radar_detect_dbg_parm_en) {
  74. phydm_radar_detect_with_dbg_parm(p_dm_odm);
  75. enable = 1;
  76. goto exit;
  77. }
  78. if (region_domain == PHYDM_DFS_DOMAIN_ETSI) {
  79. odm_set_bb_reg(p_dm_odm, 0x918, MASKDWORD, 0x1c17ecdf);
  80. odm_set_bb_reg(p_dm_odm, 0x924, MASKDWORD, 0x01528500);
  81. odm_set_bb_reg(p_dm_odm, 0x91c, MASKDWORD, 0x0fa21a20);
  82. odm_set_bb_reg(p_dm_odm, 0x920, MASKDWORD, 0xe0f69204);
  83. } else if (region_domain == PHYDM_DFS_DOMAIN_MKK) {
  84. odm_set_bb_reg(p_dm_odm, 0x924, MASKDWORD, 0x01528500);
  85. odm_set_bb_reg(p_dm_odm, 0x920, MASKDWORD, 0xe0d67234);
  86. if (c_channel >= 52 && c_channel <= 64) {
  87. odm_set_bb_reg(p_dm_odm, 0x918, MASKDWORD, 0x1c16ecdf);
  88. odm_set_bb_reg(p_dm_odm, 0x91c, MASKDWORD, 0x0f141a20);
  89. } else {
  90. odm_set_bb_reg(p_dm_odm, 0x918, MASKDWORD, 0x1c16acdf);
  91. if (band_width == ODM_BW20M)
  92. odm_set_bb_reg(p_dm_odm, 0x91c, MASKDWORD, 0x64721a20);
  93. else
  94. odm_set_bb_reg(p_dm_odm, 0x91c, MASKDWORD, 0x68721a20);
  95. }
  96. } else if (region_domain == PHYDM_DFS_DOMAIN_FCC) {
  97. odm_set_bb_reg(p_dm_odm, 0x918, MASKDWORD, 0x1c16acdf);
  98. odm_set_bb_reg(p_dm_odm, 0x924, MASKDWORD, 0x01528500);
  99. odm_set_bb_reg(p_dm_odm, 0x920, MASKDWORD, 0xe0d67231);
  100. if (band_width == ODM_BW20M)
  101. odm_set_bb_reg(p_dm_odm, 0x91c, MASKDWORD, 0x64741a20);
  102. else
  103. odm_set_bb_reg(p_dm_odm, 0x91c, MASKDWORD, 0x68741a20);
  104. } else {
  105. /* not supported */
  106. ODM_RT_TRACE(p_dm_odm, ODM_COMP_DFS, ODM_DBG_LOUD, ("Unsupported dfs_region_domain:%d\n", region_domain));
  107. goto exit;
  108. }
  109. } else if (p_dm_odm->support_ic_type & (ODM_RTL8814A | ODM_RTL8822B | ODM_RTL8821C)) {
  110. odm_set_bb_reg(p_dm_odm, 0x814, 0x3fffffff, 0x04cc4d10);
  111. odm_set_bb_reg(p_dm_odm, 0x834, MASKBYTE0, 0x06);
  112. /* 8822B only, when BW = 20M, DFIR output is 40Mhz, but DFS input is 80MMHz, so it need to upgrade to 80MHz */
  113. if (p_dm_odm->support_ic_type & (ODM_RTL8822B | ODM_RTL8821C)) {
  114. if (band_width == ODM_BW20M)
  115. odm_set_bb_reg(p_dm_odm, 0x1984, BIT(26), 1);
  116. else
  117. odm_set_bb_reg(p_dm_odm, 0x1984, BIT(26), 0);
  118. }
  119. if (p_dm_odm->radar_detect_dbg_parm_en) {
  120. phydm_radar_detect_with_dbg_parm(p_dm_odm);
  121. enable = 1;
  122. goto exit;
  123. }
  124. if (region_domain == PHYDM_DFS_DOMAIN_ETSI) {
  125. odm_set_bb_reg(p_dm_odm, 0x918, MASKDWORD, 0x1c16acdf);
  126. odm_set_bb_reg(p_dm_odm, 0x924, MASKDWORD, 0x095a8500);
  127. odm_set_bb_reg(p_dm_odm, 0x91c, MASKDWORD, 0x0fa21a20);
  128. odm_set_bb_reg(p_dm_odm, 0x920, MASKDWORD, 0xe0f57204);
  129. } else if (region_domain == PHYDM_DFS_DOMAIN_MKK) {
  130. odm_set_bb_reg(p_dm_odm, 0x924, MASKDWORD, 0x095a8500);
  131. odm_set_bb_reg(p_dm_odm, 0x920, MASKDWORD, 0xe0d67234);
  132. if (c_channel >= 52 && c_channel <= 64) {
  133. odm_set_bb_reg(p_dm_odm, 0x918, MASKDWORD, 0x1c16ecdf);
  134. odm_set_bb_reg(p_dm_odm, 0x91c, MASKDWORD, 0x0f141a20);
  135. } else {
  136. odm_set_bb_reg(p_dm_odm, 0x918, MASKDWORD, 0x1c166cdf);
  137. if (band_width == ODM_BW20M)
  138. odm_set_bb_reg(p_dm_odm, 0x91c, MASKDWORD, 0x64721a20);
  139. else
  140. odm_set_bb_reg(p_dm_odm, 0x91c, MASKDWORD, 0x68721a20);
  141. }
  142. } else if (region_domain == PHYDM_DFS_DOMAIN_FCC) {
  143. odm_set_bb_reg(p_dm_odm, 0x918, MASKDWORD, 0x1c166cdf);
  144. odm_set_bb_reg(p_dm_odm, 0x924, MASKDWORD, 0x095a8500);
  145. odm_set_bb_reg(p_dm_odm, 0x920, MASKDWORD, 0xe0d67231);
  146. if (band_width == ODM_BW20M)
  147. odm_set_bb_reg(p_dm_odm, 0x91c, MASKDWORD, 0x64741a20);
  148. else
  149. odm_set_bb_reg(p_dm_odm, 0x91c, MASKDWORD, 0x68741a20);
  150. } else {
  151. /* not supported */
  152. ODM_RT_TRACE(p_dm_odm, ODM_COMP_DFS, ODM_DBG_LOUD, ("Unsupported dfs_region_domain:%d\n", region_domain));
  153. goto exit;
  154. }
  155. } else {
  156. /* not supported IC type*/
  157. ODM_RT_TRACE(p_dm_odm, ODM_COMP_DFS, ODM_DBG_LOUD, ("Unsupported IC type:%d\n", p_dm_odm->support_ic_type));
  158. goto exit;
  159. }
  160. enable = 1;
  161. p_dfs->st_l2h_cur = (u8)odm_get_bb_reg(p_dm_odm, 0x91c, 0x000000ff);
  162. p_dfs->pwdb_th = (u8)odm_get_bb_reg(p_dm_odm, 0x918, 0x00001f00);
  163. p_dfs->peak_th = (u8)odm_get_bb_reg(p_dm_odm, 0x918, 0x00030000);
  164. p_dfs->short_pulse_cnt_th = (u8)odm_get_bb_reg(p_dm_odm, 0x920, 0x000f0000);
  165. p_dfs->long_pulse_cnt_th = (u8)odm_get_bb_reg(p_dm_odm, 0x920, 0x00f00000);
  166. p_dfs->peak_window = (u8)odm_get_bb_reg(p_dm_odm, 0x920, 0x00000300);
  167. p_dfs->nb2wb_th = (u8)odm_get_bb_reg(p_dm_odm, 0x920, 0x0000e000);
  168. phydm_dfs_parameter_init(p_dm_odm);
  169. exit:
  170. if (enable) {
  171. phydm_radar_detect_reset(p_dm_odm);
  172. ODM_RT_TRACE(p_dm_odm, ODM_COMP_DFS, ODM_DBG_LOUD, ("on cch:%u, bw:%u\n", c_channel, band_width));
  173. } else
  174. phydm_radar_detect_disable(p_dm_odm);
  175. }
  176. void phydm_dfs_parameter_init(void *p_dm_void)
  177. {
  178. struct PHY_DM_STRUCT *p_dm_odm = (struct PHY_DM_STRUCT *)p_dm_void;
  179. struct _DFS_STATISTICS *p_dfs = (struct _DFS_STATISTICS *)phydm_get_structure(p_dm_odm, PHYDM_DFS);
  180. u8 i;
  181. p_dfs->fa_mask_th = 30;
  182. p_dfs->det_print = 1;
  183. p_dfs->det_print2 = 0;
  184. p_dfs->st_l2h_min = 0x20;
  185. p_dfs->st_l2h_max = 0x4e;
  186. p_dfs->pwdb_scalar_factor = 12;
  187. p_dfs->pwdb_th = 8;
  188. for(i=0; i<5;i++){
  189. p_dfs->pulse_flag_hist[i] = 0;
  190. p_dfs->radar_det_mask_hist[i] = 0;
  191. p_dfs->fa_inc_hist[i] = 0;
  192. }
  193. }
  194. void phydm_dfs_dynamic_setting(
  195. void *p_dm_void
  196. ){
  197. struct PHY_DM_STRUCT *p_dm_odm = (struct PHY_DM_STRUCT *)p_dm_void;
  198. struct _DFS_STATISTICS *p_dfs = (struct _DFS_STATISTICS *)phydm_get_structure(p_dm_odm, PHYDM_DFS);
  199. u8 peak_th_cur=0, short_pulse_cnt_th_cur=0, long_pulse_cnt_th_cur=0, three_peak_opt_cur=0, three_peak_th2_cur=0;
  200. u8 peak_window_cur=0, nb2wb_th_cur=0;
  201. u8 region_domain = p_dm_odm->dfs_region_domain;
  202. u8 c_channel = *(p_dm_odm->p_channel);
  203. if (p_dm_odm->rx_tp <= 2) {
  204. p_dfs->idle_mode = 1;
  205. if(p_dfs->force_TP_mode)
  206. p_dfs->idle_mode = 0;
  207. }
  208. else{
  209. p_dfs->idle_mode = 0;
  210. }
  211. if ((p_dfs->idle_mode == 1)) { /*idle (no traffic)*/
  212. peak_th_cur = 3;
  213. short_pulse_cnt_th_cur = 6;
  214. long_pulse_cnt_th_cur = 13;
  215. peak_window_cur = 2;
  216. nb2wb_th_cur = 6;
  217. three_peak_opt_cur = 1;
  218. three_peak_th2_cur = 2;
  219. if(region_domain == PHYDM_DFS_DOMAIN_MKK){
  220. if ((c_channel >= 52) && (c_channel <= 64)) {
  221. short_pulse_cnt_th_cur = 14;
  222. long_pulse_cnt_th_cur = 15;
  223. nb2wb_th_cur = 3;
  224. three_peak_th2_cur = 0;
  225. }
  226. else {
  227. short_pulse_cnt_th_cur = 6;
  228. nb2wb_th_cur = 3;
  229. three_peak_th2_cur = 0;
  230. long_pulse_cnt_th_cur = 10;
  231. }
  232. }
  233. else if(region_domain == PHYDM_DFS_DOMAIN_FCC){
  234. three_peak_th2_cur = 0;
  235. }
  236. else if(region_domain == PHYDM_DFS_DOMAIN_ETSI){
  237. long_pulse_cnt_th_cur = 15;
  238. if(phydm_dfs_is_meteorology_channel(p_dm_odm)){/*need to add check cac end condition*/
  239. peak_th_cur = 2;
  240. nb2wb_th_cur = 3;
  241. three_peak_opt_cur = 1;
  242. three_peak_th2_cur = 0;
  243. short_pulse_cnt_th_cur = 7;
  244. }
  245. else{
  246. three_peak_opt_cur = 1;
  247. three_peak_th2_cur = 0;
  248. short_pulse_cnt_th_cur = 7;
  249. nb2wb_th_cur = 3;
  250. }
  251. }
  252. else{ /*default: FCC*/
  253. three_peak_th2_cur = 0;
  254. }
  255. }
  256. else{ /*in service (with TP)*/
  257. peak_th_cur = 2;
  258. short_pulse_cnt_th_cur = 6;
  259. long_pulse_cnt_th_cur = 9;
  260. peak_window_cur = 2;
  261. nb2wb_th_cur = 3;
  262. three_peak_opt_cur = 1;
  263. three_peak_th2_cur = 2;
  264. if(region_domain == PHYDM_DFS_DOMAIN_MKK){
  265. if ((c_channel >= 52) && (c_channel <= 64)) {
  266. long_pulse_cnt_th_cur = 15;
  267. short_pulse_cnt_th_cur = 5; /*for high duty cycle*/
  268. three_peak_th2_cur = 0;
  269. }
  270. else {
  271. three_peak_opt_cur = 0;
  272. three_peak_th2_cur = 0;
  273. long_pulse_cnt_th_cur = 8;
  274. }
  275. }
  276. else if(region_domain == PHYDM_DFS_DOMAIN_FCC){
  277. }
  278. else if(region_domain == PHYDM_DFS_DOMAIN_ETSI){
  279. long_pulse_cnt_th_cur = 15;
  280. short_pulse_cnt_th_cur = 5;
  281. three_peak_opt_cur = 0;
  282. }
  283. else{
  284. }
  285. }
  286. }
  287. boolean
  288. phydm_radar_detect_dm_check(
  289. void *p_dm_void
  290. ){
  291. struct PHY_DM_STRUCT *p_dm_odm = (struct PHY_DM_STRUCT *)p_dm_void;
  292. struct _DFS_STATISTICS *p_dfs = (struct _DFS_STATISTICS *)phydm_get_structure(p_dm_odm, PHYDM_DFS);
  293. u8 region_domain = p_dm_odm->dfs_region_domain, index=0;
  294. u16 i=0, k=0, fa_count_cur=0, fa_count_inc=0, total_fa_in_hist=0, pre_post_now_acc_fa_in_hist=0, max_fa_in_hist=0, vht_crc_ok_cnt_cur=0;
  295. u16 vht_crc_ok_cnt_inc=0, ht_crc_ok_cnt_cur=0, ht_crc_ok_cnt_inc=0, leg_crc_ok_cnt_cur=0, leg_crc_ok_cnt_inc=0;
  296. u16 total_crc_ok_cnt_inc=0, short_pulse_cnt_cur=0, short_pulse_cnt_inc=0, long_pulse_cnt_cur=0, long_pulse_cnt_inc=0, total_pulse_count_inc=0;
  297. u32 regf98_value=0, reg918_value=0, reg91c_value=0, reg920_value=0, reg924_value=0;
  298. boolean tri_short_pulse=0, tri_long_pulse=0, radar_type=0, fault_flag_det=0, fault_flag_psd=0, fa_flag=0, radar_detected=0;
  299. u8 st_l2h_new=0, fa_mask_th=0, sum=0;
  300. u8 c_channel = *(p_dm_odm->p_channel);
  301. /*Get FA count during past 100ms*/
  302. fa_count_cur = (u16)odm_get_bb_reg(p_dm_odm, 0xf48, 0x0000ffff);
  303. if (p_dfs->fa_count_pre == 0)
  304. fa_count_inc = 0;
  305. else if (fa_count_cur >= p_dfs->fa_count_pre)
  306. fa_count_inc = fa_count_cur - p_dfs->fa_count_pre;
  307. else
  308. fa_count_inc = fa_count_cur;
  309. p_dfs->fa_count_pre = fa_count_cur;
  310. p_dfs->fa_inc_hist[p_dfs->mask_idx] = fa_count_inc;
  311. for (i=0; i<5; i++) {
  312. total_fa_in_hist = total_fa_in_hist + p_dfs->fa_inc_hist[i];
  313. if (p_dfs->fa_inc_hist[i] > max_fa_in_hist)
  314. max_fa_in_hist = p_dfs->fa_inc_hist[i];
  315. }
  316. if (p_dfs->mask_idx >= 2)
  317. index = p_dfs->mask_idx - 2;
  318. else
  319. index = 5 + p_dfs->mask_idx - 2;
  320. if (index == 0)
  321. pre_post_now_acc_fa_in_hist = p_dfs->fa_inc_hist[index] + p_dfs->fa_inc_hist[index+1] + p_dfs->fa_inc_hist[4];
  322. else if (index == 4)
  323. pre_post_now_acc_fa_in_hist = p_dfs->fa_inc_hist[index] + p_dfs->fa_inc_hist[0] + p_dfs->fa_inc_hist[index-1];
  324. else
  325. pre_post_now_acc_fa_in_hist = p_dfs->fa_inc_hist[index] + p_dfs->fa_inc_hist[index+1] + p_dfs->fa_inc_hist[index-1];
  326. /*Get VHT CRC32 ok count during past 100ms*/
  327. vht_crc_ok_cnt_cur = (u16)odm_get_bb_reg(p_dm_odm, 0xf0c, 0x00003fff);
  328. if (vht_crc_ok_cnt_cur >= p_dfs->vht_crc_ok_cnt_pre)
  329. vht_crc_ok_cnt_inc = vht_crc_ok_cnt_cur - p_dfs->vht_crc_ok_cnt_pre;
  330. else
  331. vht_crc_ok_cnt_inc = vht_crc_ok_cnt_cur;
  332. p_dfs->vht_crc_ok_cnt_pre = vht_crc_ok_cnt_cur;
  333. /*Get HT CRC32 ok count during past 100ms*/
  334. ht_crc_ok_cnt_cur = (u16)odm_get_bb_reg(p_dm_odm, 0xf10, 0x00003fff);
  335. if (ht_crc_ok_cnt_cur >= p_dfs->ht_crc_ok_cnt_pre)
  336. ht_crc_ok_cnt_inc = ht_crc_ok_cnt_cur - p_dfs->ht_crc_ok_cnt_pre;
  337. else
  338. ht_crc_ok_cnt_inc = ht_crc_ok_cnt_cur;
  339. p_dfs->ht_crc_ok_cnt_pre = ht_crc_ok_cnt_cur;
  340. /*Get Legacy CRC32 ok count during past 100ms*/
  341. leg_crc_ok_cnt_cur = (u16)odm_get_bb_reg(p_dm_odm, 0xf14, 0x00003fff);
  342. if (leg_crc_ok_cnt_cur >= p_dfs->leg_crc_ok_cnt_pre)
  343. leg_crc_ok_cnt_inc = leg_crc_ok_cnt_cur - p_dfs->leg_crc_ok_cnt_pre;
  344. else
  345. leg_crc_ok_cnt_inc = leg_crc_ok_cnt_cur;
  346. p_dfs->leg_crc_ok_cnt_pre = leg_crc_ok_cnt_cur;
  347. if ((vht_crc_ok_cnt_cur == 0x3fff) ||
  348. (ht_crc_ok_cnt_cur == 0x3fff) ||
  349. (leg_crc_ok_cnt_cur == 0x3fff)) {
  350. odm_set_bb_reg(p_dm_odm, 0xb58, BIT(0), 1);
  351. odm_set_bb_reg(p_dm_odm, 0xb58, BIT(0), 0);
  352. }
  353. total_crc_ok_cnt_inc = vht_crc_ok_cnt_inc + ht_crc_ok_cnt_inc + leg_crc_ok_cnt_inc;
  354. /*Get short pulse count, need carefully handle the counter overflow*/
  355. regf98_value = odm_get_bb_reg(p_dm_odm, 0xf98, 0xffffffff);
  356. short_pulse_cnt_cur = (u16)regf98_value & 0x000000ff;
  357. if (short_pulse_cnt_cur >= p_dfs->short_pulse_cnt_pre)
  358. short_pulse_cnt_inc = short_pulse_cnt_cur - p_dfs->short_pulse_cnt_pre;
  359. else
  360. short_pulse_cnt_inc = short_pulse_cnt_cur;
  361. p_dfs->short_pulse_cnt_pre = short_pulse_cnt_cur;
  362. /*Get long pulse count, need carefully handle the counter overflow*/
  363. long_pulse_cnt_cur = (u16)((regf98_value & 0x0000ff00) >> 8);
  364. if (long_pulse_cnt_cur >= p_dfs->long_pulse_cnt_pre)
  365. long_pulse_cnt_inc = long_pulse_cnt_cur - p_dfs->long_pulse_cnt_pre;
  366. else
  367. long_pulse_cnt_inc = long_pulse_cnt_cur;
  368. p_dfs->long_pulse_cnt_pre = long_pulse_cnt_cur;
  369. total_pulse_count_inc = short_pulse_cnt_inc + long_pulse_cnt_inc;
  370. if (p_dfs->det_print){
  371. ODM_RT_TRACE(p_dm_odm, ODM_COMP_DFS, ODM_DBG_LOUD, ("=====================================================================\n"));
  372. ODM_RT_TRACE(p_dm_odm, ODM_COMP_DFS, ODM_DBG_LOUD, ("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",
  373. total_crc_ok_cnt_inc, vht_crc_ok_cnt_inc, ht_crc_ok_cnt_inc, leg_crc_ok_cnt_inc, fa_count_inc));
  374. ODM_RT_TRACE(p_dm_odm, ODM_COMP_DFS, ODM_DBG_LOUD, ("Init_Gain[%x] 0x91c[%x] 0xf98[%08x] short_pulse_cnt_inc[%d] long_pulse_cnt_inc[%d]\n",
  375. p_dfs->igi_cur, p_dfs->st_l2h_cur, regf98_value, short_pulse_cnt_inc, long_pulse_cnt_inc));
  376. ODM_RT_TRACE(p_dm_odm, ODM_COMP_DFS, ODM_DBG_LOUD, ("Throughput: %dMbps\n", p_dm_odm->rx_tp));
  377. reg918_value = odm_get_bb_reg(p_dm_odm, 0x918, 0xffffffff);
  378. reg91c_value = odm_get_bb_reg(p_dm_odm, 0x91c, 0xffffffff);
  379. reg920_value = odm_get_bb_reg(p_dm_odm, 0x920, 0xffffffff);
  380. reg924_value = odm_get_bb_reg(p_dm_odm, 0x924, 0xffffffff);
  381. ODM_RT_TRACE(p_dm_odm, ODM_COMP_DFS, ODM_DBG_LOUD, ("0x918[%08x] 0x91c[%08x] 0x920[%08x] 0x924[%08x]\n", reg918_value, reg91c_value, reg920_value, reg924_value));
  382. ODM_RT_TRACE(p_dm_odm, ODM_COMP_DFS, ODM_DBG_LOUD, ("dfs_regdomain = %d, dbg_mode = %d, idle_mode = %d\n", region_domain, p_dfs->dbg_mode, p_dfs->idle_mode));
  383. }
  384. tri_short_pulse = (regf98_value & BIT(17))? 1 : 0;
  385. tri_long_pulse = (regf98_value & BIT(19))? 1 : 0;
  386. if(tri_short_pulse)
  387. radar_type = 0;
  388. else if(tri_long_pulse)
  389. radar_type = 1;
  390. if (tri_short_pulse) {
  391. odm_set_bb_reg(p_dm_odm, 0x924, BIT(15), 0);
  392. odm_set_bb_reg(p_dm_odm, 0x924, BIT(15), 1);
  393. }
  394. if (tri_long_pulse) {
  395. odm_set_bb_reg(p_dm_odm, 0x924, BIT(15), 0);
  396. odm_set_bb_reg(p_dm_odm, 0x924, BIT(15), 1);
  397. if (region_domain == PHYDM_DFS_DOMAIN_MKK) {
  398. if ((c_channel >= 52) && (c_channel <= 64)) {
  399. tri_long_pulse = 0;
  400. }
  401. }
  402. if (region_domain == PHYDM_DFS_DOMAIN_ETSI) {
  403. tri_long_pulse = 0;
  404. }
  405. }
  406. st_l2h_new = p_dfs->st_l2h_cur;
  407. p_dfs->pulse_flag_hist[p_dfs->mask_idx] = tri_short_pulse | tri_long_pulse;
  408. /* PSD(not ready) */
  409. fault_flag_det = 0;
  410. fault_flag_psd = 0;
  411. fa_flag = 0;
  412. if(region_domain == PHYDM_DFS_DOMAIN_ETSI){
  413. fa_mask_th = p_dfs->fa_mask_th + 20;
  414. }
  415. else{
  416. fa_mask_th = p_dfs->fa_mask_th;
  417. }
  418. if (max_fa_in_hist >= fa_mask_th || total_fa_in_hist >= fa_mask_th || pre_post_now_acc_fa_in_hist >= fa_mask_th || (p_dfs->igi_cur >= 0x30)){
  419. st_l2h_new = p_dfs->st_l2h_max;
  420. p_dfs->radar_det_mask_hist[index] = 1;
  421. if (p_dfs->pulse_flag_hist[index] == 1){
  422. p_dfs->pulse_flag_hist[index] = 0;
  423. if (p_dfs->det_print2){
  424. ODM_RT_TRACE(p_dm_odm, ODM_COMP_DFS, ODM_DBG_LOUD, ("Radar is masked : FA mask\n"));
  425. }
  426. }
  427. fa_flag = 1;
  428. }
  429. if (p_dfs->det_print) {
  430. ODM_RT_TRACE(p_dm_odm, ODM_COMP_DFS, ODM_DBG_LOUD, ("mask_idx: %d\n", p_dfs->mask_idx));
  431. ODM_RT_TRACE(p_dm_odm, ODM_COMP_DFS, ODM_DBG_LOUD, ("radar_det_mask_hist: "));
  432. for (i=0; i<5; i++)
  433. ODM_RT_TRACE(p_dm_odm, ODM_COMP_DFS, ODM_DBG_LOUD, ("%d ", p_dfs->radar_det_mask_hist[i]));
  434. ODM_RT_TRACE(p_dm_odm, ODM_COMP_DFS, ODM_DBG_LOUD, ("pulse_flag_hist: "));
  435. for (i=0; i<5; i++)
  436. ODM_RT_TRACE(p_dm_odm, ODM_COMP_DFS, ODM_DBG_LOUD, ("%d ", p_dfs->pulse_flag_hist[i]));
  437. ODM_RT_TRACE(p_dm_odm, ODM_COMP_DFS, ODM_DBG_LOUD, ("fa_inc_hist: "));
  438. for (i=0; i<5; i++)
  439. ODM_RT_TRACE(p_dm_odm, ODM_COMP_DFS, ODM_DBG_LOUD, ("%d ", p_dfs->fa_inc_hist[i]));
  440. ODM_RT_TRACE(p_dm_odm, ODM_COMP_DFS, ODM_DBG_LOUD, ("\nmax_fa_in_hist: %d pre_post_now_acc_fa_in_hist: %d ",max_fa_in_hist,pre_post_now_acc_fa_in_hist));
  441. }
  442. sum = 0;
  443. for (k=0; k<5; k++) {
  444. if (p_dfs->radar_det_mask_hist[k] == 1)
  445. sum++;
  446. }
  447. if (p_dfs->mask_hist_checked <= 5)
  448. p_dfs->mask_hist_checked++;
  449. if ((p_dfs->mask_hist_checked >= 5) && p_dfs->pulse_flag_hist[index])
  450. {
  451. if (sum <= 2)
  452. {
  453. radar_detected = 1 ;
  454. ODM_RT_TRACE(p_dm_odm, ODM_COMP_DFS, ODM_DBG_LOUD, ("Detected type %d radar signal!\n", radar_type));
  455. }
  456. else {
  457. fault_flag_det = 1;
  458. if (p_dfs->det_print2){
  459. ODM_RT_TRACE(p_dm_odm, ODM_COMP_DFS, ODM_DBG_LOUD, ("Radar is masked : mask_hist large than thd\n"));
  460. }
  461. }
  462. }
  463. p_dfs->mask_idx++;
  464. if (p_dfs->mask_idx == 5)
  465. p_dfs->mask_idx = 0;
  466. if ((fault_flag_det == 0) && (fault_flag_psd == 0) && (fa_flag ==0)) {
  467. if (p_dfs->igi_cur < 0x30) {
  468. st_l2h_new = p_dfs->st_l2h_min;
  469. }
  470. }
  471. if ((st_l2h_new != p_dfs->st_l2h_cur)) {
  472. if (st_l2h_new < p_dfs->st_l2h_min) {
  473. p_dfs->st_l2h_cur = p_dfs->st_l2h_min;
  474. }
  475. else if (st_l2h_new > p_dfs->st_l2h_max)
  476. p_dfs->st_l2h_cur = p_dfs->st_l2h_max;
  477. else
  478. p_dfs->st_l2h_cur = st_l2h_new;
  479. odm_set_bb_reg(p_dm_odm, 0x91c, 0xff, p_dfs->st_l2h_cur);
  480. p_dfs->pwdb_th = ((int)p_dfs->st_l2h_cur - (int)p_dfs->igi_cur)/2 + p_dfs->pwdb_scalar_factor;
  481. p_dfs->pwdb_th = MAX_2(p_dfs->pwdb_th, (int)p_dfs->pwdb_th); /*limit the pwdb value to absoulte lower bound 8*/
  482. p_dfs->pwdb_th = MIN_2(p_dfs->pwdb_th, 0x1f); /*limit the pwdb value to absoulte upper bound 0x1f*/
  483. odm_set_bb_reg(p_dm_odm, 0x918, 0x00001f00, p_dfs->pwdb_th);
  484. }
  485. if (p_dfs->det_print2) {
  486. ODM_RT_TRACE(p_dm_odm, ODM_COMP_DFS, ODM_DBG_LOUD, ("fault_flag_det[%d], fault_flag_psd[%d], DFS_detected [%d]\n",fault_flag_det, fault_flag_psd, radar_detected));
  487. }
  488. return radar_detected;
  489. }
  490. boolean phydm_radar_detect(void *p_dm_void)
  491. {
  492. struct PHY_DM_STRUCT *p_dm_odm = (struct PHY_DM_STRUCT *)p_dm_void;
  493. struct _DFS_STATISTICS *p_dfs = (struct _DFS_STATISTICS *)phydm_get_structure(p_dm_odm, PHYDM_DFS);
  494. boolean enable_DFS = false;
  495. boolean radar_detected = false;
  496. p_dfs->igi_cur = (u8)odm_get_bb_reg(p_dm_odm, 0xc50, 0x0000007f);
  497. p_dfs->st_l2h_cur = (u8)odm_get_bb_reg(p_dm_odm, 0x91c, 0x000000ff);
  498. /* dynamic pwdb calibration */
  499. if (p_dfs->igi_pre != p_dfs->igi_cur) {
  500. p_dfs->pwdb_th = ((int)p_dfs->st_l2h_cur - (int)p_dfs->igi_cur)/2 + p_dfs->pwdb_scalar_factor;
  501. p_dfs->pwdb_th = MAX_2(p_dfs->pwdb_th_cur, (int)p_dfs->pwdb_th); /* limit the pwdb value to absoulte lower bound 0xa */
  502. p_dfs->pwdb_th = MIN_2(p_dfs->pwdb_th_cur, 0x1f); /* limit the pwdb value to absoulte upper bound 0x1f */
  503. odm_set_bb_reg(p_dm_odm, 0x918, 0x00001f00, p_dfs->pwdb_th);
  504. }
  505. p_dfs->igi_pre = p_dfs->igi_cur;
  506. phydm_dfs_dynamic_setting(p_dm_odm);
  507. radar_detected = phydm_radar_detect_dm_check(p_dm_odm);
  508. if (odm_get_bb_reg(p_dm_odm, 0x924, BIT(15)))
  509. enable_DFS = true;
  510. if (enable_DFS && radar_detected) {
  511. ODM_RT_TRACE(p_dm_odm, ODM_COMP_DFS, ODM_DBG_LOUD, ("Radar detect: enable_DFS:%d, radar_detected:%d\n", enable_DFS, radar_detected));
  512. phydm_radar_detect_reset(p_dm_odm);
  513. if (p_dfs->dbg_mode == 1){
  514. ODM_RT_TRACE(p_dm_odm, ODM_COMP_DFS, ODM_DBG_LOUD, ("Radar is detected in DFS dbg mode.\n"));
  515. radar_detected = 0;
  516. }
  517. }
  518. return enable_DFS && radar_detected;
  519. }
  520. void
  521. phydm_dfs_debug(
  522. void *p_dm_void,
  523. u32 *const argv,
  524. u32 *_used,
  525. char *output,
  526. u32 *_out_len
  527. )
  528. {
  529. struct PHY_DM_STRUCT *p_dm_odm = (struct PHY_DM_STRUCT *)p_dm_void;
  530. struct _DFS_STATISTICS *p_dfs = (struct _DFS_STATISTICS *)phydm_get_structure(p_dm_odm, PHYDM_DFS);
  531. u32 used = *_used;
  532. u32 out_len = *_out_len;
  533. p_dfs->dbg_mode = (boolean)argv[0];
  534. p_dfs->force_TP_mode = (boolean)argv[1];
  535. p_dfs->det_print = (boolean)argv[2];
  536. p_dfs->det_print2 = (boolean)argv[3];
  537. PHYDM_SNPRINTF((output + used, out_len - used, "dbg_mode: %d, force_TP_mode: %d, det_print: %d, det_print2: %d\n", p_dfs->dbg_mode, p_dfs->force_TP_mode, p_dfs->det_print, p_dfs->det_print2));
  538. /*switch (argv[0]) {
  539. case 1:
  540. #if defined(CONFIG_PHYDM_DFS_MASTER)
  541. set dbg parameters for radar detection instead of the default value
  542. if (argv[1] == 1) {
  543. p_dm_odm->radar_detect_reg_918 = argv[2];
  544. p_dm_odm->radar_detect_reg_91c = argv[3];
  545. p_dm_odm->radar_detect_reg_920 = argv[4];
  546. p_dm_odm->radar_detect_reg_924 = argv[5];
  547. p_dm_odm->radar_detect_dbg_parm_en = 1;
  548. PHYDM_SNPRINTF((output + used, out_len - used, "Radar detection with dbg parameter\n"));
  549. PHYDM_SNPRINTF((output + used, out_len - used, "reg918:0x%08X\n", p_dm_odm->radar_detect_reg_918));
  550. PHYDM_SNPRINTF((output + used, out_len - used, "reg91c:0x%08X\n", p_dm_odm->radar_detect_reg_91c));
  551. PHYDM_SNPRINTF((output + used, out_len - used, "reg920:0x%08X\n", p_dm_odm->radar_detect_reg_920));
  552. PHYDM_SNPRINTF((output + used, out_len - used, "reg924:0x%08X\n", p_dm_odm->radar_detect_reg_924));
  553. } else {
  554. p_dm_odm->radar_detect_dbg_parm_en = 0;
  555. PHYDM_SNPRINTF((output + used, out_len - used, "Radar detection with default parameter\n"));
  556. }
  557. phydm_radar_detect_enable(p_dm_odm);
  558. #endif defined(CONFIG_PHYDM_DFS_MASTER)
  559. break;
  560. default:
  561. break;
  562. }*/
  563. }
  564. #endif /* defined(CONFIG_PHYDM_DFS_MASTER) */
  565. boolean
  566. phydm_dfs_master_enabled(
  567. void *p_dm_void
  568. )
  569. {
  570. #ifdef CONFIG_PHYDM_DFS_MASTER
  571. struct PHY_DM_STRUCT *p_dm_odm = (struct PHY_DM_STRUCT *)p_dm_void;
  572. return *p_dm_odm->dfs_master_enabled ? true : false;
  573. #else
  574. return false;
  575. #endif
  576. }