phydm_dfs.c 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2007 - 2017 Realtek Corporation.
  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. * The full GNU General Public License is included in this distribution in the
  15. * file called LICENSE.
  16. *
  17. * Contact Information:
  18. * wlanfae <wlanfae@realtek.com>
  19. * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
  20. * Hsinchu 300, Taiwan.
  21. *
  22. * Larry Finger <Larry.Finger@lwfinger.net>
  23. *
  24. *****************************************************************************/
  25. /*@
  26. * ============================================================
  27. * include files
  28. * ============================================================
  29. */
  30. #include "mp_precomp.h"
  31. #include "phydm_precomp.h"
  32. #if defined(CONFIG_PHYDM_DFS_MASTER)
  33. boolean phydm_dfs_is_meteorology_channel(void *dm_void)
  34. {
  35. struct dm_struct *dm = (struct dm_struct *)dm_void;
  36. u8 ch = *dm->channel;
  37. u8 bw = *dm->band_width;
  38. return ((bw == CHANNEL_WIDTH_80 && (ch) >= 116 && (ch) <= 128) ||
  39. (bw == CHANNEL_WIDTH_40 && (ch) >= 116 && (ch) <= 128) ||
  40. (bw == CHANNEL_WIDTH_20 && (ch) >= 120 && (ch) <= 128));
  41. }
  42. void phydm_radar_detect_reset(void *dm_void)
  43. {
  44. struct dm_struct *dm = (struct dm_struct *)dm_void;
  45. odm_set_bb_reg(dm, R_0x924, BIT(15), 0);
  46. odm_set_bb_reg(dm, R_0x924, BIT(15), 1);
  47. }
  48. void phydm_radar_detect_disable(void *dm_void)
  49. {
  50. struct dm_struct *dm = (struct dm_struct *)dm_void;
  51. odm_set_bb_reg(dm, R_0x924, BIT(15), 0);
  52. PHYDM_DBG(dm, DBG_DFS, "\n");
  53. }
  54. static void phydm_radar_detect_with_dbg_parm(void *dm_void)
  55. {
  56. struct dm_struct *dm = (struct dm_struct *)dm_void;
  57. odm_set_bb_reg(dm, R_0x918, MASKDWORD, dm->radar_detect_reg_918);
  58. odm_set_bb_reg(dm, R_0x91c, MASKDWORD, dm->radar_detect_reg_91c);
  59. odm_set_bb_reg(dm, R_0x920, MASKDWORD, dm->radar_detect_reg_920);
  60. odm_set_bb_reg(dm, R_0x924, MASKDWORD, dm->radar_detect_reg_924);
  61. }
  62. /* @Init radar detection parameters, called after ch, bw is set */
  63. void phydm_radar_detect_enable(void *dm_void)
  64. {
  65. struct dm_struct *dm = (struct dm_struct *)dm_void;
  66. struct _DFS_STATISTICS *dfs = &dm->dfs;
  67. u8 region_domain = dm->dfs_region_domain;
  68. u8 c_channel = *dm->channel;
  69. u8 band_width = *dm->band_width;
  70. u8 enable = 0;
  71. u8 short_pw_upperbound = 0;
  72. PHYDM_DBG(dm, DBG_DFS, "test, region_domain = %d\n", region_domain);
  73. if (region_domain == PHYDM_DFS_DOMAIN_UNKNOWN) {
  74. PHYDM_DBG(dm, DBG_DFS, "PHYDM_DFS_DOMAIN_UNKNOWN\n");
  75. goto exit;
  76. }
  77. if (dm->support_ic_type & (ODM_RTL8821 | ODM_RTL8812 | ODM_RTL8881A)) {
  78. odm_set_bb_reg(dm, R_0x814, 0x3fffffff, 0x04cc4d10);
  79. odm_set_bb_reg(dm, R_0x834, MASKBYTE0, 0x06);
  80. if (dm->radar_detect_dbg_parm_en) {
  81. phydm_radar_detect_with_dbg_parm(dm);
  82. enable = 1;
  83. goto exit;
  84. }
  85. if (region_domain == PHYDM_DFS_DOMAIN_ETSI) {
  86. odm_set_bb_reg(dm, R_0x918, MASKDWORD, 0x1c17ecdf);
  87. odm_set_bb_reg(dm, R_0x924, MASKDWORD, 0x01528500);
  88. odm_set_bb_reg(dm, R_0x91c, MASKDWORD, 0x0fa21a20);
  89. odm_set_bb_reg(dm, R_0x920, MASKDWORD, 0xe0f69204);
  90. } else if (region_domain == PHYDM_DFS_DOMAIN_MKK) {
  91. odm_set_bb_reg(dm, R_0x924, MASKDWORD, 0x01528500);
  92. odm_set_bb_reg(dm, R_0x920, MASKDWORD, 0xe0d67234);
  93. if (c_channel >= 52 && c_channel <= 64) {
  94. odm_set_bb_reg(dm, R_0x918, MASKDWORD,
  95. 0x1c16ecdf);
  96. odm_set_bb_reg(dm, R_0x91c, MASKDWORD,
  97. 0x0f141a20);
  98. } else {
  99. odm_set_bb_reg(dm, R_0x918, MASKDWORD,
  100. 0x1c16acdf);
  101. if (band_width == CHANNEL_WIDTH_20)
  102. odm_set_bb_reg(dm, R_0x91c, MASKDWORD,
  103. 0x64721a20);
  104. else
  105. odm_set_bb_reg(dm, R_0x91c, MASKDWORD,
  106. 0x68721a20);
  107. }
  108. } else if (region_domain == PHYDM_DFS_DOMAIN_FCC) {
  109. odm_set_bb_reg(dm, R_0x918, MASKDWORD, 0x1c16acdf);
  110. odm_set_bb_reg(dm, R_0x924, MASKDWORD, 0x01528500);
  111. odm_set_bb_reg(dm, R_0x920, MASKDWORD, 0xe0d67231);
  112. if (band_width == CHANNEL_WIDTH_20)
  113. odm_set_bb_reg(dm, R_0x91c, MASKDWORD,
  114. 0x64741a20);
  115. else
  116. odm_set_bb_reg(dm, R_0x91c, MASKDWORD,
  117. 0x68741a20);
  118. } else {
  119. /* not supported */
  120. PHYDM_DBG(dm, DBG_DFS,
  121. "Unsupported dfs_region_domain:%d\n",
  122. region_domain);
  123. goto exit;
  124. }
  125. } else if (dm->support_ic_type &
  126. (ODM_RTL8814A | ODM_RTL8822B | ODM_RTL8821C)) {
  127. /*@for 8822B RXHP H2L, since L will always cause DFS FRD
  128. if (dm->support_ic_type & (ODM_RTL8822B)) {
  129. odm_set_bb_reg(dm, 0x8d8, MASKDWORD, 0x29035612);
  130. odm_set_bb_reg(dm, 0x8cc, MASKDWORD, 0x08108492);
  131. }
  132. */
  133. odm_set_bb_reg(dm, R_0x814, 0x3fffffff, 0x04cc4d10);
  134. odm_set_bb_reg(dm, R_0x834, MASKBYTE0, 0x06);
  135. /* @8822B only, when BW = 20M, DFIR output is 40Mhz,
  136. * but DFS input is 80MMHz, so it need to upgrade to 80MHz
  137. */
  138. if (dm->support_ic_type & (ODM_RTL8822B | ODM_RTL8821C)) {
  139. if (band_width == CHANNEL_WIDTH_20)
  140. odm_set_bb_reg(dm, R_0x1984, BIT(26), 1);
  141. else
  142. odm_set_bb_reg(dm, R_0x1984, BIT(26), 0);
  143. }
  144. if (dm->radar_detect_dbg_parm_en) {
  145. phydm_radar_detect_with_dbg_parm(dm);
  146. enable = 1;
  147. goto exit;
  148. }
  149. if (region_domain == PHYDM_DFS_DOMAIN_ETSI) {
  150. odm_set_bb_reg(dm, R_0x918, MASKDWORD, 0x1c16acdf);
  151. odm_set_bb_reg(dm, R_0x924, MASKDWORD, 0x095a8500);
  152. odm_set_bb_reg(dm, R_0x91c, MASKDWORD, 0x0fa21a20);
  153. odm_set_bb_reg(dm, R_0x920, MASKDWORD, 0xe0f57204);
  154. } else if (region_domain == PHYDM_DFS_DOMAIN_MKK) {
  155. odm_set_bb_reg(dm, R_0x924, MASKDWORD, 0x095a8500);
  156. odm_set_bb_reg(dm, R_0x920, MASKDWORD, 0xe0d67234);
  157. if (c_channel >= 52 && c_channel <= 64) {
  158. odm_set_bb_reg(dm, R_0x918, MASKDWORD,
  159. 0x1c16ecdf);
  160. odm_set_bb_reg(dm, R_0x91c, MASKDWORD,
  161. 0x0f141a20);
  162. } else {
  163. odm_set_bb_reg(dm, R_0x918, MASKDWORD,
  164. 0x1c166cdf);
  165. if (band_width == CHANNEL_WIDTH_20)
  166. odm_set_bb_reg(dm, R_0x91c, MASKDWORD,
  167. 0x64721a20);
  168. else
  169. odm_set_bb_reg(dm, R_0x91c, MASKDWORD,
  170. 0x68721a20);
  171. }
  172. } else if (region_domain == PHYDM_DFS_DOMAIN_FCC) {
  173. odm_set_bb_reg(dm, R_0x918, MASKDWORD, 0x1c176cdf);
  174. odm_set_bb_reg(dm, R_0x924, MASKDWORD, 0x095a8400);
  175. odm_set_bb_reg(dm, R_0x920, MASKDWORD, 0xe076d231);
  176. if (band_width == CHANNEL_WIDTH_20)
  177. odm_set_bb_reg(dm, R_0x91c, MASKDWORD,
  178. 0x64901a20);
  179. else
  180. odm_set_bb_reg(dm, R_0x91c, MASKDWORD,
  181. 0x62901a20);
  182. } else {
  183. /* not supported */
  184. PHYDM_DBG(dm, DBG_DFS,
  185. "Unsupported dfs_region_domain:%d\n",
  186. region_domain);
  187. goto exit;
  188. }
  189. /*RXHP low corner will extend the pulse width,
  190. *so we need to increase the upper bound.
  191. */
  192. if (dm->support_ic_type & (ODM_RTL8822B | ODM_RTL8821C)) {
  193. if (odm_get_bb_reg(dm, 0x8d8,
  194. BIT28 | BIT27 | BIT26) == 0) {
  195. short_pw_upperbound =
  196. (u8)odm_get_bb_reg(dm, 0x91c,
  197. BIT23 | BIT22 |
  198. BIT21 | BIT20);
  199. if ((short_pw_upperbound + 4) > 15)
  200. odm_set_bb_reg(dm, 0x91c,
  201. BIT23 | BIT22 |
  202. BIT21 | BIT20, 15);
  203. else
  204. odm_set_bb_reg(dm, 0x91c,
  205. BIT23 | BIT22 |
  206. BIT21 | BIT20,
  207. short_pw_upperbound + 4);
  208. }
  209. /*@if peak index -1~+1, use original NB method*/
  210. odm_set_bb_reg(dm, 0x19e4, 0x003C0000, 13);
  211. odm_set_bb_reg(dm, 0x924, 0x70000, 0);
  212. }
  213. if (dm->support_ic_type & (ODM_RTL8881A))
  214. odm_set_bb_reg(dm, 0xb00, 0xc0000000, 3);
  215. /*@for 8814 new dfs mechanism setting*/
  216. if (dm->support_ic_type &
  217. (ODM_RTL8814A | ODM_RTL8822B | ODM_RTL8821C)) {
  218. /*Turn off dfs scaling factor*/
  219. odm_set_bb_reg(dm, 0x19e4, 0x1fff, 0x0c00);
  220. /*NonDC peak_th = 2times DC peak_th*/
  221. odm_set_bb_reg(dm, 0x19e4, 0x30000, 1);
  222. /*power for debug and auto test flow latch after ST*/
  223. odm_set_bb_reg(dm, 0x9f8, 0xc0000000, 3);
  224. /*@low pulse width radar pattern will cause wrong drop*/
  225. /*@disable peak index should the same
  226. *during the same short pulse (new mechan)
  227. */
  228. odm_set_bb_reg(dm, 0x9f4, 0x80000000, 0);
  229. /*@disable peak index should the same
  230. *during the same short pulse (old mechan)
  231. */
  232. odm_set_bb_reg(dm, 0x924, 0x20000000, 0);
  233. /*@if peak index diff >=2, then drop the result*/
  234. odm_set_bb_reg(dm, 0x19e4, 0xe000, 2);
  235. if (region_domain == 2) {
  236. if ((c_channel >= 52) && (c_channel <= 64)) {
  237. /*pulse width hist th setting*/
  238. /*th1=2*04us*/
  239. odm_set_bb_reg(dm, 0x19e4,
  240. 0xff000000, 2);
  241. /*th2 = 3*0.4us, th3 = 4*0.4us
  242. *th4 = 7*0.4, th5 = 34*0.4
  243. */
  244. odm_set_bb_reg(dm, 0x19e8,
  245. MASKDWORD, 0x22070403);
  246. /*PRI hist th setting*/
  247. /*th1=42*32us*/
  248. odm_set_bb_reg(dm, 0x19b8,
  249. 0x00007f80, 42);
  250. /*th2=47*32us, th3=115*32us,
  251. *th4=123*32us, th5=130*32us
  252. */
  253. odm_set_bb_reg(dm, 0x19ec,
  254. MASKDWORD, 0x827b732f);
  255. } else{
  256. /*pulse width hist th setting*/
  257. /*th1=2*04us*/
  258. odm_set_bb_reg(dm, 0x19e4,
  259. 0xff000000, 1);
  260. /*th2 = 13*0.4us, th3 = 26*0.4us
  261. *th4 = 75*0.4us, th5 = 255*0.4us
  262. */
  263. odm_set_bb_reg(dm, 0x19e8,
  264. MASKDWORD, 0xff4b1a0d);
  265. /*PRI hist th setting*/
  266. /*th1=4*32us*/
  267. odm_set_bb_reg(dm, 0x19b8,
  268. 0x00007f80, 4);
  269. /*th2=8*32us, th3=16*32us,
  270. *th4=32*32us, th5=128*32=4096us
  271. */
  272. odm_set_bb_reg(dm, 0x19ec,
  273. MASKDWORD, 0x80201008);
  274. }
  275. }
  276. /*@ETSI*/
  277. else if (region_domain == 3) {
  278. /*pulse width hist th setting*/
  279. /*th1=2*04us*/
  280. odm_set_bb_reg(dm, 0x19e4, 0xff000000, 1);
  281. odm_set_bb_reg(dm, 0x19e8,
  282. MASKDWORD, 0x68260d06);
  283. /*PRI hist th setting*/
  284. /*th1=7*32us*/
  285. odm_set_bb_reg(dm, 0x19b8, 0x00007f80, 7);
  286. /*th2=40*32us, th3=80*32us,
  287. *th4=110*32us, th5=157*32=5024
  288. */
  289. odm_set_bb_reg(dm, 0x19ec,
  290. MASKDWORD, 0x9d6e2010);
  291. }
  292. /*@FCC*/
  293. else if (region_domain == 1) {
  294. /*pulse width hist th setting*/
  295. /*th1=2*04us*/
  296. odm_set_bb_reg(dm, 0x19e4, 0xff000000, 2);
  297. /*th2 = 13*0.4us, th3 = 26*0.4us,
  298. *th4 = 75*0.4us, th5 = 255*0.4us
  299. */
  300. odm_set_bb_reg(dm, 0x19e8,
  301. MASKDWORD, 0xff4b1a0d);
  302. /*PRI hist th setting*/
  303. /*th1=4*32us*/
  304. odm_set_bb_reg(dm, 0x19b8, 0x00007f80, 4);
  305. /*th2=8*32us, th3=21*32us,
  306. *th4=32*32us, th5=96*32=3072
  307. */
  308. if (band_width == CHANNEL_WIDTH_20)
  309. odm_set_bb_reg(dm, 0x19ec,
  310. MASKDWORD, 0x60282010);
  311. else
  312. odm_set_bb_reg(dm, 0x19ec,
  313. MASKDWORD, 0x60282420);
  314. } else {
  315. }
  316. }
  317. } else {
  318. /*not supported IC type*/
  319. PHYDM_DBG(dm, DBG_DFS, "Unsupported IC type:%d\n",
  320. dm->support_ic_type);
  321. goto exit;
  322. }
  323. enable = 1;
  324. dfs->st_l2h_cur = (u8)odm_get_bb_reg(dm, R_0x91c, 0x000000ff);
  325. dfs->pwdb_th_cur = (u8)odm_get_bb_reg(dm, R_0x918, 0x00001f00);
  326. dfs->peak_th = (u8)odm_get_bb_reg(dm, R_0x918, 0x00030000);
  327. dfs->short_pulse_cnt_th = (u8)odm_get_bb_reg(dm, R_0x920, 0x000f0000);
  328. dfs->long_pulse_cnt_th = (u8)odm_get_bb_reg(dm, R_0x920, 0x00f00000);
  329. dfs->peak_window = (u8)odm_get_bb_reg(dm, R_0x920, 0x00000300);
  330. dfs->three_peak_opt = (u8)odm_get_bb_reg(dm, 0x924, 0x00000180);
  331. dfs->three_peak_th2 = (u8)odm_get_bb_reg(dm, 0x924, 0x00007000);
  332. phydm_dfs_parameter_init(dm);
  333. exit:
  334. if (enable) {
  335. phydm_radar_detect_reset(dm);
  336. PHYDM_DBG(dm, DBG_DFS, "on cch:%u, bw:%u\n", c_channel,
  337. band_width);
  338. } else
  339. phydm_radar_detect_disable(dm);
  340. }
  341. void phydm_dfs_parameter_init(void *dm_void)
  342. {
  343. struct dm_struct *dm = (struct dm_struct *)dm_void;
  344. struct _DFS_STATISTICS *dfs = &dm->dfs;
  345. u8 i;
  346. dfs->fa_mask_th = 30;
  347. dfs->force_TP_mode = 0;
  348. dfs->det_print = 0;
  349. dfs->det_print2 = 0;
  350. dfs->print_hist_rpt = 0;
  351. dfs->hist_cond_on = 1;
  352. dfs->st_l2h_min = 0x20;
  353. dfs->st_l2h_max = 0x4e;
  354. dfs->pwdb_scalar_factor = 12;
  355. dfs->pwdb_th = 8;
  356. for (i = 0; i < 5; i++) {
  357. dfs->pulse_flag_hist[i] = 0;
  358. dfs->pulse_type_hist[i] = 0;
  359. dfs->radar_det_mask_hist[i] = 0;
  360. dfs->fa_inc_hist[i] = 0;
  361. }
  362. /*@for dfs histogram*/
  363. dfs->pri_hist_th = 5;
  364. dfs->pri_sum_g1_th = 9;
  365. dfs->pri_sum_g5_th = 4;
  366. dfs->pri_sum_g1_fcc_th = 4; /*@FCC Type6*/
  367. dfs->pri_sum_g3_fcc_th = 6;
  368. dfs->pri_sum_safe_th = 50;
  369. dfs->pri_sum_safe_fcc_th = 110; /*@30 for AP*/
  370. dfs->pri_sum_type4_th = 16;
  371. dfs->pri_sum_type6_th = 12;
  372. dfs->pri_sum_g5_under_g1_th = 0;
  373. dfs->pri_pw_diff_th = 4;
  374. dfs->pri_pw_diff_fcc_th = 8;
  375. dfs->pri_pw_diff_fcc_idle_th = 2;
  376. dfs->pri_pw_diff_w53_th = 10;
  377. dfs->pw_std_th = 7; /*@FCC Type4*/
  378. dfs->pw_std_idle_th = 10;
  379. dfs->pri_std_th = 6; /*@FCC Type3,4,6*/
  380. dfs->pri_std_idle_th = 10;
  381. dfs->pri_type1_upp_fcc_th = 110;
  382. dfs->pri_type1_low_fcc_th = 50;
  383. dfs->pri_type1_cen_fcc_th = 70;
  384. dfs->pw_g0_th = 8;
  385. dfs->pw_long_lower_th = 6; /*@7->6*/
  386. dfs->pri_long_upper_th = 30;
  387. dfs->pw_long_lower_20m_th = 7; /*@7 for AP*/
  388. dfs->pw_long_sum_upper_th = 60;
  389. dfs->type4_pw_max_cnt = 7;
  390. dfs->type4_safe_pri_sum_th = 5;
  391. }
  392. void phydm_dfs_dynamic_setting(
  393. void *dm_void)
  394. {
  395. struct dm_struct *dm = (struct dm_struct *)dm_void;
  396. struct _DFS_STATISTICS *dfs = &dm->dfs;
  397. u8 peak_th_cur = 0, short_pulse_cnt_th_cur = 0;
  398. u8 long_pulse_cnt_th_cur = 0, three_peak_opt_cur = 0;
  399. u8 three_peak_th2_cur = 0;
  400. u8 peak_window_cur = 0;
  401. u8 region_domain = dm->dfs_region_domain;
  402. u8 c_channel = *dm->channel;
  403. if (dm->rx_tp + dm->tx_tp <= 2) {
  404. dfs->idle_mode = 1;
  405. if (dfs->force_TP_mode)
  406. dfs->idle_mode = 0;
  407. } else {
  408. dfs->idle_mode = 0;
  409. }
  410. if (dfs->idle_mode == 1) { /*@idle (no traffic)*/
  411. peak_th_cur = 3;
  412. short_pulse_cnt_th_cur = 6;
  413. long_pulse_cnt_th_cur = 9;
  414. peak_window_cur = 2;
  415. three_peak_opt_cur = 0;
  416. three_peak_th2_cur = 2;
  417. if (region_domain == PHYDM_DFS_DOMAIN_MKK) {
  418. if (c_channel >= 52 && c_channel <= 64) {
  419. short_pulse_cnt_th_cur = 14;
  420. long_pulse_cnt_th_cur = 15;
  421. three_peak_th2_cur = 0;
  422. } else {
  423. short_pulse_cnt_th_cur = 6;
  424. three_peak_th2_cur = 0;
  425. long_pulse_cnt_th_cur = 10;
  426. }
  427. } else if (region_domain == PHYDM_DFS_DOMAIN_FCC) {
  428. three_peak_th2_cur = 0;
  429. } else if (region_domain == PHYDM_DFS_DOMAIN_ETSI) {
  430. long_pulse_cnt_th_cur = 15;
  431. if (phydm_dfs_is_meteorology_channel(dm)) {
  432. /*need to add check cac end condition*/
  433. peak_th_cur = 2;
  434. three_peak_opt_cur = 0;
  435. three_peak_th2_cur = 0;
  436. short_pulse_cnt_th_cur = 7;
  437. } else {
  438. three_peak_opt_cur = 0;
  439. three_peak_th2_cur = 0;
  440. short_pulse_cnt_th_cur = 7;
  441. }
  442. } else /*@default: FCC*/
  443. three_peak_th2_cur = 0;
  444. } else { /*@in service (with TP)*/
  445. peak_th_cur = 2;
  446. short_pulse_cnt_th_cur = 6;
  447. long_pulse_cnt_th_cur = 7;
  448. peak_window_cur = 2;
  449. three_peak_opt_cur = 0;
  450. three_peak_th2_cur = 2;
  451. if (region_domain == PHYDM_DFS_DOMAIN_MKK) {
  452. if (c_channel >= 52 && c_channel <= 64) {
  453. long_pulse_cnt_th_cur = 15;
  454. /*@for high duty cycle*/
  455. short_pulse_cnt_th_cur = 5;
  456. three_peak_th2_cur = 0;
  457. } else {
  458. three_peak_opt_cur = 0;
  459. three_peak_th2_cur = 0;
  460. long_pulse_cnt_th_cur = 8;
  461. }
  462. } else if (region_domain == PHYDM_DFS_DOMAIN_FCC) {
  463. long_pulse_cnt_th_cur = 5; /*for 80M FCC*/
  464. short_pulse_cnt_th_cur = 5; /*for 80M FCC*/
  465. } else if (region_domain == PHYDM_DFS_DOMAIN_ETSI) {
  466. long_pulse_cnt_th_cur = 15;
  467. short_pulse_cnt_th_cur = 5;
  468. three_peak_opt_cur = 0;
  469. }
  470. }
  471. if (dfs->peak_th != peak_th_cur)
  472. odm_set_bb_reg(dm, 0x918, 0x00030000, peak_th_cur);
  473. if (dfs->short_pulse_cnt_th != short_pulse_cnt_th_cur)
  474. odm_set_bb_reg(dm, 0x920, 0x000f0000, short_pulse_cnt_th_cur);
  475. if (dfs->long_pulse_cnt_th != long_pulse_cnt_th_cur)
  476. odm_set_bb_reg(dm, 0x920, 0x00f00000, long_pulse_cnt_th_cur);
  477. if (dfs->peak_window != peak_window_cur)
  478. odm_set_bb_reg(dm, 0x920, 0x00000300, peak_window_cur);
  479. if (dfs->three_peak_opt != three_peak_opt_cur)
  480. odm_set_bb_reg(dm, 0x924, 0x00000180, three_peak_opt_cur);
  481. if (dfs->three_peak_th2 != three_peak_th2_cur)
  482. odm_set_bb_reg(dm, 0x924, 0x00007000, three_peak_th2_cur);
  483. dfs->peak_th = peak_th_cur;
  484. dfs->short_pulse_cnt_th = short_pulse_cnt_th_cur;
  485. dfs->long_pulse_cnt_th = long_pulse_cnt_th_cur;
  486. dfs->peak_window = peak_window_cur;
  487. dfs->three_peak_opt = three_peak_opt_cur;
  488. dfs->three_peak_th2 = three_peak_th2_cur;
  489. }
  490. boolean
  491. phydm_radar_detect_dm_check(
  492. void *dm_void)
  493. {
  494. struct dm_struct *dm = (struct dm_struct *)dm_void;
  495. struct _DFS_STATISTICS *dfs = &dm->dfs;
  496. u8 region_domain = dm->dfs_region_domain, index = 0;
  497. u16 i = 0, j = 0, k = 0, fa_count_cur = 0, fa_count_inc = 0;
  498. u16 total_fa_in_hist = 0, pre_post_now_acc_fa_in_hist = 0;
  499. u16 max_fa_in_hist = 0, vht_crc_ok_cnt_cur = 0;
  500. u16 vht_crc_ok_cnt_inc = 0, ht_crc_ok_cnt_cur = 0;
  501. u16 ht_crc_ok_cnt_inc = 0, leg_crc_ok_cnt_cur = 0;
  502. u16 leg_crc_ok_cnt_inc = 0;
  503. u16 total_crc_ok_cnt_inc = 0, short_pulse_cnt_cur = 0;
  504. u16 short_pulse_cnt_inc = 0, long_pulse_cnt_cur = 0;
  505. u16 long_pulse_cnt_inc = 0, total_pulse_count_inc = 0;
  506. u32 regf98_value = 0, reg918_value = 0, reg91c_value = 0;
  507. u32 reg920_value = 0, reg924_value = 0;
  508. boolean tri_short_pulse = 0, tri_long_pulse = 0, radar_type = 0;
  509. boolean fault_flag_det = 0, fault_flag_psd = 0, fa_flag = 0;
  510. boolean radar_detected = 0;
  511. u8 st_l2h_new = 0, fa_mask_th = 0, sum = 0;
  512. u8 c_channel = *dm->channel;
  513. /*@Get FA count during past 100ms*/
  514. fa_count_cur = (u16)odm_get_bb_reg(dm, R_0xf48, 0x0000ffff);
  515. if (dfs->fa_count_pre == 0)
  516. fa_count_inc = 0;
  517. else if (fa_count_cur >= dfs->fa_count_pre)
  518. fa_count_inc = fa_count_cur - dfs->fa_count_pre;
  519. else
  520. fa_count_inc = fa_count_cur;
  521. dfs->fa_count_pre = fa_count_cur;
  522. dfs->fa_inc_hist[dfs->mask_idx] = fa_count_inc;
  523. for (i = 0; i < 5; i++) {
  524. total_fa_in_hist = total_fa_in_hist + dfs->fa_inc_hist[i];
  525. if (dfs->fa_inc_hist[i] > max_fa_in_hist)
  526. max_fa_in_hist = dfs->fa_inc_hist[i];
  527. }
  528. if (dfs->mask_idx >= 2)
  529. index = dfs->mask_idx - 2;
  530. else
  531. index = 5 + dfs->mask_idx - 2;
  532. if (index == 0) {
  533. pre_post_now_acc_fa_in_hist = dfs->fa_inc_hist[index] +
  534. dfs->fa_inc_hist[index + 1] +
  535. dfs->fa_inc_hist[4];
  536. } else if (index == 4) {
  537. pre_post_now_acc_fa_in_hist = dfs->fa_inc_hist[index] +
  538. dfs->fa_inc_hist[0] +
  539. dfs->fa_inc_hist[index - 1];
  540. } else {
  541. pre_post_now_acc_fa_in_hist = dfs->fa_inc_hist[index] +
  542. dfs->fa_inc_hist[index + 1] +
  543. dfs->fa_inc_hist[index - 1];
  544. }
  545. /*@Get VHT CRC32 ok count during past 100ms*/
  546. vht_crc_ok_cnt_cur = (u16)odm_get_bb_reg(dm, R_0xf0c, 0x00003fff);
  547. if (vht_crc_ok_cnt_cur >= dfs->vht_crc_ok_cnt_pre) {
  548. vht_crc_ok_cnt_inc = vht_crc_ok_cnt_cur -
  549. dfs->vht_crc_ok_cnt_pre;
  550. } else {
  551. vht_crc_ok_cnt_inc = vht_crc_ok_cnt_cur;
  552. }
  553. dfs->vht_crc_ok_cnt_pre = vht_crc_ok_cnt_cur;
  554. /*@Get HT CRC32 ok count during past 100ms*/
  555. ht_crc_ok_cnt_cur = (u16)odm_get_bb_reg(dm, R_0xf10, 0x00003fff);
  556. if (ht_crc_ok_cnt_cur >= dfs->ht_crc_ok_cnt_pre)
  557. ht_crc_ok_cnt_inc = ht_crc_ok_cnt_cur - dfs->ht_crc_ok_cnt_pre;
  558. else
  559. ht_crc_ok_cnt_inc = ht_crc_ok_cnt_cur;
  560. dfs->ht_crc_ok_cnt_pre = ht_crc_ok_cnt_cur;
  561. /*@Get Legacy CRC32 ok count during past 100ms*/
  562. leg_crc_ok_cnt_cur = (u16)odm_get_bb_reg(dm, R_0xf14, 0x00003fff);
  563. if (leg_crc_ok_cnt_cur >= dfs->leg_crc_ok_cnt_pre)
  564. leg_crc_ok_cnt_inc = leg_crc_ok_cnt_cur - dfs->leg_crc_ok_cnt_pre;
  565. else
  566. leg_crc_ok_cnt_inc = leg_crc_ok_cnt_cur;
  567. dfs->leg_crc_ok_cnt_pre = leg_crc_ok_cnt_cur;
  568. if (vht_crc_ok_cnt_cur == 0x3fff ||
  569. ht_crc_ok_cnt_cur == 0x3fff ||
  570. leg_crc_ok_cnt_cur == 0x3fff) {
  571. phydm_reset_bb_hw_cnt_ac(dm);
  572. /*@*/
  573. }
  574. total_crc_ok_cnt_inc = vht_crc_ok_cnt_inc +
  575. ht_crc_ok_cnt_inc +
  576. leg_crc_ok_cnt_inc;
  577. /*@Get short pulse count, need carefully handle the counter overflow*/
  578. regf98_value = odm_get_bb_reg(dm, R_0xf98, 0xffffffff);
  579. short_pulse_cnt_cur = (u16)(regf98_value & 0x000000ff);
  580. if (short_pulse_cnt_cur >= dfs->short_pulse_cnt_pre) {
  581. short_pulse_cnt_inc = short_pulse_cnt_cur -
  582. dfs->short_pulse_cnt_pre;
  583. } else {
  584. short_pulse_cnt_inc = short_pulse_cnt_cur;
  585. }
  586. dfs->short_pulse_cnt_pre = short_pulse_cnt_cur;
  587. /*@Get long pulse count, need carefully handle the counter overflow*/
  588. long_pulse_cnt_cur = (u16)((regf98_value & 0x0000ff00) >> 8);
  589. if (long_pulse_cnt_cur >= dfs->long_pulse_cnt_pre) {
  590. long_pulse_cnt_inc = long_pulse_cnt_cur -
  591. dfs->long_pulse_cnt_pre;
  592. } else {
  593. long_pulse_cnt_inc = long_pulse_cnt_cur;
  594. }
  595. dfs->long_pulse_cnt_pre = long_pulse_cnt_cur;
  596. total_pulse_count_inc = short_pulse_cnt_inc + long_pulse_cnt_inc;
  597. if (dfs->det_print) {
  598. PHYDM_DBG(dm, DBG_DFS,
  599. "===============================================\n");
  600. PHYDM_DBG(dm, DBG_DFS,
  601. "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",
  602. total_crc_ok_cnt_inc, vht_crc_ok_cnt_inc,
  603. ht_crc_ok_cnt_inc, leg_crc_ok_cnt_inc, fa_count_inc);
  604. PHYDM_DBG(dm, DBG_DFS,
  605. "Init_Gain[%x] 0x91c[%x] 0xf98[%08x] short_pulse_cnt_inc[%d] long_pulse_cnt_inc[%d]\n",
  606. dfs->igi_cur, dfs->st_l2h_cur, regf98_value,
  607. short_pulse_cnt_inc, long_pulse_cnt_inc);
  608. PHYDM_DBG(dm, DBG_DFS, "Throughput: %dMbps\n",
  609. dm->rx_tp + dm->tx_tp);
  610. reg918_value = odm_get_bb_reg(dm, R_0x918,
  611. 0xffffffff);
  612. reg91c_value = odm_get_bb_reg(dm, R_0x91c,
  613. 0xffffffff);
  614. reg920_value = odm_get_bb_reg(dm, R_0x920,
  615. 0xffffffff);
  616. reg924_value = odm_get_bb_reg(dm, R_0x924,
  617. 0xffffffff);
  618. PHYDM_DBG(dm, DBG_DFS,
  619. "0x918[%08x] 0x91c[%08x] 0x920[%08x] 0x924[%08x]\n",
  620. reg918_value, reg91c_value,
  621. reg920_value, reg924_value);
  622. PHYDM_DBG(dm, DBG_DFS,
  623. "dfs_regdomain = %d, dbg_mode = %d, idle_mode = %d, print_hist_rpt = %d, hist_cond_on = %d\n",
  624. region_domain, dfs->dbg_mode,
  625. dfs->idle_mode, dfs->print_hist_rpt,
  626. dfs->hist_cond_on);
  627. }
  628. tri_short_pulse = (regf98_value & BIT(17)) ? 1 : 0;
  629. tri_long_pulse = (regf98_value & BIT(19)) ? 1 : 0;
  630. if (tri_short_pulse) {
  631. odm_set_bb_reg(dm, R_0x924, BIT(15), 0);
  632. odm_set_bb_reg(dm, R_0x924, BIT(15), 1);
  633. }
  634. if (tri_long_pulse) {
  635. odm_set_bb_reg(dm, R_0x924, BIT(15), 0);
  636. odm_set_bb_reg(dm, R_0x924, BIT(15), 1);
  637. if (region_domain == PHYDM_DFS_DOMAIN_MKK) {
  638. if (c_channel >= 52 && c_channel <= 64) {
  639. tri_long_pulse = 0;
  640. }
  641. }
  642. if (region_domain == PHYDM_DFS_DOMAIN_ETSI) {
  643. tri_long_pulse = 0;
  644. }
  645. }
  646. st_l2h_new = dfs->st_l2h_cur;
  647. dfs->pulse_flag_hist[dfs->mask_idx] = tri_short_pulse | tri_long_pulse;
  648. dfs->pulse_type_hist[dfs->mask_idx] = (tri_long_pulse) ? 1 : 0;
  649. /* PSD(not ready) */
  650. fault_flag_det = 0;
  651. fault_flag_psd = 0;
  652. fa_flag = 0;
  653. if (region_domain == PHYDM_DFS_DOMAIN_ETSI) {
  654. fa_mask_th = dfs->fa_mask_th + 20;
  655. } else {
  656. fa_mask_th = dfs->fa_mask_th;
  657. }
  658. if (max_fa_in_hist >= fa_mask_th ||
  659. total_fa_in_hist >= fa_mask_th ||
  660. pre_post_now_acc_fa_in_hist >= fa_mask_th ||
  661. dfs->igi_cur >= 0x30) {
  662. st_l2h_new = dfs->st_l2h_max;
  663. dfs->radar_det_mask_hist[index] = 1;
  664. if (dfs->pulse_flag_hist[index] == 1) {
  665. dfs->pulse_flag_hist[index] = 0;
  666. if (dfs->det_print2) {
  667. PHYDM_DBG(dm, DBG_DFS,
  668. "Radar is masked : FA mask\n");
  669. }
  670. }
  671. fa_flag = 1;
  672. } else {
  673. dfs->radar_det_mask_hist[index] = 0;
  674. }
  675. if (dfs->det_print) {
  676. PHYDM_DBG(dm, DBG_DFS, "mask_idx: %d\n", dfs->mask_idx);
  677. PHYDM_DBG(dm, DBG_DFS, "radar_det_mask_hist: ");
  678. for (i = 0; i < 5; i++)
  679. PHYDM_DBG(dm, DBG_DFS, "%d ",
  680. dfs->radar_det_mask_hist[i]);
  681. PHYDM_DBG(dm, DBG_DFS, "pulse_flag_hist: ");
  682. for (i = 0; i < 5; i++)
  683. PHYDM_DBG(dm, DBG_DFS, "%d ", dfs->pulse_flag_hist[i]);
  684. PHYDM_DBG(dm, DBG_DFS, "fa_inc_hist: ");
  685. for (i = 0; i < 5; i++)
  686. PHYDM_DBG(dm, DBG_DFS, "%d ", dfs->fa_inc_hist[i]);
  687. PHYDM_DBG(dm, DBG_DFS,
  688. "\nfa_mask_th: %d max_fa_in_hist: %d total_fa_in_hist: %d pre_post_now_acc_fa_in_hist: %d ",
  689. fa_mask_th, max_fa_in_hist, total_fa_in_hist,
  690. pre_post_now_acc_fa_in_hist);
  691. }
  692. sum = 0;
  693. for (k = 0; k < 5; k++) {
  694. if (dfs->radar_det_mask_hist[k] == 1)
  695. sum++;
  696. }
  697. if (dfs->mask_hist_checked <= 5)
  698. dfs->mask_hist_checked++;
  699. if (dfs->mask_hist_checked >= 5 && dfs->pulse_flag_hist[index]) {
  700. if (sum <= 2) {
  701. if (dfs->hist_cond_on) {
  702. /*return the value from hist_radar_detected*/
  703. radar_detected = phydm_dfs_hist_log(dm, index);
  704. } else {
  705. if (dfs->pulse_type_hist[index] == 0)
  706. dfs->radar_type = 0;
  707. else if (dfs->pulse_type_hist[index] == 1)
  708. dfs->radar_type = 1;
  709. radar_detected = 1;
  710. PHYDM_DBG(dm, DBG_DFS,
  711. "Detected type %d radar signal!\n",
  712. dfs->radar_type);
  713. }
  714. } else {
  715. fault_flag_det = 1;
  716. if (dfs->det_print2) {
  717. PHYDM_DBG(dm, DBG_DFS,
  718. "Radar is masked : mask_hist large than thd\n");
  719. }
  720. }
  721. }
  722. dfs->mask_idx++;
  723. if (dfs->mask_idx == 5)
  724. dfs->mask_idx = 0;
  725. if (fault_flag_det == 0 && fault_flag_psd == 0 && fa_flag == 0) {
  726. if (dfs->igi_cur < 0x30) {
  727. st_l2h_new = dfs->st_l2h_min;
  728. }
  729. }
  730. if (st_l2h_new != dfs->st_l2h_cur) {
  731. if (st_l2h_new < dfs->st_l2h_min) {
  732. dfs->st_l2h_cur = dfs->st_l2h_min;
  733. } else if (st_l2h_new > dfs->st_l2h_max)
  734. dfs->st_l2h_cur = dfs->st_l2h_max;
  735. else
  736. dfs->st_l2h_cur = st_l2h_new;
  737. /*odm_set_bb_reg(dm, R_0x91c, 0xff, dfs->st_l2h_cur);*/
  738. dfs->pwdb_th_cur = ((int)dfs->st_l2h_cur - (int)dfs->igi_cur)
  739. / 2 + dfs->pwdb_scalar_factor;
  740. /*@limit the pwdb value to absolute lower bound 8*/
  741. dfs->pwdb_th_cur = MAX_2(dfs->pwdb_th_cur, (int)dfs->pwdb_th);
  742. /*@limit the pwdb value to absolute upper bound 0x1f*/
  743. dfs->pwdb_th_cur = MIN_2(dfs->pwdb_th_cur, 0x1f);
  744. odm_set_bb_reg(dm, R_0x918, 0x00001f00, dfs->pwdb_th_cur);
  745. }
  746. if (dfs->det_print) {
  747. PHYDM_DBG(dm, DBG_DFS,
  748. "fault_flag_det[%d], fault_flag_psd[%d], DFS_detected [%d]\n",
  749. fault_flag_det, fault_flag_psd, radar_detected);
  750. }
  751. return radar_detected;
  752. }
  753. void phydm_dfs_histogram_radar_distinguish(
  754. void *dm_void)
  755. {
  756. struct dm_struct *dm = (struct dm_struct *)dm_void;
  757. struct _DFS_STATISTICS *dfs = &dm->dfs;
  758. u8 region_domain = dm->dfs_region_domain;
  759. u8 c_channel = *dm->channel;
  760. u8 band_width = *dm->band_width;
  761. u8 dfs_pw_thd1 = 0, dfs_pw_thd2 = 0, dfs_pw_thd3 = 0;
  762. u8 dfs_pw_thd4 = 0, dfs_pw_thd5 = 0;
  763. u8 dfs_pri_thd1 = 0, dfs_pri_thd2 = 0, dfs_pri_thd3 = 0;
  764. u8 dfs_pri_thd4 = 0, dfs_pri_thd5 = 0;
  765. u8 pri_th = 0, i = 0;
  766. u8 max_pri_idx = 0, max_pw_idx = 0, max_pri_cnt_th = 0;
  767. u8 max_pri_cnt_fcc_g1_th = 0, max_pri_cnt_fcc_g3_th = 0;
  768. u8 safe_pri_pw_diff_th = 0, safe_pri_pw_diff_fcc_th = 0;
  769. u8 safe_pri_pw_diff_w53_th = 0, safe_pri_pw_diff_fcc_idle_th = 0;
  770. u16 j = 0;
  771. u32 dfs_hist1_peak_index = 0, dfs_hist2_peak_index = 0;
  772. u32 dfs_hist1_pw = 0, dfs_hist2_pw = 0, g_pw[6] = {0};
  773. u32 g_peakindex[16] = {0}, g_mask_32 = 0, false_peak_hist1 = 0;
  774. u32 false_peak_hist2_above10 = 0, false_peak_hist2_above0 = 0;
  775. u32 dfs_hist1_pri = 0, dfs_hist2_pri = 0, g_pri[6] = {0};
  776. u32 pw_sum_g0g5 = 0, pw_sum_g1g2g3g4 = 0;
  777. u32 pri_sum_g0g5 = 0, pri_sum_g1g2g3g4 = 0;
  778. u32 pw_sum_ss_g1g2g3g4 = 0, pri_sum_ss_g1g2g3g4 = 0;
  779. u32 max_pri_cnt = 0, max_pw_cnt = 0;
  780. /*read peak index hist report*/
  781. odm_set_bb_reg(dm, 0x19e4, BIT(22) | BIT(23), 0x0);
  782. dfs_hist1_peak_index = odm_get_bb_reg(dm, 0xf5c, 0xffffffff);
  783. dfs_hist2_peak_index = odm_get_bb_reg(dm, 0xf74, 0xffffffff);
  784. g_peakindex[15] = ((dfs_hist1_peak_index & 0x0000000f) >> 0);
  785. g_peakindex[14] = ((dfs_hist1_peak_index & 0x000000f0) >> 4);
  786. g_peakindex[13] = ((dfs_hist1_peak_index & 0x00000f00) >> 8);
  787. g_peakindex[12] = ((dfs_hist1_peak_index & 0x0000f000) >> 12);
  788. g_peakindex[11] = ((dfs_hist1_peak_index & 0x000f0000) >> 16);
  789. g_peakindex[10] = ((dfs_hist1_peak_index & 0x00f00000) >> 20);
  790. g_peakindex[9] = ((dfs_hist1_peak_index & 0x0f000000) >> 24);
  791. g_peakindex[8] = ((dfs_hist1_peak_index & 0xf0000000) >> 28);
  792. g_peakindex[7] = ((dfs_hist2_peak_index & 0x0000000f) >> 0);
  793. g_peakindex[6] = ((dfs_hist2_peak_index & 0x000000f0) >> 4);
  794. g_peakindex[5] = ((dfs_hist2_peak_index & 0x00000f00) >> 8);
  795. g_peakindex[4] = ((dfs_hist2_peak_index & 0x0000f000) >> 12);
  796. g_peakindex[3] = ((dfs_hist2_peak_index & 0x000f0000) >> 16);
  797. g_peakindex[2] = ((dfs_hist2_peak_index & 0x00f00000) >> 20);
  798. g_peakindex[1] = ((dfs_hist2_peak_index & 0x0f000000) >> 24);
  799. g_peakindex[0] = ((dfs_hist2_peak_index & 0xf0000000) >> 28);
  800. /*read pulse width hist report*/
  801. odm_set_bb_reg(dm, 0x19e4, BIT(22) | BIT(23), 0x1);
  802. dfs_hist1_pw = odm_get_bb_reg(dm, 0xf5c, 0xffffffff);
  803. dfs_hist2_pw = odm_get_bb_reg(dm, 0xf74, 0xffffffff);
  804. g_pw[0] = (unsigned int)((dfs_hist2_pw & 0xff000000) >> 24);
  805. g_pw[1] = (unsigned int)((dfs_hist2_pw & 0x00ff0000) >> 16);
  806. g_pw[2] = (unsigned int)((dfs_hist2_pw & 0x0000ff00) >> 8);
  807. g_pw[3] = (unsigned int)dfs_hist2_pw & 0x000000ff;
  808. g_pw[4] = (unsigned int)((dfs_hist1_pw & 0xff000000) >> 24);
  809. g_pw[5] = (unsigned int)((dfs_hist1_pw & 0x00ff0000) >> 16);
  810. /*read pulse repetition interval hist report*/
  811. odm_set_bb_reg(dm, 0x19e4, BIT(22) | BIT(23), 0x3);
  812. dfs_hist1_pri = odm_get_bb_reg(dm, 0xf5c, 0xffffffff);
  813. dfs_hist2_pri = odm_get_bb_reg(dm, 0xf74, 0xffffffff);
  814. odm_set_bb_reg(dm, 0x19b4, 0x10000000, 1); /*reset histo report*/
  815. odm_set_bb_reg(dm, 0x19b4, 0x10000000, 0); /*@continue histo report*/
  816. g_pri[0] = (unsigned int)((dfs_hist2_pri & 0xff000000) >> 24);
  817. g_pri[1] = (unsigned int)((dfs_hist2_pri & 0x00ff0000) >> 16);
  818. g_pri[2] = (unsigned int)((dfs_hist2_pri & 0x0000ff00) >> 8);
  819. g_pri[3] = (unsigned int)dfs_hist2_pri & 0x000000ff;
  820. g_pri[4] = (unsigned int)((dfs_hist1_pri & 0xff000000) >> 24);
  821. g_pri[5] = (unsigned int)((dfs_hist1_pri & 0x00ff0000) >> 16);
  822. dfs->pri_cond1 = 0;
  823. dfs->pri_cond2 = 0;
  824. dfs->pri_cond3 = 0;
  825. dfs->pri_cond4 = 0;
  826. dfs->pri_cond5 = 0;
  827. dfs->pw_cond1 = 0;
  828. dfs->pw_cond2 = 0;
  829. dfs->pw_cond3 = 0;
  830. dfs->pri_type3_4_cond1 = 0; /*@for ETSI*/
  831. dfs->pri_type3_4_cond2 = 0; /*@for ETSI*/
  832. dfs->pw_long_cond1 = 0; /*@for long radar*/
  833. dfs->pw_long_cond2 = 0; /*@for long radar*/
  834. dfs->pri_long_cond1 = 0; /*@for long radar*/
  835. dfs->pw_flag = 0;
  836. dfs->pri_flag = 0;
  837. dfs->pri_type3_4_flag = 0; /*@for ETSI*/
  838. dfs->long_radar_flag = 0;
  839. dfs->pw_std = 0; /*The std(var) of reasonable num of pw group*/
  840. dfs->pri_std = 0; /*The std(var) of reasonable num of pri group*/
  841. for (i = 0; i < 6; i++) {
  842. dfs->pw_hold_sum[i] = 0;
  843. dfs->pri_hold_sum[i] = 0;
  844. dfs->pw_long_hold_sum[i] = 0;
  845. dfs->pri_long_hold_sum[i] = 0;
  846. }
  847. if (dfs->idle_mode == 1)
  848. pri_th = dfs->pri_hist_th;
  849. else
  850. pri_th = dfs->pri_hist_th - 1;
  851. for (i = 0; i < 6; i++) {
  852. dfs->pw_hold[dfs->hist_idx][i] = (u8)g_pw[i];
  853. dfs->pri_hold[dfs->hist_idx][i] = (u8)g_pri[i];
  854. /*@collect whole histogram report may take some time
  855. *so we add the counter of 2 time slots in FCC and ETSI
  856. */
  857. if (region_domain == 1 || region_domain == 3) {
  858. dfs->pw_hold_sum[i] = dfs->pw_hold_sum[i] +
  859. dfs->pw_hold[(dfs->hist_idx + 1) % 3][i] +
  860. dfs->pw_hold[(dfs->hist_idx + 2) % 3][i];
  861. dfs->pri_hold_sum[i] = dfs->pri_hold_sum[i] +
  862. dfs->pri_hold[(dfs->hist_idx + 1) % 3][i] +
  863. dfs->pri_hold[(dfs->hist_idx + 2) % 3][i];
  864. } else{
  865. /*@collect whole histogram report may take some time,
  866. *so we add the counter of 3 time slots in MKK or else
  867. */
  868. dfs->pw_hold_sum[i] = dfs->pw_hold_sum[i] +
  869. dfs->pw_hold[(dfs->hist_idx + 1) % 4][i] +
  870. dfs->pw_hold[(dfs->hist_idx + 2) % 4][i] +
  871. dfs->pw_hold[(dfs->hist_idx + 3) % 4][i];
  872. dfs->pri_hold_sum[i] = dfs->pri_hold_sum[i] +
  873. dfs->pri_hold[(dfs->hist_idx + 1) % 4][i] +
  874. dfs->pri_hold[(dfs->hist_idx + 2) % 4][i] +
  875. dfs->pri_hold[(dfs->hist_idx + 3) % 4][i];
  876. }
  877. }
  878. /*@For long radar type*/
  879. for (i = 0; i < 6; i++) {
  880. dfs->pw_long_hold[dfs->hist_long_idx][i] = (u8)g_pw[i];
  881. dfs->pri_long_hold[dfs->hist_long_idx][i] = (u8)g_pri[i];
  882. /*@collect whole histogram report may take some time,
  883. *so we add the counter of 299 time slots for long radar
  884. */
  885. for (j = 1; j < 300; j++) {
  886. dfs->pw_long_hold_sum[i] = dfs->pw_long_hold_sum[i] +
  887. dfs->pw_long_hold[(dfs->hist_long_idx + j) % 300][i];
  888. dfs->pri_long_hold_sum[i] = dfs->pri_long_hold_sum[i] +
  889. dfs->pri_long_hold[(dfs->hist_long_idx + j) % 300][i];
  890. }
  891. }
  892. dfs->hist_idx++;
  893. dfs->hist_long_idx++;
  894. if (dfs->hist_long_idx == 300)
  895. dfs->hist_long_idx = 0;
  896. if (region_domain == 1 || region_domain == 3) {
  897. if (dfs->hist_idx == 3)
  898. dfs->hist_idx = 0;
  899. } else if (dfs->hist_idx == 4) {
  900. dfs->hist_idx = 0;
  901. }
  902. max_pri_cnt = 0;
  903. max_pri_idx = 0;
  904. max_pw_cnt = 0;
  905. max_pw_idx = 0;
  906. max_pri_cnt_th = dfs->pri_sum_g1_th;
  907. max_pri_cnt_fcc_g1_th = dfs->pri_sum_g1_fcc_th;
  908. max_pri_cnt_fcc_g3_th = dfs->pri_sum_g3_fcc_th;
  909. safe_pri_pw_diff_th = dfs->pri_pw_diff_th;
  910. safe_pri_pw_diff_fcc_th = dfs->pri_pw_diff_fcc_th;
  911. safe_pri_pw_diff_fcc_idle_th = dfs->pri_pw_diff_fcc_idle_th;
  912. safe_pri_pw_diff_w53_th = dfs->pri_pw_diff_w53_th;
  913. /*@g1 to g4 is the reseasonable range of pri and pw*/
  914. for (i = 1; i <= 4; i++) {
  915. if (dfs->pri_hold_sum[i] > max_pri_cnt) {
  916. max_pri_cnt = dfs->pri_hold_sum[i];
  917. max_pri_idx = i;
  918. }
  919. if (dfs->pw_hold_sum[i] > max_pw_cnt) {
  920. max_pw_cnt = dfs->pw_hold_sum[i];
  921. max_pw_idx = i;
  922. }
  923. if (dfs->pri_hold_sum[i] >= pri_th)
  924. dfs->pri_cond1 = 1;
  925. }
  926. pri_sum_g0g5 = dfs->pri_hold_sum[0];
  927. if (pri_sum_g0g5 == 0)
  928. pri_sum_g0g5 = 1;
  929. pri_sum_g1g2g3g4 = dfs->pri_hold_sum[1] + dfs->pri_hold_sum[2]
  930. + dfs->pri_hold_sum[3] + dfs->pri_hold_sum[4];
  931. /*pw will reduce because of dc, so we do not treat g0 as illegal group*/
  932. pw_sum_g0g5 = dfs->pw_hold_sum[5];
  933. if (pw_sum_g0g5 == 0)
  934. pw_sum_g0g5 = 1;
  935. pw_sum_g1g2g3g4 = dfs->pw_hold_sum[1] + dfs->pw_hold_sum[2] +
  936. dfs->pw_hold_sum[3] + dfs->pw_hold_sum[4];
  937. /*@Calculate the variation from g1 to g4*/
  938. for (i = 1; i < 5; i++) {
  939. /*Sum of square*/
  940. pw_sum_ss_g1g2g3g4 = pw_sum_ss_g1g2g3g4 +
  941. (dfs->pw_hold_sum[i] - (pw_sum_g1g2g3g4 / 4)) *
  942. (dfs->pw_hold_sum[i] - (pw_sum_g1g2g3g4 / 4));
  943. pri_sum_ss_g1g2g3g4 = pri_sum_ss_g1g2g3g4 +
  944. (dfs->pri_hold_sum[i] - (pri_sum_g1g2g3g4 / 4)) *
  945. (dfs->pri_hold_sum[i] - (pri_sum_g1g2g3g4 / 4));
  946. }
  947. /*The value may less than the normal variance,
  948. *since the variable type is int (not float)
  949. */
  950. dfs->pw_std = (u16)(pw_sum_ss_g1g2g3g4 / 4);
  951. dfs->pri_std = (u16)(pri_sum_ss_g1g2g3g4 / 4);
  952. if (region_domain == 1) {
  953. dfs->pri_type3_4_flag = 1; /*@ETSI flag*/
  954. /*PRI judgment conditions for short radar type*/
  955. /*ratio of reasonable group and illegal group &&
  956. *pri variation of short radar should be large (=6)
  957. */
  958. if (max_pri_idx != 4 && dfs->pri_hold_sum[5] > 0)
  959. dfs->pri_cond2 = 0;
  960. else
  961. dfs->pri_cond2 = 1;
  962. /*reasonable group shouldn't large*/
  963. if ((pri_sum_g0g5 + pri_sum_g1g2g3g4) / pri_sum_g0g5 > 2 &&
  964. pri_sum_g1g2g3g4 <= dfs->pri_sum_safe_fcc_th)
  965. dfs->pri_cond3 = 1;
  966. /*@Cancel the condition that the abs between pri and pw*/
  967. if (dfs->pri_std >= dfs->pri_std_th)
  968. dfs->pri_cond4 = 1;
  969. else if (max_pri_idx == 1 &&
  970. max_pri_cnt >= max_pri_cnt_fcc_g1_th)
  971. dfs->pri_cond4 = 1;
  972. /*we set threshold = 7 (>4) for distinguishing type 3,4 (g3)*/
  973. if (max_pri_idx == 1 && dfs->pri_hold_sum[3] +
  974. dfs->pri_hold_sum[4] + dfs->pri_hold_sum[5] > 0)
  975. dfs->pri_cond5 = 0;
  976. else
  977. dfs->pri_cond5 = 1;
  978. if (dfs->pri_cond1 && dfs->pri_cond2 && dfs->pri_cond3 &&
  979. dfs->pri_cond4 && dfs->pri_cond5)
  980. dfs->pri_flag = 1;
  981. /* PW judgment conditions for short radar type */
  982. /*ratio of reasonable and illegal group && g5 should be zero*/
  983. if (((pw_sum_g0g5 + pw_sum_g1g2g3g4) / pw_sum_g0g5 > 2) &&
  984. (dfs->pw_hold_sum[5] <= 1))
  985. dfs->pw_cond1 = 1;
  986. /*unreasonable group*/
  987. if (dfs->pw_hold_sum[4] == 0 && dfs->pw_hold_sum[5] == 0)
  988. dfs->pw_cond2 = 1;
  989. /*pw's std (short radar) should be large(=7)*/
  990. if (dfs->pw_std >= dfs->pw_std_th)
  991. dfs->pw_cond3 = 1;
  992. if (dfs->pw_cond1 && dfs->pw_cond2 && dfs->pw_cond3)
  993. dfs->pw_flag = 1;
  994. /* @Judgment conditions of long radar type */
  995. if (band_width == CHANNEL_WIDTH_20) {
  996. if (dfs->pw_long_hold_sum[4] >=
  997. dfs->pw_long_lower_20m_th)
  998. dfs->pw_long_cond1 = 1;
  999. } else{
  1000. if (dfs->pw_long_hold_sum[4] >= dfs->pw_long_lower_th)
  1001. dfs->pw_long_cond1 = 1;
  1002. }
  1003. /* @Disable the condition that dfs->pw_long_hold_sum[1] */
  1004. if (dfs->pw_long_hold_sum[2] + dfs->pw_long_hold_sum[3] +
  1005. dfs->pw_long_hold_sum[4] <= dfs->pw_long_sum_upper_th &&
  1006. dfs->pw_long_hold_sum[2] <= dfs->pw_long_hold_sum[4] &&
  1007. dfs->pw_long_hold_sum[3] <= dfs->pw_long_hold_sum[4])
  1008. dfs->pw_long_cond2 = 1;
  1009. /*@g4 should be large for long radar*/
  1010. if (dfs->pri_long_hold_sum[4] <= dfs->pri_long_upper_th)
  1011. dfs->pri_long_cond1 = 1;
  1012. if (dfs->pw_long_cond1 && dfs->pw_long_cond2 &&
  1013. dfs->pri_long_cond1)
  1014. dfs->long_radar_flag = 1;
  1015. } else if (region_domain == 2) {
  1016. dfs->pri_type3_4_flag = 1; /*@ETSI flag*/
  1017. /*PRI judgment conditions for short radar type*/
  1018. if ((pri_sum_g0g5 + pri_sum_g1g2g3g4) / pri_sum_g0g5 > 2)
  1019. dfs->pri_cond2 = 1;
  1020. /*reasonable group shouldn't too large*/
  1021. if (pri_sum_g1g2g3g4 <= dfs->pri_sum_safe_fcc_th)
  1022. dfs->pri_cond3 = 1;
  1023. /*the difference between pri and pw for idle mode (thr=2)*/
  1024. if (dfs->idle_mode == 1) {
  1025. if (abs(pw_sum_g1g2g3g4 - pri_sum_g1g2g3g4) <=
  1026. safe_pri_pw_diff_fcc_idle_th)
  1027. dfs->pri_cond4 = 1;
  1028. } else{
  1029. if ((c_channel >= 52) && (c_channel <= 64)) {
  1030. /*the difference between pri and pw for w53 TP mode (thr=15)*/
  1031. if (abs(pw_sum_g1g2g3g4 - pri_sum_g1g2g3g4) <=
  1032. safe_pri_pw_diff_w53_th)
  1033. dfs->pri_cond4 = 1;
  1034. } else {
  1035. /*the difference between pri and pw for TP mode (thr=8)*/
  1036. if (abs(pw_sum_g1g2g3g4 - pri_sum_g1g2g3g4) <=
  1037. safe_pri_pw_diff_fcc_th)
  1038. dfs->pri_cond4 = 1;
  1039. }
  1040. }
  1041. if (dfs->idle_mode == 1) {
  1042. if (dfs->pri_std >= dfs->pri_std_idle_th) {
  1043. if (max_pw_idx == 3 &&
  1044. pri_sum_g1g2g3g4 <= dfs->pri_sum_type4_th){
  1045. /*To distinguish between type 4 radar and false detection*/
  1046. dfs->pri_cond5 = 1;
  1047. } else if (max_pw_idx == 1 &&
  1048. pri_sum_g1g2g3g4 >=
  1049. dfs->pri_sum_type6_th) {
  1050. /*To distinguish between type 6 radar and false detection*/
  1051. dfs->pri_cond5 = 1;
  1052. } else {
  1053. /*pri variation of short radar should be large (idle mode)*/
  1054. dfs->pri_cond5 = 1;
  1055. }
  1056. }
  1057. } else {
  1058. /*pri variation of short radar should be large (TP mode)*/
  1059. if (dfs->pri_std >= dfs->pri_std_th)
  1060. dfs->pri_cond5 = 1;
  1061. }
  1062. if (dfs->pri_cond1 && dfs->pri_cond2 && dfs->pri_cond3 &&
  1063. dfs->pri_cond4 && dfs->pri_cond5)
  1064. dfs->pri_flag = 1;
  1065. /* PW judgment conditions for short radar type */
  1066. if (((pw_sum_g0g5 + pw_sum_g1g2g3g4) / pw_sum_g0g5 > 2) &&
  1067. (dfs->pw_hold_sum[5] <= 1))
  1068. /*ratio of reasonable and illegal group && g5 should be zero*/
  1069. dfs->pw_cond1 = 1;
  1070. if ((c_channel >= 52) && (c_channel <= 64))
  1071. dfs->pw_cond2 = 1;
  1072. /*unreasonable group shouldn't too large*/
  1073. else if (dfs->pw_hold_sum[0] <= dfs->pw_g0_th)
  1074. dfs->pw_cond2 = 1;
  1075. if (dfs->idle_mode == 1) {
  1076. /*pw variation of short radar should be large (idle mode)*/
  1077. if (dfs->pw_std >= dfs->pw_std_idle_th)
  1078. dfs->pw_cond3 = 1;
  1079. } else {
  1080. /*pw variation of short radar should be large (TP mode)*/
  1081. if (dfs->pw_std >= dfs->pw_std_th)
  1082. dfs->pw_cond3 = 1;
  1083. }
  1084. if (dfs->pw_cond1 && dfs->pw_cond2 && dfs->pw_cond3)
  1085. dfs->pw_flag = 1;
  1086. /* @Judgment conditions of long radar type */
  1087. if (band_width == CHANNEL_WIDTH_20) {
  1088. if (dfs->pw_long_hold_sum[4] >=
  1089. dfs->pw_long_lower_20m_th)
  1090. dfs->pw_long_cond1 = 1;
  1091. } else{
  1092. if (dfs->pw_long_hold_sum[4] >= dfs->pw_long_lower_th)
  1093. dfs->pw_long_cond1 = 1;
  1094. }
  1095. if (dfs->pw_long_hold_sum[1] + dfs->pw_long_hold_sum[2] +
  1096. dfs->pw_long_hold_sum[3] + dfs->pw_long_hold_sum[4]
  1097. <= dfs->pw_long_sum_upper_th)
  1098. dfs->pw_long_cond2 = 1;
  1099. /*@g4 should be large for long radar*/
  1100. if (dfs->pri_long_hold_sum[4] <= dfs->pri_long_upper_th)
  1101. dfs->pri_long_cond1 = 1;
  1102. if (dfs->pw_long_cond1 &&
  1103. dfs->pw_long_cond2 && dfs->pri_long_cond1)
  1104. dfs->long_radar_flag = 1;
  1105. } else if (region_domain == 3) {
  1106. /*ratio of reasonable group and illegal group */
  1107. if ((pri_sum_g0g5 + pri_sum_g1g2g3g4) / pri_sum_g0g5 > 2)
  1108. dfs->pri_cond2 = 1;
  1109. if (pri_sum_g1g2g3g4 <= dfs->pri_sum_safe_th)
  1110. dfs->pri_cond3 = 1;
  1111. /*@Cancel the condition that the abs between pri and pw*/
  1112. dfs->pri_cond4 = 1;
  1113. if (dfs->pri_hold_sum[5] <= dfs->pri_sum_g5_th)
  1114. dfs->pri_cond5 = 1;
  1115. if (band_width == CHANNEL_WIDTH_40) {
  1116. if (max_pw_idx == 4) {
  1117. if (max_pw_cnt >= dfs->type4_pw_max_cnt &&
  1118. pri_sum_g1g2g3g4 >=
  1119. dfs->type4_safe_pri_sum_th) {
  1120. dfs->pri_cond1 = 1;
  1121. dfs->pri_cond4 = 1;
  1122. dfs->pri_type3_4_cond1 = 1;
  1123. }
  1124. }
  1125. }
  1126. if (dfs->pri_cond1 && dfs->pri_cond2 &&
  1127. dfs->pri_cond3 && dfs->pri_cond4 && dfs->pri_cond5)
  1128. dfs->pri_flag = 1;
  1129. if (((pw_sum_g0g5 + pw_sum_g1g2g3g4) / pw_sum_g0g5 > 2) &&
  1130. (dfs->pw_hold_sum[5] == 0))
  1131. dfs->pw_flag = 1;
  1132. /*@max num pri group is g1 means radar type3 or type4*/
  1133. if (max_pri_idx == 1) {
  1134. if (max_pri_cnt >= max_pri_cnt_th)
  1135. dfs->pri_type3_4_cond1 = 1;
  1136. if (dfs->pri_hold_sum[4] <=
  1137. dfs->pri_sum_g5_under_g1_th &&
  1138. dfs->pri_hold_sum[5] <= dfs->pri_sum_g5_under_g1_th)
  1139. dfs->pri_type3_4_cond2 = 1;
  1140. } else {
  1141. dfs->pri_type3_4_cond1 = 1;
  1142. dfs->pri_type3_4_cond2 = 1;
  1143. }
  1144. if (dfs->pri_type3_4_cond1 && dfs->pri_type3_4_cond2)
  1145. dfs->pri_type3_4_flag = 1;
  1146. } else {
  1147. }
  1148. if (dfs->print_hist_rpt) {
  1149. dfs_pw_thd1 = (u8)odm_get_bb_reg(dm, 0x19e4, 0xff000000);
  1150. dfs_pw_thd2 = (u8)odm_get_bb_reg(dm, 0x19e8, 0x000000ff);
  1151. dfs_pw_thd3 = (u8)odm_get_bb_reg(dm, 0x19e8, 0x0000ff00);
  1152. dfs_pw_thd4 = (u8)odm_get_bb_reg(dm, 0x19e8, 0x00ff0000);
  1153. dfs_pw_thd5 = (u8)odm_get_bb_reg(dm, 0x19e8, 0xff000000);
  1154. dfs_pri_thd1 = (u8)odm_get_bb_reg(dm, 0x19b8, 0x7F80);
  1155. dfs_pri_thd2 = (u8)odm_get_bb_reg(dm, 0x19ec, 0x000000ff);
  1156. dfs_pri_thd3 = (u8)odm_get_bb_reg(dm, 0x19ec, 0x0000ff00);
  1157. dfs_pri_thd4 = (u8)odm_get_bb_reg(dm, 0x19ec, 0x00ff0000);
  1158. dfs_pri_thd5 = (u8)odm_get_bb_reg(dm, 0x19ec, 0xff000000);
  1159. PHYDM_DBG(dm, DBG_DFS, "peak index hist\n");
  1160. PHYDM_DBG(dm, DBG_DFS, "dfs_hist_peak_index=%x %x\n",
  1161. dfs_hist1_peak_index, dfs_hist2_peak_index);
  1162. PHYDM_DBG(dm, DBG_DFS, "g_peak_index_hist = ");
  1163. for (i = 0; i < 16; i++)
  1164. PHYDM_DBG(dm, DBG_DFS, " %x", g_peakindex[i]);
  1165. PHYDM_DBG(dm, DBG_DFS, "\ndfs_pw_thd=%d %d %d %d %d\n",
  1166. dfs_pw_thd1, dfs_pw_thd2, dfs_pw_thd3,
  1167. dfs_pw_thd4, dfs_pw_thd5);
  1168. PHYDM_DBG(dm, DBG_DFS, "-----pulse width hist-----\n");
  1169. PHYDM_DBG(dm, DBG_DFS, "dfs_hist_pw=%x %x\n",
  1170. dfs_hist1_pw, dfs_hist2_pw);
  1171. PHYDM_DBG(dm, DBG_DFS, "g_pw_hist = %x %x %x %x %x %x\n",
  1172. g_pw[0], g_pw[1], g_pw[2], g_pw[3],
  1173. g_pw[4], g_pw[5]);
  1174. PHYDM_DBG(dm, DBG_DFS, "dfs_pri_thd=%d %d %d %d %d\n",
  1175. dfs_pri_thd1, dfs_pri_thd2, dfs_pri_thd3,
  1176. dfs_pri_thd4, dfs_pri_thd5);
  1177. PHYDM_DBG(dm, DBG_DFS, "-----pulse interval hist-----\n");
  1178. PHYDM_DBG(dm, DBG_DFS, "dfs_hist_pri=%x %x\n",
  1179. dfs_hist1_pri, dfs_hist2_pri);
  1180. PHYDM_DBG(dm, DBG_DFS,
  1181. "g_pri_hist = %x %x %x %x %x %x, pw_flag = %d, pri_flag = %d\n",
  1182. g_pri[0], g_pri[1], g_pri[2], g_pri[3], g_pri[4],
  1183. g_pri[5], dfs->pw_flag, dfs->pri_flag);
  1184. if (region_domain == 1 || region_domain == 3) {
  1185. PHYDM_DBG(dm, DBG_DFS, "hist_idx= %d\n",
  1186. (dfs->hist_idx + 2) % 3);
  1187. } else {
  1188. PHYDM_DBG(dm, DBG_DFS, "hist_idx= %d\n",
  1189. (dfs->hist_idx + 3) % 4);
  1190. }
  1191. PHYDM_DBG(dm, DBG_DFS, "hist_long_idx= %d\n",
  1192. (dfs->hist_long_idx + 299) % 300);
  1193. PHYDM_DBG(dm, DBG_DFS,
  1194. "pw_sum_g0g5 = %d, pw_sum_g1g2g3g4 = %d\n",
  1195. pw_sum_g0g5, pw_sum_g1g2g3g4);
  1196. PHYDM_DBG(dm, DBG_DFS,
  1197. "pri_sum_g0g5 = %d, pri_sum_g1g2g3g4 = %d\n",
  1198. pri_sum_g0g5, pri_sum_g1g2g3g4);
  1199. PHYDM_DBG(dm, DBG_DFS, "pw_hold_sum = %d %d %d %d %d %d\n",
  1200. dfs->pw_hold_sum[0], dfs->pw_hold_sum[1],
  1201. dfs->pw_hold_sum[2], dfs->pw_hold_sum[3],
  1202. dfs->pw_hold_sum[4], dfs->pw_hold_sum[5]);
  1203. PHYDM_DBG(dm, DBG_DFS, "pri_hold_sum = %d %d %d %d %d %d\n",
  1204. dfs->pri_hold_sum[0], dfs->pri_hold_sum[1],
  1205. dfs->pri_hold_sum[2], dfs->pri_hold_sum[3],
  1206. dfs->pri_hold_sum[4], dfs->pri_hold_sum[5]);
  1207. PHYDM_DBG(dm, DBG_DFS, "pw_long_hold_sum = %d %d %d %d %d %d\n",
  1208. dfs->pw_long_hold_sum[0], dfs->pw_long_hold_sum[1],
  1209. dfs->pw_long_hold_sum[2], dfs->pw_long_hold_sum[3],
  1210. dfs->pw_long_hold_sum[4], dfs->pw_long_hold_sum[5]);
  1211. PHYDM_DBG(dm, DBG_DFS,
  1212. "pri_long_hold_sum = %d %d %d %d %d %d\n",
  1213. dfs->pri_long_hold_sum[0], dfs->pri_long_hold_sum[1],
  1214. dfs->pri_long_hold_sum[2], dfs->pri_long_hold_sum[3],
  1215. dfs->pri_long_hold_sum[4], dfs->pri_long_hold_sum[5]);
  1216. PHYDM_DBG(dm, DBG_DFS, "idle_mode = %d\n", dfs->idle_mode);
  1217. PHYDM_DBG(dm, DBG_DFS, "pw_standard = %d\n", dfs->pw_std);
  1218. PHYDM_DBG(dm, DBG_DFS, "pri_standard = %d\n", dfs->pri_std);
  1219. for (j = 0; j < 4; j++) {
  1220. for (i = 0; i < 6; i++) {
  1221. PHYDM_DBG(dm, DBG_DFS, "pri_hold = %d ",
  1222. dfs->pri_hold[j][i]);
  1223. }
  1224. PHYDM_DBG(dm, DBG_DFS, "\n");
  1225. }
  1226. PHYDM_DBG(dm, DBG_DFS, "\n");
  1227. PHYDM_DBG(dm, DBG_DFS,
  1228. "pri_cond1 = %d, pri_cond2 = %d, pri_cond3 = %d, pri_cond4 = %d, pri_cond5 = %d\n",
  1229. dfs->pri_cond1, dfs->pri_cond2, dfs->pri_cond3,
  1230. dfs->pri_cond4, dfs->pri_cond5);
  1231. PHYDM_DBG(dm, DBG_DFS,
  1232. "bandwidth = %d, pri_th = %d, max_pri_cnt_th = %d, safe_pri_pw_diff_th = %d\n",
  1233. band_width, pri_th, max_pri_cnt_th,
  1234. safe_pri_pw_diff_th);
  1235. }
  1236. }
  1237. boolean phydm_dfs_hist_log(void *dm_void, u8 index)
  1238. {
  1239. struct dm_struct *dm = (struct dm_struct *)dm_void;
  1240. struct _DFS_STATISTICS *dfs = &dm->dfs;
  1241. u8 i = 0, j = 0;
  1242. boolean hist_radar_detected = 0;
  1243. if (dfs->pulse_type_hist[index] == 0) {
  1244. dfs->radar_type = 0;
  1245. if (dfs->pw_flag && dfs->pri_flag &&
  1246. dfs->pri_type3_4_flag) {
  1247. hist_radar_detected = 1;
  1248. PHYDM_DBG(dm, DBG_DFS,
  1249. "Detected type %d radar signal!\n",
  1250. dfs->radar_type);
  1251. if (dfs->det_print2) {
  1252. PHYDM_DBG(dm, DBG_DFS,
  1253. "hist_idx= %d\n",
  1254. (dfs->hist_idx + 3) % 4);
  1255. for (j = 0; j < 4; j++) {
  1256. for (i = 0; i < 6; i++) {
  1257. PHYDM_DBG(dm, DBG_DFS,
  1258. "pri_hold = %d ",
  1259. dfs->pri_hold[j][i]);
  1260. }
  1261. PHYDM_DBG(dm, DBG_DFS, "\n");
  1262. }
  1263. PHYDM_DBG(dm, DBG_DFS, "\n");
  1264. for (j = 0; j < 4; j++) {
  1265. for (i = 0; i < 6; i++) {
  1266. PHYDM_DBG(dm, DBG_DFS, "pw_hold = %d ",
  1267. dfs->pw_hold[j][i]);
  1268. }
  1269. PHYDM_DBG(dm, DBG_DFS, "\n");
  1270. }
  1271. PHYDM_DBG(dm, DBG_DFS, "\n");
  1272. PHYDM_DBG(dm, DBG_DFS, "idle_mode = %d\n",
  1273. dfs->idle_mode);
  1274. PHYDM_DBG(dm, DBG_DFS,
  1275. "pw_hold_sum = %d %d %d %d %d %d\n",
  1276. dfs->pw_hold_sum[0],
  1277. dfs->pw_hold_sum[1],
  1278. dfs->pw_hold_sum[2],
  1279. dfs->pw_hold_sum[3],
  1280. dfs->pw_hold_sum[4],
  1281. dfs->pw_hold_sum[5]);
  1282. PHYDM_DBG(dm, DBG_DFS,
  1283. "pri_hold_sum = %d %d %d %d %d %d\n",
  1284. dfs->pri_hold_sum[0],
  1285. dfs->pri_hold_sum[1],
  1286. dfs->pri_hold_sum[2],
  1287. dfs->pri_hold_sum[3],
  1288. dfs->pri_hold_sum[4],
  1289. dfs->pri_hold_sum[5]);
  1290. }
  1291. } else {
  1292. if (dfs->det_print2) {
  1293. if (dfs->pulse_flag_hist[index] &&
  1294. dfs->pri_flag == 0) {
  1295. PHYDM_DBG(dm, DBG_DFS, "pri_variation = %d\n",
  1296. dfs->pri_std);
  1297. PHYDM_DBG(dm, DBG_DFS,
  1298. "PRI criterion is not satisfied!\n");
  1299. if (dfs->pri_cond1 == 0)
  1300. PHYDM_DBG(dm, DBG_DFS,
  1301. "pri_cond1 is not satisfied!\n");
  1302. if (dfs->pri_cond2 == 0)
  1303. PHYDM_DBG(dm, DBG_DFS,
  1304. "pri_cond2 is not satisfied!\n");
  1305. if (dfs->pri_cond3 == 0)
  1306. PHYDM_DBG(dm, DBG_DFS,
  1307. "pri_cond3 is not satisfied!\n");
  1308. if (dfs->pri_cond4 == 0)
  1309. PHYDM_DBG(dm, DBG_DFS,
  1310. "pri_cond4 is not satisfied!\n");
  1311. if (dfs->pri_cond5 == 0)
  1312. PHYDM_DBG(dm, DBG_DFS,
  1313. "pri_cond5 is not satisfied!\n");
  1314. }
  1315. if (dfs->pulse_flag_hist[index] &&
  1316. dfs->pw_flag == 0) {
  1317. PHYDM_DBG(dm, DBG_DFS, "pw_variation = %d\n",
  1318. dfs->pw_std);
  1319. PHYDM_DBG(dm, DBG_DFS,
  1320. "PW criterion is not satisfied!\n");
  1321. if (dfs->pw_cond1 == 0)
  1322. PHYDM_DBG(dm, DBG_DFS,
  1323. "pw_cond1 is not satisfied!\n");
  1324. if (dfs->pw_cond2 == 0)
  1325. PHYDM_DBG(dm, DBG_DFS,
  1326. "pw_cond2 is not satisfied!\n");
  1327. if (dfs->pw_cond3 == 0)
  1328. PHYDM_DBG(dm, DBG_DFS,
  1329. "pw_cond3 is not satisfied!\n");
  1330. }
  1331. if (dfs->pulse_flag_hist[index] &&
  1332. (dfs->pri_type3_4_flag == 0)) {
  1333. PHYDM_DBG(dm, DBG_DFS,
  1334. "pri_type3_4 criterion is not satisfied!\n");
  1335. if (dfs->pri_type3_4_cond1 == 0)
  1336. PHYDM_DBG(dm, DBG_DFS,
  1337. "pri_type3_4_cond1 is not satisfied!\n");
  1338. if (dfs->pri_type3_4_cond2 == 0)
  1339. PHYDM_DBG(dm, DBG_DFS,
  1340. "pri_type3_4_cond2 is not satisfied!\n");
  1341. }
  1342. PHYDM_DBG(dm, DBG_DFS, "hist_idx= %d\n",
  1343. (dfs->hist_idx + 3) % 4);
  1344. for (j = 0; j < 4; j++) {
  1345. for (i = 0; i < 6; i++) {
  1346. PHYDM_DBG(dm, DBG_DFS,
  1347. "pri_hold = %d ",
  1348. dfs->pri_hold[j][i]);
  1349. }
  1350. PHYDM_DBG(dm, DBG_DFS, "\n");
  1351. }
  1352. PHYDM_DBG(dm, DBG_DFS, "\n");
  1353. for (j = 0; j < 4; j++) {
  1354. for (i = 0; i < 6; i++)
  1355. PHYDM_DBG(dm, DBG_DFS,
  1356. "pw_hold = %d ",
  1357. dfs->pw_hold[j][i]);
  1358. PHYDM_DBG(dm, DBG_DFS, "\n");
  1359. }
  1360. PHYDM_DBG(dm, DBG_DFS, "\n");
  1361. PHYDM_DBG(dm, DBG_DFS, "idle_mode = %d\n",
  1362. dfs->idle_mode);
  1363. PHYDM_DBG(dm, DBG_DFS,
  1364. "pw_hold_sum = %d %d %d %d %d %d\n",
  1365. dfs->pw_hold_sum[0], dfs->pw_hold_sum[1],
  1366. dfs->pw_hold_sum[2], dfs->pw_hold_sum[3],
  1367. dfs->pw_hold_sum[4], dfs->pw_hold_sum[5]);
  1368. PHYDM_DBG(dm, DBG_DFS,
  1369. "pri_hold_sum = %d %d %d %d %d %d\n",
  1370. dfs->pri_hold_sum[0], dfs->pri_hold_sum[1],
  1371. dfs->pri_hold_sum[2], dfs->pri_hold_sum[3],
  1372. dfs->pri_hold_sum[4], dfs->pri_hold_sum[5]);
  1373. }
  1374. }
  1375. } else {
  1376. dfs->radar_type = 1;
  1377. if (dfs->det_print2) {
  1378. PHYDM_DBG(dm, DBG_DFS, "\n");
  1379. PHYDM_DBG(dm, DBG_DFS, "idle_mode = %d\n",
  1380. dfs->idle_mode);
  1381. PHYDM_DBG(dm, DBG_DFS,
  1382. "long_radar_pw_hold_sum = %d %d %d %d %d %d\n",
  1383. dfs->pw_long_hold_sum[0],
  1384. dfs->pw_long_hold_sum[1],
  1385. dfs->pw_long_hold_sum[2],
  1386. dfs->pw_long_hold_sum[3],
  1387. dfs->pw_long_hold_sum[4],
  1388. dfs->pw_long_hold_sum[5]);
  1389. PHYDM_DBG(dm, DBG_DFS,
  1390. "long_radar_pri_hold_sum = %d %d %d %d %d %d\n",
  1391. dfs->pri_long_hold_sum[0],
  1392. dfs->pri_long_hold_sum[1],
  1393. dfs->pri_long_hold_sum[2],
  1394. dfs->pri_long_hold_sum[3],
  1395. dfs->pri_long_hold_sum[4],
  1396. dfs->pri_long_hold_sum[5]);
  1397. }
  1398. /* @Long radar should satisfy three conditions */
  1399. if (dfs->long_radar_flag == 1) {
  1400. hist_radar_detected = 1;
  1401. PHYDM_DBG(dm, DBG_DFS,
  1402. "Detected type %d radar signal!\n",
  1403. dfs->radar_type);
  1404. } else {
  1405. if (dfs->det_print2) {
  1406. if (dfs->pw_long_cond1 == 0)
  1407. PHYDM_DBG(dm, DBG_DFS,
  1408. "--pw_long_cond1 is not satisfied!--\n");
  1409. if (dfs->pw_long_cond2 == 0)
  1410. PHYDM_DBG(dm, DBG_DFS,
  1411. "--pw_long_cond2 is not satisfied!--\n");
  1412. if (dfs->pri_long_cond1 == 0)
  1413. PHYDM_DBG(dm, DBG_DFS,
  1414. "--pri_long_cond1 is not satisfied!--\n");
  1415. }
  1416. }
  1417. }
  1418. return hist_radar_detected;
  1419. }
  1420. boolean phydm_radar_detect(void *dm_void)
  1421. {
  1422. struct dm_struct *dm = (struct dm_struct *)dm_void;
  1423. struct _DFS_STATISTICS *dfs = &dm->dfs;
  1424. boolean enable_DFS = false;
  1425. boolean radar_detected = false;
  1426. dfs->igi_cur = (u8)odm_get_bb_reg(dm, R_0xc50, 0x0000007f);
  1427. dfs->st_l2h_cur = (u8)odm_get_bb_reg(dm, R_0x91c, 0x000000ff);
  1428. /* @dynamic pwdb calibration */
  1429. if (dfs->igi_pre != dfs->igi_cur) {
  1430. dfs->pwdb_th_cur = ((int)dfs->st_l2h_cur - (int)dfs->igi_cur)
  1431. / 2 + dfs->pwdb_scalar_factor;
  1432. /* @limit the pwdb value to absolute lower bound 0xa */
  1433. dfs->pwdb_th_cur = MAX_2(dfs->pwdb_th_cur, (int)dfs->pwdb_th);
  1434. /* @limit the pwdb value to absolute upper bound 0x1f */
  1435. dfs->pwdb_th_cur = MIN_2(dfs->pwdb_th_cur, 0x1f);
  1436. odm_set_bb_reg(dm, R_0x918, 0x00001f00, dfs->pwdb_th_cur);
  1437. }
  1438. dfs->igi_pre = dfs->igi_cur;
  1439. phydm_dfs_dynamic_setting(dm);
  1440. phydm_dfs_histogram_radar_distinguish(dm);
  1441. radar_detected = phydm_radar_detect_dm_check(dm);
  1442. if (odm_get_bb_reg(dm, R_0x924, BIT(15)))
  1443. enable_DFS = true;
  1444. if (enable_DFS && radar_detected) {
  1445. PHYDM_DBG(dm, DBG_DFS,
  1446. "Radar detect: enable_DFS:%d, radar_detected:%d\n",
  1447. enable_DFS, radar_detected);
  1448. phydm_radar_detect_reset(dm);
  1449. if (dfs->dbg_mode == 1) {
  1450. PHYDM_DBG(dm, DBG_DFS,
  1451. "Radar is detected in DFS dbg mode.\n");
  1452. radar_detected = 0;
  1453. }
  1454. }
  1455. return enable_DFS && radar_detected;
  1456. }
  1457. void phydm_dfs_debug(void *dm_void, char input[][16], u32 *_used,
  1458. char *output, u32 *_out_len)
  1459. {
  1460. struct dm_struct *dm = (struct dm_struct *)dm_void;
  1461. struct _DFS_STATISTICS *dfs = &dm->dfs;
  1462. u32 used = *_used;
  1463. u32 out_len = *_out_len;
  1464. u32 argv[10] = {0};
  1465. u8 i, input_idx = 0;
  1466. for (i = 0; i < 6; i++) {
  1467. if (input[i + 1]) {
  1468. PHYDM_SSCANF(input[i + 1], DCMD_HEX, &argv[i]);
  1469. input_idx++;
  1470. }
  1471. }
  1472. if (input_idx == 0)
  1473. return;
  1474. dfs->dbg_mode = (boolean)argv[0];
  1475. dfs->force_TP_mode = (boolean)argv[1];
  1476. dfs->det_print = (boolean)argv[2];
  1477. dfs->det_print2 = (boolean)argv[3];
  1478. dfs->print_hist_rpt = (boolean)argv[4];
  1479. dfs->hist_cond_on = (boolean)argv[5];
  1480. PDM_SNPF(out_len, used, output + used, out_len - used,
  1481. "dbg_mode: %d, force_TP_mode: %d, det_print: %d,det_print2: %d, print_hist_rpt: %d, hist_cond_on: %d\n",
  1482. dfs->dbg_mode, dfs->force_TP_mode, dfs->det_print,
  1483. dfs->det_print2, dfs->print_hist_rpt, dfs->hist_cond_on);
  1484. /*switch (argv[0]) {
  1485. case 1:
  1486. #if defined(CONFIG_PHYDM_DFS_MASTER)
  1487. set dbg parameters for radar detection instead of the default value
  1488. if (argv[1] == 1) {
  1489. dm->radar_detect_reg_918 = argv[2];
  1490. dm->radar_detect_reg_91c = argv[3];
  1491. dm->radar_detect_reg_920 = argv[4];
  1492. dm->radar_detect_reg_924 = argv[5];
  1493. dm->radar_detect_dbg_parm_en = 1;
  1494. PDM_SNPF((output + used, out_len - used, "Radar detection with dbg parameter\n"));
  1495. PDM_SNPF((output + used, out_len - used, "reg918:0x%08X\n", dm->radar_detect_reg_918));
  1496. PDM_SNPF((output + used, out_len - used, "reg91c:0x%08X\n", dm->radar_detect_reg_91c));
  1497. PDM_SNPF((output + used, out_len - used, "reg920:0x%08X\n", dm->radar_detect_reg_920));
  1498. PDM_SNPF((output + used, out_len - used, "reg924:0x%08X\n", dm->radar_detect_reg_924));
  1499. } else {
  1500. dm->radar_detect_dbg_parm_en = 0;
  1501. PDM_SNPF((output + used, out_len - used, "Radar detection with default parameter\n"));
  1502. }
  1503. phydm_radar_detect_enable(dm);
  1504. #endif defined(CONFIG_PHYDM_DFS_MASTER)
  1505. break;
  1506. default:
  1507. break;
  1508. }*/
  1509. }
  1510. u8 phydm_dfs_polling_time(void *dm_void)
  1511. {
  1512. struct dm_struct *dm = (struct dm_struct *)dm_void;
  1513. u8 dfs_polling_time = 0;
  1514. if (dm->support_ic_type & (ODM_RTL8814A | ODM_RTL8822B | ODM_RTL8821C))
  1515. dfs_polling_time = 40;
  1516. else
  1517. dfs_polling_time = 100;
  1518. return dfs_polling_time;
  1519. }
  1520. #endif /* @defined(CONFIG_PHYDM_DFS_MASTER) */
  1521. boolean
  1522. phydm_is_dfs_band(void *dm_void)
  1523. {
  1524. struct dm_struct *dm = (struct dm_struct *)dm_void;
  1525. if (((*dm->channel >= 52) && (*dm->channel <= 64)) ||
  1526. ((*dm->channel >= 100) && (*dm->channel <= 144)))
  1527. return true;
  1528. else
  1529. return false;
  1530. }
  1531. boolean
  1532. phydm_dfs_master_enabled(void *dm_void)
  1533. {
  1534. #ifdef CONFIG_PHYDM_DFS_MASTER
  1535. struct dm_struct *dm = (struct dm_struct *)dm_void;
  1536. boolean ret_val = false;
  1537. if (dm->dfs_master_enabled) /*pointer protection*/
  1538. ret_val = *dm->dfs_master_enabled ? true : false;
  1539. return ret_val;
  1540. #else
  1541. return false;
  1542. #endif
  1543. }