phydm_dig.c 81 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729
  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. * include files
  27. * ************************************************************
  28. */
  29. #include "mp_precomp.h"
  30. #include "phydm_precomp.h"
  31. #ifdef CFG_DIG_DAMPING_CHK
  32. void phydm_dig_recorder_reset(void *dm_void)
  33. {
  34. struct dm_struct *dm = (struct dm_struct *)dm_void;
  35. struct phydm_dig_struct *dig_t = &dm->dm_dig_table;
  36. struct phydm_dig_recorder_strcut *dig_rc = &dig_t->dig_recorder_t;
  37. PHYDM_DBG(dm, DBG_DIG, "%s ======>\n", __func__);
  38. odm_memory_set(dm, &dig_rc->igi_bitmap, 0,
  39. sizeof(struct phydm_dig_recorder_strcut));
  40. }
  41. void phydm_dig_recorder(void *dm_void, boolean first_connect, u8 igi_curr,
  42. u32 fa_cnt)
  43. {
  44. struct dm_struct *dm = (struct dm_struct *)dm_void;
  45. struct phydm_dig_struct *dig_t = &dm->dm_dig_table;
  46. struct phydm_dig_recorder_strcut *dig_rc = &dig_t->dig_recorder_t;
  47. u8 igi_pre = dig_rc->igi_history[0];
  48. u8 igi_up = 0;
  49. if (!dm->is_linked)
  50. return;
  51. PHYDM_DBG(dm, DBG_DIG, "%s ======>\n", __func__);
  52. if (first_connect) {
  53. phydm_dig_recorder_reset(dm);
  54. dig_rc->igi_history[0] = igi_curr;
  55. dig_rc->fa_history[0] = fa_cnt;
  56. return;
  57. }
  58. igi_pre = dig_rc->igi_history[0];
  59. igi_up = (igi_curr > igi_pre) ? 1 : 0;
  60. dig_rc->igi_bitmap = ((dig_rc->igi_bitmap << 1) & 0xfe) | igi_up;
  61. dig_rc->igi_history[3] = dig_rc->igi_history[2];
  62. dig_rc->igi_history[2] = dig_rc->igi_history[1];
  63. dig_rc->igi_history[1] = dig_rc->igi_history[0];
  64. dig_rc->igi_history[0] = igi_curr;
  65. dig_rc->fa_history[3] = dig_rc->fa_history[2];
  66. dig_rc->fa_history[2] = dig_rc->fa_history[1];
  67. dig_rc->fa_history[1] = dig_rc->fa_history[0];
  68. dig_rc->fa_history[0] = fa_cnt;
  69. PHYDM_DBG(dm, DBG_DIG, "igi_history[3:0] = {0x%x, 0x%x, 0x%x, 0x%x}\n",
  70. dig_rc->igi_history[3], dig_rc->igi_history[2],
  71. dig_rc->igi_history[1], dig_rc->igi_history[0]);
  72. PHYDM_DBG(dm, DBG_DIG, "fa_history[3:0] = {%d, %d, %d, %d}\n",
  73. dig_rc->fa_history[3], dig_rc->fa_history[2],
  74. dig_rc->fa_history[1], dig_rc->fa_history[0]);
  75. PHYDM_DBG(dm, DBG_DIG, "igi_bitmap = {%d, %d, %d, %d} = 0x%x\n",
  76. (u8)((dig_rc->igi_bitmap & BIT(3)) >> 3),
  77. (u8)((dig_rc->igi_bitmap & BIT(2)) >> 2),
  78. (u8)((dig_rc->igi_bitmap & BIT(1)) >> 1),
  79. (u8)(dig_rc->igi_bitmap & BIT(0)),
  80. dig_rc->igi_bitmap);
  81. }
  82. void phydm_dig_damping_chk(void *dm_void)
  83. {
  84. struct dm_struct *dm = (struct dm_struct *)dm_void;
  85. struct phydm_dig_struct *dig_t = &dm->dm_dig_table;
  86. struct phydm_dig_recorder_strcut *dig_rc = &dig_t->dig_recorder_t;
  87. u8 igi_bitmap_4bit = dig_rc->igi_bitmap & 0xf;
  88. u8 diff1 = 0, diff2 = 0;
  89. u32 fa_low_th = dig_t->fa_th[0];
  90. u32 fa_high_th = dig_t->fa_th[1];
  91. u8 fa_pattern_match = 0;
  92. u32 time_tmp;
  93. if (!dm->is_linked)
  94. return;
  95. PHYDM_DBG(dm, DBG_DIG, "%s ======>\n", __func__);
  96. /*@== Release Damping ================================================*/
  97. if (dig_rc->damping_limit_en) {
  98. PHYDM_DBG(dm, DBG_DIG,
  99. "[Damping Limit!] limit_time=%d, phydm_sys_up_time=%d\n",
  100. dig_rc->limit_time, dm->phydm_sys_up_time);
  101. time_tmp = dig_rc->limit_time + DIG_LIMIT_PERIOD;
  102. if (DIFF_2(dm->rssi_min, dig_rc->limit_rssi) > 3 ||
  103. time_tmp < dm->phydm_sys_up_time) {
  104. dig_rc->damping_limit_en = 0;
  105. PHYDM_DBG(dm, DBG_DIG, "rssi_min=%d, limit_rssi=%d\n",
  106. dm->rssi_min, dig_rc->limit_rssi);
  107. }
  108. return;
  109. }
  110. /*@== Damping Pattern Check===========================================*/
  111. PHYDM_DBG(dm, DBG_DIG, "fa_th{H, L}= {%d,%d}\n", fa_high_th, fa_low_th);
  112. switch (igi_bitmap_4bit) {
  113. case 0x5: /*@4b'0101 ex:down(0x24)->up(0x28)->down(0x24)->up(0x28)*/
  114. if (dig_rc->igi_history[0] > dig_rc->igi_history[1])
  115. diff1 = dig_rc->igi_history[0] - dig_rc->igi_history[1];
  116. if (dig_rc->igi_history[2] > dig_rc->igi_history[3])
  117. diff2 = dig_rc->igi_history[2] - dig_rc->igi_history[3];
  118. if (dig_rc->fa_history[0] < fa_low_th &&
  119. dig_rc->fa_history[1] > fa_high_th &&
  120. dig_rc->fa_history[2] < fa_low_th &&
  121. dig_rc->fa_history[3] > fa_high_th) {
  122. /*@Check each fa element*/
  123. fa_pattern_match = 1;
  124. }
  125. break;
  126. case 0x9: /*@4b'1001 ex:up(0x28)->down(0x26)->down(0x24)->up(0x28)*/
  127. if (dig_rc->igi_history[0] > dig_rc->igi_history[1])
  128. diff1 = dig_rc->igi_history[0] - dig_rc->igi_history[1];
  129. if (dig_rc->igi_history[2] < dig_rc->igi_history[3])
  130. diff2 = dig_rc->igi_history[3] - dig_rc->igi_history[2];
  131. if (dig_rc->fa_history[0] < fa_low_th &&
  132. dig_rc->fa_history[1] > fa_high_th &&
  133. dig_rc->fa_history[2] > fa_low_th &&
  134. dig_rc->fa_history[3] < fa_high_th) {
  135. /*@Check each fa element*/
  136. fa_pattern_match = 1;
  137. }
  138. break;
  139. default:
  140. break;
  141. }
  142. if (diff1 >= 2 && diff2 >= 2 && fa_pattern_match) {
  143. dig_rc->damping_limit_en = 1;
  144. dig_rc->damping_limit_val = dig_rc->igi_history[0];
  145. dig_rc->limit_time = dm->phydm_sys_up_time;
  146. dig_rc->limit_rssi = dm->rssi_min;
  147. PHYDM_DBG(dm, DBG_DIG,
  148. "[Start damping_limit!] IGI_dyn_min=0x%x, limit_time=%d, limit_rssi=%d\n",
  149. dig_rc->damping_limit_val,
  150. dig_rc->limit_time, dig_rc->limit_rssi);
  151. }
  152. PHYDM_DBG(dm, DBG_DIG, "damping_limit=%d\n", dig_rc->damping_limit_en);
  153. }
  154. #endif
  155. boolean
  156. phydm_dig_go_up_check(void *dm_void)
  157. {
  158. struct dm_struct *dm = (struct dm_struct *)dm_void;
  159. struct ccx_info *ccx_info = &dm->dm_ccx_info;
  160. struct phydm_dig_struct *dig_t = &dm->dm_dig_table;
  161. u8 cur_ig_value = dig_t->cur_ig_value;
  162. u8 max_cover_bond = 0;
  163. u8 rx_gain_range_max = dig_t->rx_gain_range_max;
  164. u8 i = 0, j = 0;
  165. u8 total_nhm_cnt = ccx_info->nhm_rpt_sum;
  166. u32 dig_cnt = 0;
  167. u32 over_dig_cnt = 0;
  168. boolean ret = true;
  169. if (*dm->bb_op_mode == PHYDM_PERFORMANCE_MODE)
  170. return ret;
  171. max_cover_bond = DIG_MAX_BALANCE_MODE - dig_t->upcheck_init_val;
  172. if (cur_ig_value < max_cover_bond - 6)
  173. dig_t->go_up_chk_lv = DIG_GOUPCHECK_LEVEL_0;
  174. else if (cur_ig_value <= DIG_MAX_BALANCE_MODE)
  175. dig_t->go_up_chk_lv = DIG_GOUPCHECK_LEVEL_1;
  176. else /* @cur_ig_value > DM_DIG_MAX_AP, foolproof */
  177. dig_t->go_up_chk_lv = DIG_GOUPCHECK_LEVEL_2;
  178. PHYDM_DBG(dm, DBG_DIG, "check_lv = %d, max_cover_bond = 0x%x\n",
  179. dig_t->go_up_chk_lv, max_cover_bond);
  180. if (total_nhm_cnt == 0)
  181. return true;
  182. if (dig_t->go_up_chk_lv == DIG_GOUPCHECK_LEVEL_0) {
  183. for (i = 3; i <= 11; i++)
  184. dig_cnt += ccx_info->nhm_result[i];
  185. if ((dig_t->lv0_ratio_reciprocal * dig_cnt) >= total_nhm_cnt)
  186. ret = true;
  187. else
  188. ret = false;
  189. } else if (dig_t->go_up_chk_lv == DIG_GOUPCHECK_LEVEL_1) {
  190. /* search index */
  191. for (i = 0; i <= 10; i++) {
  192. if ((max_cover_bond * 2) == ccx_info->nhm_th[i]) {
  193. for (j = (i + 1); j <= 11; j++)
  194. over_dig_cnt += ccx_info->nhm_result[j];
  195. break;
  196. }
  197. }
  198. if (dig_t->lv1_ratio_reciprocal * over_dig_cnt < total_nhm_cnt)
  199. ret = true;
  200. else
  201. ret = false;
  202. if (!ret) {
  203. /* update dig_t->rx_gain_range_max */
  204. if (rx_gain_range_max + 6 >= max_cover_bond)
  205. dig_t->rx_gain_range_max = max_cover_bond - 6;
  206. else
  207. dig_t->rx_gain_range_max = rx_gain_range_max;
  208. PHYDM_DBG(dm, DBG_DIG,
  209. "Noise pwr over DIG can filter, lock rx_gain_range_max to 0x%x\n",
  210. dig_t->rx_gain_range_max);
  211. }
  212. } else if (dig_t->go_up_chk_lv == DIG_GOUPCHECK_LEVEL_2) {
  213. /* @cur_ig_value > DM_DIG_MAX_AP, foolproof */
  214. ret = true;
  215. }
  216. return ret;
  217. }
  218. void phydm_fa_threshold_check(void *dm_void, boolean is_dfs_band)
  219. {
  220. struct dm_struct *dm = (struct dm_struct *)dm_void;
  221. struct phydm_dig_struct *dig_t = &dm->dm_dig_table;
  222. if (dig_t->is_dbg_fa_th) {
  223. PHYDM_DBG(dm, DBG_DIG, "Manual Fix FA_th\n");
  224. } else if (dm->is_linked) {
  225. if (dm->rssi_min < 20) { /*@[PHYDM-252]*/
  226. dig_t->fa_th[0] = 500;
  227. dig_t->fa_th[1] = 750;
  228. dig_t->fa_th[2] = 1000;
  229. } else if (((dm->rx_tp >> 2) > dm->tx_tp) && /*Test RX TP*/
  230. (dm->rx_tp < 10) && (dm->rx_tp > 1)) { /*TP=1~10Mb*/
  231. dig_t->fa_th[0] = 125;
  232. dig_t->fa_th[1] = 250;
  233. dig_t->fa_th[2] = 500;
  234. } else {
  235. dig_t->fa_th[0] = 250;
  236. dig_t->fa_th[1] = 500;
  237. dig_t->fa_th[2] = 750;
  238. }
  239. } else {
  240. if (is_dfs_band) { /* @For DFS band and no link */
  241. dig_t->fa_th[0] = 250;
  242. dig_t->fa_th[1] = 1000;
  243. dig_t->fa_th[2] = 2000;
  244. } else {
  245. dig_t->fa_th[0] = 2000;
  246. dig_t->fa_th[1] = 4000;
  247. dig_t->fa_th[2] = 5000;
  248. }
  249. }
  250. PHYDM_DBG(dm, DBG_DIG, "FA_th={%d,%d,%d}\n", dig_t->fa_th[0],
  251. dig_t->fa_th[1], dig_t->fa_th[2]);
  252. }
  253. void phydm_set_big_jump_step(void *dm_void, u8 curr_igi)
  254. {
  255. #if (RTL8822B_SUPPORT || RTL8197F_SUPPORT || RTL8192F_SUPPORT)
  256. struct dm_struct *dm = (struct dm_struct *)dm_void;
  257. struct phydm_dig_struct *dig_t = &dm->dm_dig_table;
  258. u8 step1[8] = {24, 30, 40, 50, 60, 70, 80, 90};
  259. u8 big_jump_lmt = dig_t->big_jump_lmt[dig_t->agc_table_idx];
  260. u8 i;
  261. if (dig_t->enable_adjust_big_jump == 0)
  262. return;
  263. for (i = 0; i <= dig_t->big_jump_step1; i++) {
  264. if ((curr_igi + step1[i]) > big_jump_lmt) {
  265. if (i != 0)
  266. i = i - 1;
  267. break;
  268. } else if (i == dig_t->big_jump_step1) {
  269. break;
  270. }
  271. }
  272. if (dm->support_ic_type & ODM_RTL8822B)
  273. odm_set_bb_reg(dm, R_0x8c8, 0xe, i);
  274. else if (dm->support_ic_type & (ODM_RTL8197F | ODM_RTL8192F))
  275. odm_set_bb_reg(dm, ODM_REG_BB_AGC_SET_2_11N, 0xe, i);
  276. PHYDM_DBG(dm, DBG_DIG, "Bigjump = %d (ori = 0x%x), LMT=0x%x\n", i,
  277. dig_t->big_jump_step1, big_jump_lmt);
  278. #endif
  279. }
  280. #ifdef PHYDM_IC_JGR3_SERIES_SUPPORT
  281. void phydm_write_dig_reg_jgr3(void *dm_void, u8 igi)
  282. {
  283. struct dm_struct *dm = (struct dm_struct *)dm_void;
  284. struct phydm_dig_struct *dig_t = &dm->dm_dig_table;
  285. PHYDM_DBG(dm, DBG_DIG, "%s===>\n", __func__);
  286. /* Set IGI value */
  287. if (!(dm->support_ic_type & ODM_IC_JGR3_SERIES))
  288. return;
  289. odm_set_bb_reg(dm, R_0x1d70, ODM_BIT_IGI_11AC, igi);
  290. #if (defined(PHYDM_COMPILE_ABOVE_2SS))
  291. if (dm->support_ic_type & PHYDM_IC_ABOVE_2SS)
  292. odm_set_bb_reg(dm, R_0x1d70, ODM_BIT_IGI_B_11AC3, igi);
  293. #endif
  294. #if (defined(PHYDM_COMPILE_ABOVE_4SS))
  295. if (dm->support_ic_type & PHYDM_IC_ABOVE_4SS) {
  296. odm_set_bb_reg(dm, R_0x1d70, ODM_BIT_IGI_C_11AC3, igi);
  297. odm_set_bb_reg(dm, R_0x1d70, ODM_BIT_IGI_D_11AC3, igi);
  298. }
  299. #endif
  300. }
  301. u8 phydm_get_igi_reg_val_jgr3(void *dm_void, enum bb_path path)
  302. {
  303. struct dm_struct *dm = (struct dm_struct *)dm_void;
  304. u32 val = 0;
  305. PHYDM_DBG(dm, DBG_DIG, "%s===>\n", __func__);
  306. /* Set IGI value */
  307. if (!(dm->support_ic_type & ODM_IC_JGR3_SERIES))
  308. return (u8)val;
  309. if (path == BB_PATH_A)
  310. val = odm_get_bb_reg(dm, R_0x1d70, ODM_BIT_IGI_11AC);
  311. else if (path == BB_PATH_B)
  312. #if (defined(PHYDM_COMPILE_ABOVE_2SS))
  313. val = odm_get_bb_reg(dm, R_0x1d70, ODM_BIT_IGI_B_11AC3);
  314. #else
  315. ;
  316. #endif
  317. else if (path == BB_PATH_C)
  318. #if (defined(PHYDM_COMPILE_ABOVE_3SS))
  319. val = odm_get_bb_reg(dm, R_0x1d70, ODM_BIT_IGI_C_11AC3);
  320. #else
  321. ;
  322. #endif
  323. else if (path == BB_PATH_D)
  324. #if (defined(PHYDM_COMPILE_ABOVE_4SS))
  325. val = odm_get_bb_reg(dm, R_0x1d70, ODM_BIT_IGI_D_11AC3);
  326. #else
  327. ;
  328. #endif
  329. return (u8)val;
  330. }
  331. void phydm_fa_cnt_statistics_jgr3(void *dm_void)
  332. {
  333. struct dm_struct *dm = (struct dm_struct *)dm_void;
  334. struct phydm_fa_struct *fa_t = &dm->false_alm_cnt;
  335. u32 ret_value = 0;
  336. u32 cck_enable = 0;
  337. u16 ofdm_tx_counter = 0;
  338. u16 cck_tx_counter = 0;
  339. if (!(dm->support_ic_type & ODM_IC_JGR3_SERIES))
  340. return;
  341. ofdm_tx_counter = (u16)odm_get_bb_reg(dm, R_0x2de0, MASKLWORD);
  342. cck_tx_counter = (u16)odm_get_bb_reg(dm, R_0x2de4, MASKLWORD);
  343. ret_value = odm_get_bb_reg(dm, R_0x2d20, MASKDWORD);
  344. fa_t->cnt_fast_fsync = (ret_value & 0xffff);
  345. fa_t->cnt_sb_search_fail = ((ret_value & 0xffff0000) >> 16);
  346. ret_value = odm_get_bb_reg(dm, R_0x2d04, MASKDWORD);
  347. fa_t->cnt_parity_fail = ((ret_value & 0xffff0000) >> 16);
  348. ret_value = odm_get_bb_reg(dm, R_0x2d08, MASKDWORD);
  349. fa_t->cnt_rate_illegal = (ret_value & 0xffff);
  350. fa_t->cnt_crc8_fail = ((ret_value & 0xffff0000) >> 16);
  351. ret_value = odm_get_bb_reg(dm, R_0x2d10, MASKDWORD);
  352. fa_t->cnt_mcs_fail = (ret_value & 0xffff);
  353. /* read OFDM FA counter */
  354. fa_t->cnt_ofdm_fail = odm_get_bb_reg(dm, R_0x2d00, MASKLWORD);
  355. /* Read CCK FA counter */
  356. fa_t->cnt_cck_fail = odm_get_bb_reg(dm, R_0x1a5c, MASKLWORD);
  357. /* read CCK/OFDM CCA counter */
  358. ret_value = odm_get_bb_reg(dm, R_0x2c08, MASKDWORD);
  359. fa_t->cnt_ofdm_cca = ((ret_value & 0xffff0000) >> 16);
  360. fa_t->cnt_cck_cca = ret_value & 0xffff;
  361. /* read CCK CRC32 counter */
  362. ret_value = odm_get_bb_reg(dm, R_0x2c04, MASKDWORD);
  363. fa_t->cnt_cck_crc32_error = ((ret_value & 0xffff0000) >> 16);
  364. fa_t->cnt_cck_crc32_ok = ret_value & 0xffff;
  365. /* read OFDM CRC32 counter */
  366. ret_value = odm_get_bb_reg(dm, R_0x2c14, MASKDWORD);
  367. fa_t->cnt_ofdm_crc32_error = ((ret_value & 0xffff0000) >> 16);
  368. fa_t->cnt_ofdm_crc32_ok = ret_value & 0xffff;
  369. /* read HT CRC32 counter */
  370. ret_value = odm_get_bb_reg(dm, R_0x2c10, MASKDWORD);
  371. fa_t->cnt_ht_crc32_error = ((ret_value & 0xffff0000) >> 16);
  372. fa_t->cnt_ht_crc32_ok = ret_value & 0xffff;
  373. /* @for VHT part */
  374. if (dm->support_ic_type & ODM_RTL8822C) {
  375. /* read VHT CRC32 counter */
  376. ret_value = odm_get_bb_reg(dm, R_0x2c0c, MASKDWORD);
  377. fa_t->cnt_vht_crc32_error = ((ret_value & 0xffff0000) >> 16);
  378. fa_t->cnt_vht_crc32_ok = ret_value & 0xffff;
  379. ret_value = odm_get_bb_reg(dm, R_0x2d10, MASKDWORD);
  380. fa_t->cnt_mcs_fail_vht = ((ret_value & 0xffff0000) >> 16);
  381. ret_value = odm_get_bb_reg(dm, R_0x2d0c, MASKDWORD);
  382. fa_t->cnt_crc8_fail_vht = ret_value & 0xffff +
  383. ((ret_value & 0xffff0000) >> 16);
  384. } else {
  385. fa_t->cnt_vht_crc32_error = 0;
  386. fa_t->cnt_vht_crc32_ok = 0;
  387. fa_t->cnt_mcs_fail_vht = 0;
  388. fa_t->cnt_crc8_fail_vht = 0;
  389. }
  390. cck_enable = odm_get_bb_reg(dm, R_0x1c3c, BIT(1)); /* @98f 1C3c[1] */
  391. if (cck_enable) { /* @if(*dm->band_type == ODM_BAND_2_4G) */
  392. fa_t->cnt_all = fa_t->cnt_ofdm_fail + fa_t->cnt_cck_fail
  393. - ofdm_tx_counter;
  394. fa_t->cnt_cca_all = fa_t->cnt_cck_cca + fa_t->cnt_ofdm_cca;
  395. PHYDM_DBG(dm, DBG_FA_CNT, "ac3 OFDM FA = %d, CCK FA = %d\n",
  396. fa_t->cnt_ofdm_fail - ofdm_tx_counter,
  397. fa_t->cnt_cck_fail);
  398. } else {
  399. fa_t->cnt_all = fa_t->cnt_ofdm_fail - ofdm_tx_counter;
  400. fa_t->cnt_cca_all = fa_t->cnt_ofdm_cca;
  401. PHYDM_DBG(dm, DBG_FA_CNT, "ac3 CCK disable OFDM FA = %d\n",
  402. fa_t->cnt_ofdm_fail - ofdm_tx_counter);
  403. }
  404. PHYDM_DBG(dm, DBG_FA_CNT,
  405. "ac3 [OFDM FA Detail] Parity_fail=((%d)), Rate_Illegal=((%d)), CRC8_fail=((%d)), Mcs_fail=((%d)), Fast_Fsync=((%d)), SBD_fail=((%d))\n",
  406. fa_t->cnt_parity_fail, fa_t->cnt_rate_illegal,
  407. fa_t->cnt_crc8_fail, fa_t->cnt_mcs_fail, fa_t->cnt_fast_fsync,
  408. fa_t->cnt_sb_search_fail);
  409. }
  410. #endif
  411. void phydm_write_dig_reg(void *dm_void, u8 igi)
  412. {
  413. struct dm_struct *dm = (struct dm_struct *)dm_void;
  414. PHYDM_DBG(dm, DBG_DIG, "%s===>\n", __func__);
  415. odm_set_bb_reg(dm, ODM_REG(IGI_A, dm), ODM_BIT(IGI, dm), igi);
  416. #if (defined(PHYDM_COMPILE_ABOVE_2SS))
  417. if (dm->support_ic_type & PHYDM_IC_ABOVE_2SS)
  418. odm_set_bb_reg(dm, ODM_REG(IGI_B, dm), ODM_BIT(IGI, dm), igi);
  419. #endif
  420. #if (defined(PHYDM_COMPILE_ABOVE_4SS))
  421. if (dm->support_ic_type & PHYDM_IC_ABOVE_4SS) {
  422. odm_set_bb_reg(dm, ODM_REG(IGI_C, dm), ODM_BIT(IGI, dm), igi);
  423. odm_set_bb_reg(dm, ODM_REG(IGI_D, dm), ODM_BIT(IGI, dm), igi);
  424. }
  425. #endif
  426. }
  427. void odm_write_dig(void *dm_void, u8 new_igi)
  428. {
  429. struct dm_struct *dm = (struct dm_struct *)dm_void;
  430. struct phydm_dig_struct *dig_t = &dm->dm_dig_table;
  431. struct phydm_adaptivity_struct *adaptivity = &dm->adaptivity;
  432. PHYDM_DBG(dm, DBG_DIG, "%s===>\n", __func__);
  433. /* @1 Check IGI by upper bound */
  434. if (adaptivity->igi_lmt_en &&
  435. new_igi > adaptivity->adapt_igi_up && dm->is_linked) {
  436. new_igi = adaptivity->adapt_igi_up;
  437. PHYDM_DBG(dm, DBG_DIG, "Force Adaptivity Up-bound=((0x%x))\n",
  438. new_igi);
  439. }
  440. #if (RTL8192F_SUPPORT)
  441. if ((dm->support_ic_type & ODM_RTL8192F) &&
  442. dm->cut_version == ODM_CUT_A &&
  443. new_igi > 0x38) {
  444. new_igi = 0x38;
  445. PHYDM_DBG(dm, DBG_DIG,
  446. "Force 92F Adaptivity Up-bound=((0x%x))\n", new_igi);
  447. }
  448. #endif
  449. if (dig_t->cur_ig_value != new_igi) {
  450. #if (RTL8822B_SUPPORT || RTL8197F_SUPPORT || RTL8192F_SUPPORT)
  451. /* @Modify big jump step for 8822B and 8197F */
  452. if (dm->support_ic_type &
  453. (ODM_RTL8822B | ODM_RTL8197F | ODM_RTL8192F))
  454. phydm_set_big_jump_step(dm, new_igi);
  455. #endif
  456. #if (ODM_PHY_STATUS_NEW_TYPE_SUPPORT)
  457. /* Set IGI value of CCK for new CCK AGC */
  458. if (dm->cck_new_agc &&
  459. (dm->support_ic_type & PHYSTS_2ND_TYPE_IC))
  460. odm_set_bb_reg(dm, R_0xa0c, 0x3f00, (new_igi >> 1));
  461. #endif
  462. /*@Add by YuChen for USB IO too slow issue*/
  463. if (!(dm->support_ic_type & ODM_IC_PWDB_EDCCA)) {
  464. if (dm->support_ability & ODM_BB_ADAPTIVITY &&
  465. new_igi < dig_t->cur_ig_value) {
  466. dig_t->cur_ig_value = new_igi;
  467. phydm_adaptivity(dm);
  468. }
  469. } else {
  470. if (dm->support_ability & ODM_BB_ADAPTIVITY &&
  471. new_igi > dig_t->cur_ig_value) {
  472. dig_t->cur_ig_value = new_igi;
  473. phydm_adaptivity(dm);
  474. }
  475. }
  476. #ifdef PHYDM_IC_JGR3_SERIES_SUPPORT
  477. if (dm->support_ic_type & ODM_IC_JGR3_SERIES)
  478. phydm_write_dig_reg_jgr3(dm, new_igi);
  479. else
  480. #endif
  481. phydm_write_dig_reg(dm, new_igi);
  482. dig_t->cur_ig_value = new_igi;
  483. }
  484. PHYDM_DBG(dm, DBG_DIG, "New_igi=((0x%x))\n\n", new_igi);
  485. }
  486. u8 phydm_get_igi_reg_val(void *dm_void, enum bb_path path)
  487. {
  488. struct dm_struct *dm = (struct dm_struct *)dm_void;
  489. u32 val = 0;
  490. u32 bit_map = ODM_BIT(IGI, dm);
  491. switch (path) {
  492. case BB_PATH_A:
  493. val = odm_get_bb_reg(dm, ODM_REG(IGI_A, dm), bit_map);
  494. break;
  495. #if (defined(PHYDM_COMPILE_ABOVE_2SS))
  496. case BB_PATH_B:
  497. val = odm_get_bb_reg(dm, ODM_REG(IGI_B, dm), bit_map);
  498. break;
  499. #endif
  500. #if (defined(PHYDM_COMPILE_ABOVE_3SS))
  501. case BB_PATH_C:
  502. val = odm_get_bb_reg(dm, ODM_REG(IGI_C, dm), bit_map);
  503. break;
  504. #endif
  505. #if (defined(PHYDM_COMPILE_ABOVE_4SS))
  506. case BB_PATH_D:
  507. val = odm_get_bb_reg(dm, ODM_REG(IGI_D, dm), bit_map);
  508. break;
  509. #endif
  510. default:
  511. break;
  512. }
  513. return (u8)val;
  514. }
  515. u8 phydm_get_igi(void *dm_void, enum bb_path path)
  516. {
  517. struct dm_struct *dm = (struct dm_struct *)dm_void;
  518. u8 val;
  519. #ifdef PHYDM_IC_JGR3_SERIES_SUPPORT
  520. if (dm->support_ic_type & ODM_IC_JGR3_SERIES)
  521. val = phydm_get_igi_reg_val_jgr3(dm, path);
  522. else
  523. #endif
  524. val = phydm_get_igi_reg_val(dm, path);
  525. return val;
  526. }
  527. void phydm_set_dig_val(void *dm_void, u32 *val_buf, u8 val_len)
  528. {
  529. struct dm_struct *dm = (struct dm_struct *)dm_void;
  530. if (val_len != 1) {
  531. PHYDM_DBG(dm, ODM_COMP_API, "[Error][DIG]Need val_len=1\n");
  532. return;
  533. }
  534. odm_write_dig(dm, (u8)(*val_buf));
  535. }
  536. void odm_pause_dig(void *dm_void, enum phydm_pause_type type,
  537. enum phydm_pause_level lv, u8 igi_input)
  538. {
  539. struct dm_struct *dm = (struct dm_struct *)dm_void;
  540. u8 rpt = false;
  541. u32 igi = (u32)igi_input;
  542. PHYDM_DBG(dm, DBG_DIG, "[%s]type=%d, LV=%d, igi=0x%x\n", __func__, type,
  543. lv, igi);
  544. switch (type) {
  545. case PHYDM_PAUSE:
  546. case PHYDM_PAUSE_NO_SET: {
  547. rpt = phydm_pause_func(dm, F00_DIG, PHYDM_PAUSE, lv, 1, &igi);
  548. break;
  549. }
  550. case PHYDM_RESUME: {
  551. rpt = phydm_pause_func(dm, F00_DIG, PHYDM_RESUME, lv, 1, &igi);
  552. break;
  553. }
  554. default:
  555. PHYDM_DBG(dm, DBG_DIG, "Wrong type\n");
  556. break;
  557. }
  558. PHYDM_DBG(dm, DBG_DIG, "pause_result=%d\n", rpt);
  559. }
  560. boolean
  561. phydm_dig_abort(void *dm_void)
  562. {
  563. struct dm_struct *dm = (struct dm_struct *)dm_void;
  564. #if (DM_ODM_SUPPORT_TYPE & ODM_WIN)
  565. void *adapter = dm->adapter;
  566. #endif
  567. /* support_ability */
  568. if ((!(dm->support_ability & ODM_BB_FA_CNT)) ||
  569. (!(dm->support_ability & ODM_BB_DIG)) ||
  570. *dm->is_scan_in_process) {
  571. PHYDM_DBG(dm, DBG_DIG, "Not Support\n");
  572. return true;
  573. }
  574. if (dm->pause_ability & ODM_BB_DIG) {
  575. PHYDM_DBG(dm, DBG_DIG, "Return: Pause DIG in LV=%d\n",
  576. dm->pause_lv_table.lv_dig);
  577. return true;
  578. }
  579. #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
  580. #if OS_WIN_FROM_WIN7(OS_VERSION)
  581. if (IsAPModeExist(adapter) && ((PADAPTER)(adapter))->bInHctTest) {
  582. PHYDM_DBG(dm, DBG_DIG, " Return: Is AP mode or In HCT Test\n");
  583. return true;
  584. }
  585. #endif
  586. #endif
  587. return false;
  588. }
  589. void phydm_dig_init(void *dm_void)
  590. {
  591. struct dm_struct *dm = (struct dm_struct *)dm_void;
  592. struct phydm_dig_struct *dig_t = &dm->dm_dig_table;
  593. #if (DM_ODM_SUPPORT_TYPE & (ODM_AP))
  594. struct phydm_fa_struct *false_alm_cnt = &dm->false_alm_cnt;
  595. #endif
  596. u32 ret_value = 0;
  597. u8 i;
  598. dig_t->dm_dig_max = DIG_MAX_BALANCE_MODE;
  599. dig_t->dm_dig_min = DIG_MIN_PERFORMANCE;
  600. dig_t->dig_max_of_min = DIG_MAX_OF_MIN_BALANCE_MODE;
  601. dig_t->cur_ig_value = phydm_get_igi(dm, BB_PATH_A);
  602. dig_t->is_media_connect = false;
  603. dig_t->fa_th[0] = 250;
  604. dig_t->fa_th[1] = 500;
  605. dig_t->fa_th[2] = 750;
  606. dig_t->is_dbg_fa_th = false;
  607. #if (DM_ODM_SUPPORT_TYPE & (ODM_AP))
  608. /* @For RTL8881A */
  609. false_alm_cnt->cnt_ofdm_fail_pre = 0;
  610. #endif
  611. dig_t->rx_gain_range_max = DIG_MAX_BALANCE_MODE;
  612. dig_t->rx_gain_range_min = dig_t->cur_ig_value;
  613. #if (RTL8822B_SUPPORT || RTL8197F_SUPPORT || RTL8192F_SUPPORT)
  614. dig_t->enable_adjust_big_jump = 1;
  615. if (dm->support_ic_type & ODM_RTL8822B)
  616. ret_value = odm_get_bb_reg(dm, R_0x8c8, MASKLWORD);
  617. else if (dm->support_ic_type & (ODM_RTL8197F | ODM_RTL8192F))
  618. ret_value = odm_get_bb_reg(dm, R_0xc74, MASKLWORD);
  619. dig_t->big_jump_step1 = (u8)(ret_value & 0xe) >> 1;
  620. dig_t->big_jump_step2 = (u8)(ret_value & 0x30) >> 4;
  621. dig_t->big_jump_step3 = (u8)(ret_value & 0xc0) >> 6;
  622. if (dm->support_ic_type &
  623. (ODM_RTL8822B | ODM_RTL8197F | ODM_RTL8192F)) {
  624. for (i = 0; i < sizeof(dig_t->big_jump_lmt); i++) {
  625. if (dig_t->big_jump_lmt[i] == 0)
  626. dig_t->big_jump_lmt[i] = 0x64;
  627. /* Set -10dBm as default value */
  628. }
  629. }
  630. #endif
  631. #ifdef PHYDM_TDMA_DIG_SUPPORT
  632. dm->original_dig_restore = true;
  633. #endif
  634. #ifdef CFG_DIG_DAMPING_CHK
  635. phydm_dig_recorder_reset(dm);
  636. dig_t->dig_dl_en = 1;
  637. #endif
  638. }
  639. void phydm_dig_abs_boundary_decision(struct dm_struct *dm, boolean is_dfs_band)
  640. {
  641. struct phydm_dig_struct *dig_t = &dm->dm_dig_table;
  642. if (!dm->is_linked) {
  643. dig_t->dm_dig_max = DIG_MAX_COVERAGR;
  644. dig_t->dm_dig_min = DIG_MIN_COVERAGE;
  645. } else if (is_dfs_band) {
  646. if (*dm->band_width == CHANNEL_WIDTH_20)
  647. dig_t->dm_dig_min = DIG_MIN_DFS + 2;
  648. else
  649. dig_t->dm_dig_min = DIG_MIN_DFS;
  650. dig_t->dig_max_of_min = DIG_MAX_OF_MIN_BALANCE_MODE;
  651. dig_t->dm_dig_max = DIG_MAX_BALANCE_MODE;
  652. } else {
  653. if (*dm->bb_op_mode == PHYDM_BALANCE_MODE) {
  654. /*service > 2 devices*/
  655. dig_t->dm_dig_max = DIG_MAX_BALANCE_MODE;
  656. #if (DIG_HW == 1)
  657. dig_t->dig_max_of_min = DIG_MIN_COVERAGE;
  658. #else
  659. dig_t->dig_max_of_min = DIG_MAX_OF_MIN_BALANCE_MODE;
  660. #endif
  661. } else if (*dm->bb_op_mode == PHYDM_PERFORMANCE_MODE) {
  662. /*service 1 devices*/
  663. dig_t->dm_dig_max = DIG_MAX_PERFORMANCE_MODE;
  664. dig_t->dig_max_of_min = DIG_MAX_OF_MIN_PERFORMANCE_MODE;
  665. }
  666. if (dm->support_ic_type &
  667. (ODM_RTL8814A | ODM_RTL8812 | ODM_RTL8821 | ODM_RTL8822B))
  668. dig_t->dm_dig_min = 0x1c;
  669. else if (dm->support_ic_type & ODM_RTL8197F)
  670. dig_t->dm_dig_min = 0x1e; /*@For HW setting*/
  671. else
  672. dig_t->dm_dig_min = DIG_MIN_PERFORMANCE;
  673. }
  674. PHYDM_DBG(dm, DBG_DIG, "Abs{Max, Min}={0x%x, 0x%x}, Max_of_min=0x%x\n",
  675. dig_t->dm_dig_max, dig_t->dm_dig_min, dig_t->dig_max_of_min);
  676. }
  677. void phydm_dig_dym_boundary_decision(struct dm_struct *dm)
  678. {
  679. struct phydm_dig_struct *dig_t = &dm->dm_dig_table;
  680. #ifdef CFG_DIG_DAMPING_CHK
  681. struct phydm_dig_recorder_strcut *dig_rc = &dig_t->dig_recorder_t;
  682. #endif
  683. u8 offset = 15, tmp_max = 0;
  684. u8 max_of_rssi_min = 0;
  685. PHYDM_DBG(dm, DBG_DIG, "%s ======>\n", __func__);
  686. if (!dm->is_linked) {
  687. /*@if no link, always stay at lower bound*/
  688. dig_t->rx_gain_range_max = dig_t->dig_max_of_min;
  689. dig_t->rx_gain_range_min = dig_t->dm_dig_min;
  690. PHYDM_DBG(dm, DBG_DIG, "No-Link, Dyn{Max, Min}={0x%x, 0x%x}\n",
  691. dig_t->rx_gain_range_max, dig_t->rx_gain_range_min);
  692. return;
  693. }
  694. PHYDM_DBG(dm, DBG_DIG, "rssi_min=%d, ofst=%d\n", dm->rssi_min, offset);
  695. /* @DIG lower bound */
  696. if (dm->rssi_min > dig_t->dig_max_of_min)
  697. dig_t->rx_gain_range_min = dig_t->dig_max_of_min;
  698. else if (dm->rssi_min < dig_t->dm_dig_min)
  699. dig_t->rx_gain_range_min = dig_t->dm_dig_min;
  700. else
  701. dig_t->rx_gain_range_min = dm->rssi_min;
  702. #ifdef CFG_DIG_DAMPING_CHK
  703. /*@Limit Dyn min by damping*/
  704. if (dig_t->dig_dl_en &&
  705. dig_rc->damping_limit_en &&
  706. dig_t->rx_gain_range_min < dig_rc->damping_limit_val) {
  707. PHYDM_DBG(dm, DBG_DIG,
  708. "[Limit by Damping] Dig_dyn_min=0x%x -> 0x%x\n",
  709. dig_t->rx_gain_range_min, dig_rc->damping_limit_val);
  710. dig_t->rx_gain_range_min = dig_rc->damping_limit_val;
  711. }
  712. #endif
  713. /* @DIG upper bound */
  714. tmp_max = dig_t->rx_gain_range_min + offset;
  715. if (dig_t->rx_gain_range_min != dm->rssi_min) {
  716. max_of_rssi_min = dm->rssi_min + offset;
  717. if (tmp_max > max_of_rssi_min)
  718. tmp_max = max_of_rssi_min;
  719. }
  720. if (tmp_max > dig_t->dm_dig_max)
  721. dig_t->rx_gain_range_max = dig_t->dm_dig_max;
  722. else if (tmp_max < dig_t->dm_dig_min)
  723. dig_t->rx_gain_range_max = dig_t->dm_dig_min;
  724. else
  725. dig_t->rx_gain_range_max = tmp_max;
  726. #ifdef CONFIG_PHYDM_ANTENNA_DIVERSITY
  727. /* @1 Force Lower Bound for AntDiv */
  728. if (!dm->is_one_entry_only &&
  729. (dm->support_ability & ODM_BB_ANT_DIV) &&
  730. (dm->ant_div_type == CG_TRX_HW_ANTDIV ||
  731. dm->ant_div_type == CG_TRX_SMART_ANTDIV)) {
  732. if (dig_t->ant_div_rssi_max > dig_t->dig_max_of_min)
  733. dig_t->rx_gain_range_min = dig_t->dig_max_of_min;
  734. else
  735. dig_t->rx_gain_range_min = (u8)dig_t->ant_div_rssi_max;
  736. PHYDM_DBG(dm, DBG_DIG, "Force Dyn-Min=0x%x, RSSI_max=0x%x\n",
  737. dig_t->rx_gain_range_min, dig_t->ant_div_rssi_max);
  738. }
  739. #endif
  740. PHYDM_DBG(dm, DBG_DIG, "Dyn{Max, Min}={0x%x, 0x%x}\n",
  741. dig_t->rx_gain_range_max, dig_t->rx_gain_range_min);
  742. }
  743. void phydm_dig_abnormal_case(struct dm_struct *dm)
  744. {
  745. struct phydm_dig_struct *dig_t = &dm->dm_dig_table;
  746. /* @Abnormal lower bound case */
  747. if (dig_t->rx_gain_range_min > dig_t->rx_gain_range_max)
  748. dig_t->rx_gain_range_min = dig_t->rx_gain_range_max;
  749. PHYDM_DBG(dm, DBG_DIG, "Abnoraml checked {Max, Min}={0x%x, 0x%x}\n",
  750. dig_t->rx_gain_range_max, dig_t->rx_gain_range_min);
  751. }
  752. u8 phydm_new_igi_by_fa(struct dm_struct *dm, u8 igi, u32 fa_cnt, u8 *step_size)
  753. {
  754. boolean dig_go_up_check = true;
  755. struct phydm_dig_struct *dig_t = &dm->dm_dig_table;
  756. #if 0
  757. /*@dig_go_up_check = phydm_dig_go_up_check(dm);*/
  758. #endif
  759. if (fa_cnt > dig_t->fa_th[2] && dig_go_up_check)
  760. igi = igi + step_size[0];
  761. else if ((fa_cnt > dig_t->fa_th[1]) && dig_go_up_check)
  762. igi = igi + step_size[1];
  763. else if (fa_cnt < dig_t->fa_th[0])
  764. igi = igi - step_size[2];
  765. return igi;
  766. }
  767. u8 phydm_get_new_igi(struct dm_struct *dm, u8 igi, u32 fa_cnt,
  768. boolean is_dfs_band)
  769. {
  770. struct phydm_dig_struct *dig_t = &dm->dm_dig_table;
  771. u8 step[3] = {0};
  772. boolean first_connect = false, first_dis_connect = false;
  773. first_connect = (dm->is_linked) && !dig_t->is_media_connect;
  774. first_dis_connect = (!dm->is_linked) && dig_t->is_media_connect;
  775. if (dm->is_linked) {
  776. if (dm->pre_rssi_min <= dm->rssi_min) {
  777. PHYDM_DBG(dm, DBG_DIG, "pre_rssi_min <= rssi_min\n");
  778. step[0] = 2;
  779. step[1] = 1;
  780. step[2] = 2;
  781. } else {
  782. step[0] = 4;
  783. step[1] = 2;
  784. step[2] = 2;
  785. }
  786. } else {
  787. step[0] = 2;
  788. step[1] = 1;
  789. step[2] = 2;
  790. }
  791. PHYDM_DBG(dm, DBG_DIG, "step = {-%d, +%d, +%d}\n", step[2], step[1],
  792. step[0]);
  793. if (first_connect) {
  794. if (is_dfs_band) {
  795. if (dm->rssi_min > DIG_MAX_DFS)
  796. igi = DIG_MAX_DFS;
  797. else
  798. igi = dm->rssi_min;
  799. PHYDM_DBG(dm, DBG_DIG, "DFS band:IgiMax=0x%x\n",
  800. dig_t->rx_gain_range_max);
  801. } else {
  802. igi = dig_t->rx_gain_range_min;
  803. }
  804. #if (DM_ODM_SUPPORT_TYPE & (ODM_WIN | ODM_CE))
  805. #if (RTL8812A_SUPPORT)
  806. if (dm->support_ic_type == ODM_RTL8812)
  807. odm_config_bb_with_header_file(dm,
  808. CONFIG_BB_AGC_TAB_DIFF);
  809. #endif
  810. #endif
  811. PHYDM_DBG(dm, DBG_DIG, "First connect: foce IGI=0x%x\n", igi);
  812. } else if (dm->is_linked) {
  813. PHYDM_DBG(dm, DBG_DIG, "Adjust IGI @ linked\n");
  814. /* @4 Abnormal # beacon case */
  815. #if (DM_ODM_SUPPORT_TYPE & (ODM_WIN | ODM_CE))
  816. if (dm->phy_dbg_info.num_qry_beacon_pkt < 5 &&
  817. fa_cnt < DM_DIG_FA_TH1 && dm->bsta_state &&
  818. dm->support_ic_type != ODM_RTL8723D) {
  819. dig_t->rx_gain_range_min = 0x1c;
  820. igi = dig_t->rx_gain_range_min;
  821. PHYDM_DBG(dm, DBG_DIG, "Beacon_num=%d,force igi=0x%x\n",
  822. dm->phy_dbg_info.num_qry_beacon_pkt, igi);
  823. } else {
  824. igi = phydm_new_igi_by_fa(dm, igi, fa_cnt, step);
  825. }
  826. #else
  827. igi = phydm_new_igi_by_fa(dm, igi, fa_cnt, step);
  828. #endif
  829. } else {
  830. /* @2 Before link */
  831. PHYDM_DBG(dm, DBG_DIG, "Adjust IGI before link\n");
  832. if (first_dis_connect) {
  833. igi = dig_t->dm_dig_min;
  834. PHYDM_DBG(dm, DBG_DIG,
  835. "First disconnect:foce IGI to lower bound\n");
  836. } else {
  837. PHYDM_DBG(dm, DBG_DIG, "Pre_IGI=((0x%x)), FA=((%d))\n",
  838. igi, fa_cnt);
  839. igi = phydm_new_igi_by_fa(dm, igi, fa_cnt, step);
  840. }
  841. }
  842. /*@Check IGI by dyn-upper/lower bound */
  843. if (igi < dig_t->rx_gain_range_min)
  844. igi = dig_t->rx_gain_range_min;
  845. if (igi > dig_t->rx_gain_range_max)
  846. igi = dig_t->rx_gain_range_max;
  847. PHYDM_DBG(dm, DBG_DIG, "fa_cnt = %d, IGI: 0x%x -> 0x%x\n",
  848. fa_cnt, dig_t->cur_ig_value, igi);
  849. return igi;
  850. }
  851. boolean phydm_dig_dfs_mode_en(void *dm_void)
  852. {
  853. struct dm_struct *dm = (struct dm_struct *)dm_void;
  854. boolean dfs_mode_en = false;
  855. /* @Modify lower bound for DFS band */
  856. if (dm->is_dfs_band) {
  857. #if (DM_ODM_SUPPORT_TYPE & (ODM_AP))
  858. dfs_mode_en = true;
  859. #else
  860. if (phydm_dfs_master_enabled(dm))
  861. dfs_mode_en = true;
  862. #endif
  863. PHYDM_DBG(dm, DBG_DIG, "In DFS band\n");
  864. }
  865. return dfs_mode_en;
  866. }
  867. void phydm_dig(void *dm_void)
  868. {
  869. struct dm_struct *dm = (struct dm_struct *)dm_void;
  870. struct phydm_dig_struct *dig_t = &dm->dm_dig_table;
  871. struct phydm_fa_struct *falm_cnt = &dm->false_alm_cnt;
  872. #ifdef PHYDM_TDMA_DIG_SUPPORT
  873. struct phydm_fa_acc_struct *falm_cnt_acc = &dm->false_alm_cnt_acc;
  874. #endif
  875. boolean first_connect, first_disconnect;
  876. u8 igi = dig_t->cur_ig_value;
  877. u8 new_igi = 0x20;
  878. u32 fa_cnt = falm_cnt->cnt_all;
  879. boolean dfs_mode_en = false;
  880. #ifdef PHYDM_TDMA_DIG_SUPPORT
  881. if (!(dm->original_dig_restore)) {
  882. if (dig_t->cur_ig_value_tdma == 0)
  883. dig_t->cur_ig_value_tdma = dig_t->cur_ig_value;
  884. igi = dig_t->cur_ig_value_tdma;
  885. fa_cnt = falm_cnt_acc->cnt_all_1sec;
  886. }
  887. #endif
  888. if (phydm_dig_abort(dm)) {
  889. dig_t->cur_ig_value = phydm_get_igi(dm, BB_PATH_A);
  890. return;
  891. }
  892. PHYDM_DBG(dm, DBG_DIG, "%s Start===>\n", __func__);
  893. /* @1 Update status */
  894. first_connect = (dm->is_linked) && !dig_t->is_media_connect;
  895. first_disconnect = (!dm->is_linked) && dig_t->is_media_connect;
  896. PHYDM_DBG(dm, DBG_DIG,
  897. "is_linked=%d, RSSI=%d, 1stConnect=%d, 1stDisconnect=%d\n",
  898. dm->is_linked, dm->rssi_min, first_connect, first_disconnect);
  899. PHYDM_DBG(dm, DBG_DIG, "DIG ((%s)) mode\n",
  900. (*dm->bb_op_mode ? "Balance" : "Performance"));
  901. /*@DFS mode enable check*/
  902. dfs_mode_en = phydm_dig_dfs_mode_en(dm);
  903. #ifdef CFG_DIG_DAMPING_CHK
  904. /*Record IGI History*/
  905. phydm_dig_recorder(dm, first_connect, igi, fa_cnt);
  906. /*@DIG Damping Check*/
  907. phydm_dig_damping_chk(dm);
  908. #endif
  909. /*@Absolute Boundary Decision */
  910. phydm_dig_abs_boundary_decision(dm, dfs_mode_en);
  911. /*@Dynamic Boundary Decision*/
  912. phydm_dig_dym_boundary_decision(dm);
  913. /*@Abnormal case check*/
  914. phydm_dig_abnormal_case(dm);
  915. /*@FA threshold decision */
  916. phydm_fa_threshold_check(dm, dfs_mode_en);
  917. /*Select new IGI by FA */
  918. new_igi = phydm_get_new_igi(dm, igi, fa_cnt, dfs_mode_en);
  919. /* @1 Update status */
  920. #ifdef PHYDM_TDMA_DIG_SUPPORT
  921. if (!(dm->original_dig_restore)) {
  922. dig_t->cur_ig_value_tdma = new_igi;
  923. /*@It is possible fa_acc_1sec_tsf >= */
  924. /*@1sec while tdma_dig_state == 0*/
  925. if (dig_t->tdma_dig_state != 0)
  926. odm_write_dig(dm, dig_t->cur_ig_value_tdma);
  927. } else
  928. #endif
  929. odm_write_dig(dm, new_igi);
  930. dig_t->is_media_connect = dm->is_linked;
  931. }
  932. void phydm_dig_lps_32k(void *dm_void)
  933. {
  934. struct dm_struct *dm = (struct dm_struct *)dm_void;
  935. u8 current_igi = dm->rssi_min;
  936. odm_write_dig(dm, current_igi);
  937. }
  938. void phydm_dig_by_rssi_lps(void *dm_void)
  939. {
  940. #if (DM_ODM_SUPPORT_TYPE & (ODM_WIN | ODM_CE))
  941. struct dm_struct *dm = (struct dm_struct *)dm_void;
  942. struct phydm_fa_struct *falm_cnt;
  943. u8 rssi_lower = DIG_MIN_LPS; /* @0x1E or 0x1C */
  944. u8 current_igi = dm->rssi_min;
  945. falm_cnt = &dm->false_alm_cnt;
  946. if (phydm_dig_abort(dm))
  947. return;
  948. current_igi = current_igi + RSSI_OFFSET_DIG_LPS;
  949. PHYDM_DBG(dm, DBG_DIG, "%s==>\n", __func__);
  950. /* Using FW PS mode to make IGI */
  951. /* @Adjust by FA in LPS MODE */
  952. if (falm_cnt->cnt_all > DM_DIG_FA_TH2_LPS)
  953. current_igi = current_igi + 4;
  954. else if (falm_cnt->cnt_all > DM_DIG_FA_TH1_LPS)
  955. current_igi = current_igi + 2;
  956. else if (falm_cnt->cnt_all < DM_DIG_FA_TH0_LPS)
  957. current_igi = current_igi - 2;
  958. /* @Lower bound checking */
  959. /* RSSI Lower bound check */
  960. if ((dm->rssi_min - 10) > DIG_MIN_LPS)
  961. rssi_lower = (dm->rssi_min - 10);
  962. else
  963. rssi_lower = DIG_MIN_LPS;
  964. /* Upper and Lower Bound checking */
  965. if (current_igi > DIG_MAX_LPS)
  966. current_igi = DIG_MAX_LPS;
  967. else if (current_igi < rssi_lower)
  968. current_igi = rssi_lower;
  969. PHYDM_DBG(dm, DBG_DIG, "fa_cnt_all=%d, rssi_min=%d, curr_igi=0x%x\n",
  970. falm_cnt->cnt_all, dm->rssi_min, current_igi);
  971. odm_write_dig(dm, current_igi);
  972. #endif
  973. }
  974. /* @3============================================================
  975. * 3 FASLE ALARM CHECK
  976. * 3============================================================
  977. */
  978. void phydm_false_alarm_counter_reg_reset(void *dm_void)
  979. {
  980. struct dm_struct *dm = (struct dm_struct *)dm_void;
  981. struct phydm_fa_struct *falm_cnt = &dm->false_alm_cnt;
  982. #ifdef PHYDM_TDMA_DIG_SUPPORT
  983. struct phydm_dig_struct *dig_t = &dm->dm_dig_table;
  984. struct phydm_fa_acc_struct *falm_cnt_acc = &dm->false_alm_cnt_acc;
  985. #endif
  986. u32 false_alm_cnt;
  987. #ifdef PHYDM_TDMA_DIG_SUPPORT
  988. if (!(dm->original_dig_restore)) {
  989. if (dig_t->cur_ig_value_tdma == 0)
  990. dig_t->cur_ig_value_tdma = dig_t->cur_ig_value;
  991. false_alm_cnt = falm_cnt_acc->cnt_all_1sec;
  992. } else
  993. #endif
  994. {
  995. false_alm_cnt = falm_cnt->cnt_all;
  996. }
  997. #ifdef PHYDM_IC_JGR3_SERIES_SUPPORT
  998. if (dm->support_ic_type & ODM_IC_JGR3_SERIES) {
  999. /* reset CCK FA counter */
  1000. odm_set_bb_reg(dm, R_0x1a2c, BIT(15) | BIT(14), 0);
  1001. odm_set_bb_reg(dm, R_0x1a2c, BIT(15) | BIT(14), 2);
  1002. /* reset CCK CCA counter */
  1003. odm_set_bb_reg(dm, R_0x1a2c, BIT(13) | BIT(12), 0);
  1004. odm_set_bb_reg(dm, R_0x1a2c, BIT(13) | BIT(12), 2);
  1005. /* reset OFDM CCA counter, OFDM FA counter*/
  1006. odm_set_bb_reg(dm, R_0x1eb4, BIT(25), 1);
  1007. odm_set_bb_reg(dm, R_0x1eb4, BIT(25), 0);
  1008. }
  1009. #endif
  1010. #if (ODM_IC_11N_SERIES_SUPPORT)
  1011. if (dm->support_ic_type & ODM_IC_11N_SERIES) {
  1012. /*reset false alarm counter registers*/
  1013. odm_set_bb_reg(dm, R_0xc0c, BIT(31), 1);
  1014. odm_set_bb_reg(dm, R_0xc0c, BIT(31), 0);
  1015. odm_set_bb_reg(dm, R_0xd00, BIT(27), 1);
  1016. odm_set_bb_reg(dm, R_0xd00, BIT(27), 0);
  1017. /*update ofdm counter*/
  1018. /*update page C counter*/
  1019. odm_set_bb_reg(dm, R_0xc00, BIT(31), 0);
  1020. /*update page D counter*/
  1021. odm_set_bb_reg(dm, R_0xd00, BIT(31), 0);
  1022. /*reset CCK CCA counter*/
  1023. odm_set_bb_reg(dm, R_0xa2c, BIT(13) | BIT(12), 0);
  1024. odm_set_bb_reg(dm, R_0xa2c, BIT(13) | BIT(12), 2);
  1025. /*reset CCK FA counter*/
  1026. odm_set_bb_reg(dm, R_0xa2c, BIT(15) | BIT(14), 0);
  1027. odm_set_bb_reg(dm, R_0xa2c, BIT(15) | BIT(14), 2);
  1028. /*reset CRC32 counter*/
  1029. odm_set_bb_reg(dm, R_0xf14, BIT(16), 1);
  1030. odm_set_bb_reg(dm, R_0xf14, BIT(16), 0);
  1031. }
  1032. #endif /* @#if (ODM_IC_11N_SERIES_SUPPORT) */
  1033. #if (ODM_IC_11AC_SERIES_SUPPORT)
  1034. if (dm->support_ic_type & ODM_IC_11AC_SERIES) {
  1035. #if (RTL8881A_SUPPORT)
  1036. /* Reset FA counter by enable/disable OFDM */
  1037. if ((dm->support_ic_type == ODM_RTL8881A) &&
  1038. false_alm_cnt->cnt_ofdm_fail_pre >= 0x7fff) {
  1039. /* reset OFDM */
  1040. odm_set_bb_reg(dm, R_0x808, BIT(29), 0);
  1041. odm_set_bb_reg(dm, R_0x808, BIT(29), 1);
  1042. false_alm_cnt->cnt_ofdm_fail_pre = 0;
  1043. PHYDM_DBG(dm, DBG_FA_CNT, "Reset FA_cnt\n");
  1044. }
  1045. #endif /* @#if (RTL8881A_SUPPORT) */
  1046. /* reset OFDM FA countner */
  1047. odm_set_bb_reg(dm, R_0x9a4, BIT(17), 1);
  1048. odm_set_bb_reg(dm, R_0x9a4, BIT(17), 0);
  1049. /* reset CCK FA counter */
  1050. odm_set_bb_reg(dm, R_0xa2c, BIT(15), 0);
  1051. odm_set_bb_reg(dm, R_0xa2c, BIT(15), 1);
  1052. /* reset CCA counter */
  1053. phydm_reset_bb_hw_cnt_ac(dm);
  1054. }
  1055. #endif /* @#if (ODM_IC_11AC_SERIES_SUPPORT) */
  1056. }
  1057. void phydm_false_alarm_counter_reg_hold(void *dm_void)
  1058. {
  1059. struct dm_struct *dm = (struct dm_struct *)dm_void;
  1060. if (dm->support_ic_type & ODM_IC_JGR3_SERIES) {
  1061. /* @hold cck counter */
  1062. odm_set_bb_reg(dm, R_0x1a2c, BIT(12), 1);
  1063. odm_set_bb_reg(dm, R_0x1a2c, BIT(14), 1);
  1064. } else if (dm->support_ic_type & ODM_IC_11N_SERIES) {
  1065. /*@hold ofdm counter*/
  1066. /*@hold page C counter*/
  1067. odm_set_bb_reg(dm, R_0xc00, BIT(31), 1);
  1068. /*@hold page D counter*/
  1069. odm_set_bb_reg(dm, R_0xd00, BIT(31), 1);
  1070. /*@hold cck counter*/
  1071. odm_set_bb_reg(dm, R_0xa2c, BIT(12), 1);
  1072. odm_set_bb_reg(dm, R_0xa2c, BIT(14), 1);
  1073. }
  1074. }
  1075. #if (ODM_IC_11N_SERIES_SUPPORT)
  1076. void phydm_fa_cnt_statistics_n(void *dm_void)
  1077. {
  1078. struct dm_struct *dm = (struct dm_struct *)dm_void;
  1079. struct phydm_fa_struct *fa_t = &dm->false_alm_cnt;
  1080. u32 reg = 0;
  1081. if (!(dm->support_ic_type & ODM_IC_11N_SERIES))
  1082. return;
  1083. /* @hold ofdm & cck counter */
  1084. phydm_false_alarm_counter_reg_hold(dm);
  1085. reg = odm_get_bb_reg(dm, ODM_REG_OFDM_FA_TYPE1_11N, MASKDWORD);
  1086. fa_t->cnt_fast_fsync = (reg & 0xffff);
  1087. fa_t->cnt_sb_search_fail = ((reg & 0xffff0000) >> 16);
  1088. reg = odm_get_bb_reg(dm, ODM_REG_OFDM_FA_TYPE2_11N, MASKDWORD);
  1089. fa_t->cnt_ofdm_cca = (reg & 0xffff);
  1090. fa_t->cnt_parity_fail = ((reg & 0xffff0000) >> 16);
  1091. reg = odm_get_bb_reg(dm, ODM_REG_OFDM_FA_TYPE3_11N, MASKDWORD);
  1092. fa_t->cnt_rate_illegal = (reg & 0xffff);
  1093. fa_t->cnt_crc8_fail = ((reg & 0xffff0000) >> 16);
  1094. reg = odm_get_bb_reg(dm, ODM_REG_OFDM_FA_TYPE4_11N, MASKDWORD);
  1095. fa_t->cnt_mcs_fail = (reg & 0xffff);
  1096. fa_t->cnt_ofdm_fail =
  1097. fa_t->cnt_parity_fail + fa_t->cnt_rate_illegal +
  1098. fa_t->cnt_crc8_fail + fa_t->cnt_mcs_fail +
  1099. fa_t->cnt_fast_fsync + fa_t->cnt_sb_search_fail;
  1100. /* read CCK CRC32 counter */
  1101. fa_t->cnt_cck_crc32_error = odm_get_bb_reg(dm, R_0xf84, MASKDWORD);
  1102. fa_t->cnt_cck_crc32_ok = odm_get_bb_reg(dm, R_0xf88, MASKDWORD);
  1103. /* read OFDM CRC32 counter */
  1104. reg = odm_get_bb_reg(dm, ODM_REG_OFDM_CRC32_CNT_11N, MASKDWORD);
  1105. fa_t->cnt_ofdm_crc32_error = (reg & 0xffff0000) >> 16;
  1106. fa_t->cnt_ofdm_crc32_ok = reg & 0xffff;
  1107. /* read HT CRC32 counter */
  1108. reg = odm_get_bb_reg(dm, ODM_REG_HT_CRC32_CNT_11N, MASKDWORD);
  1109. fa_t->cnt_ht_crc32_error = (reg & 0xffff0000) >> 16;
  1110. fa_t->cnt_ht_crc32_ok = reg & 0xffff;
  1111. /* read VHT CRC32 counter */
  1112. fa_t->cnt_vht_crc32_error = 0;
  1113. fa_t->cnt_vht_crc32_ok = 0;
  1114. #if (RTL8723D_SUPPORT)
  1115. if (dm->support_ic_type == ODM_RTL8723D) {
  1116. /* read HT CRC32 agg counter */
  1117. reg = odm_get_bb_reg(dm, R_0xfb8, MASKDWORD);
  1118. fa_t->cnt_ht_crc32_error_agg = (reg & 0xffff0000) >> 16;
  1119. fa_t->cnt_ht_crc32_ok_agg = reg & 0xffff;
  1120. }
  1121. #endif
  1122. #if (RTL8188E_SUPPORT)
  1123. if (dm->support_ic_type == ODM_RTL8188E) {
  1124. reg = odm_get_bb_reg(dm, ODM_REG_SC_CNT_11N, MASKDWORD);
  1125. fa_t->cnt_bw_lsc = (reg & 0xffff);
  1126. fa_t->cnt_bw_usc = ((reg & 0xffff0000) >> 16);
  1127. }
  1128. #endif
  1129. reg = odm_get_bb_reg(dm, ODM_REG_CCK_FA_LSB_11N, MASKBYTE0);
  1130. fa_t->cnt_cck_fail = reg;
  1131. reg = odm_get_bb_reg(dm, ODM_REG_CCK_FA_MSB_11N, MASKBYTE3);
  1132. fa_t->cnt_cck_fail += (reg & 0xff) << 8;
  1133. reg = odm_get_bb_reg(dm, ODM_REG_CCK_CCA_CNT_11N, MASKDWORD);
  1134. fa_t->cnt_cck_cca = ((reg & 0xFF) << 8) | ((reg & 0xFF00) >> 8);
  1135. fa_t->cnt_all_pre = fa_t->cnt_all;
  1136. fa_t->cnt_all = fa_t->cnt_fast_fsync +
  1137. fa_t->cnt_sb_search_fail +
  1138. fa_t->cnt_parity_fail +
  1139. fa_t->cnt_rate_illegal +
  1140. fa_t->cnt_crc8_fail +
  1141. fa_t->cnt_mcs_fail +
  1142. fa_t->cnt_cck_fail;
  1143. fa_t->cnt_cca_all = fa_t->cnt_ofdm_cca + fa_t->cnt_cck_cca;
  1144. PHYDM_DBG(dm, DBG_FA_CNT,
  1145. "[OFDM FA Detail] Parity_Fail=((%d)), Rate_Illegal=((%d)), CRC8_fail=((%d)), Mcs_fail=((%d)), Fast_Fsync=(( %d )), SBD_fail=((%d))\n",
  1146. fa_t->cnt_parity_fail, fa_t->cnt_rate_illegal,
  1147. fa_t->cnt_crc8_fail, fa_t->cnt_mcs_fail, fa_t->cnt_fast_fsync,
  1148. fa_t->cnt_sb_search_fail);
  1149. }
  1150. #endif
  1151. #if (ODM_IC_11AC_SERIES_SUPPORT == 1)
  1152. void phydm_fa_cnt_statistics_ac(void *dm_void)
  1153. {
  1154. struct dm_struct *dm = (struct dm_struct *)dm_void;
  1155. struct phydm_fa_struct *fa_t = &dm->false_alm_cnt;
  1156. u32 ret_value = 0;
  1157. u32 cck_enable;
  1158. if (!(dm->support_ic_type & ODM_IC_11AC_SERIES))
  1159. return;
  1160. ret_value = odm_get_bb_reg(dm, ODM_REG_OFDM_FA_TYPE1_11AC, MASKDWORD);
  1161. fa_t->cnt_fast_fsync = ((ret_value & 0xffff0000) >> 16);
  1162. ret_value = odm_get_bb_reg(dm, ODM_REG_OFDM_FA_TYPE2_11AC, MASKDWORD);
  1163. fa_t->cnt_sb_search_fail = (ret_value & 0xffff);
  1164. ret_value = odm_get_bb_reg(dm, ODM_REG_OFDM_FA_TYPE3_11AC, MASKDWORD);
  1165. fa_t->cnt_parity_fail = (ret_value & 0xffff);
  1166. fa_t->cnt_rate_illegal = ((ret_value & 0xffff0000) >> 16);
  1167. ret_value = odm_get_bb_reg(dm, ODM_REG_OFDM_FA_TYPE4_11AC, MASKDWORD);
  1168. fa_t->cnt_crc8_fail = (ret_value & 0xffff);
  1169. fa_t->cnt_mcs_fail = ((ret_value & 0xffff0000) >> 16);
  1170. ret_value = odm_get_bb_reg(dm, ODM_REG_OFDM_FA_TYPE5_11AC, MASKDWORD);
  1171. fa_t->cnt_crc8_fail_vht = (ret_value & 0xffff) +
  1172. (ret_value & 0xffff0000 >> 16);
  1173. ret_value = odm_get_bb_reg(dm, ODM_REG_OFDM_FA_TYPE6_11AC, MASKDWORD);
  1174. fa_t->cnt_mcs_fail_vht = (ret_value & 0xffff);
  1175. /* read OFDM FA counter */
  1176. fa_t->cnt_ofdm_fail = odm_get_bb_reg(dm, R_0xf48, MASKLWORD);
  1177. /* Read CCK FA counter */
  1178. fa_t->cnt_cck_fail = odm_get_bb_reg(dm, ODM_REG_CCK_FA_11AC, MASKLWORD);
  1179. /* read CCK/OFDM CCA counter */
  1180. ret_value = odm_get_bb_reg(dm, ODM_REG_CCK_CCA_CNT_11AC, MASKDWORD);
  1181. fa_t->cnt_ofdm_cca = (ret_value & 0xffff0000) >> 16;
  1182. fa_t->cnt_cck_cca = ret_value & 0xffff;
  1183. /* read CCK CRC32 counter */
  1184. ret_value = odm_get_bb_reg(dm, ODM_REG_CCK_CRC32_CNT_11AC, MASKDWORD);
  1185. fa_t->cnt_cck_crc32_error = (ret_value & 0xffff0000) >> 16;
  1186. fa_t->cnt_cck_crc32_ok = ret_value & 0xffff;
  1187. /* read OFDM CRC32 counter */
  1188. ret_value = odm_get_bb_reg(dm, ODM_REG_OFDM_CRC32_CNT_11AC, MASKDWORD);
  1189. fa_t->cnt_ofdm_crc32_error = (ret_value & 0xffff0000) >> 16;
  1190. fa_t->cnt_ofdm_crc32_ok = ret_value & 0xffff;
  1191. /* read HT CRC32 counter */
  1192. ret_value = odm_get_bb_reg(dm, ODM_REG_HT_CRC32_CNT_11AC, MASKDWORD);
  1193. fa_t->cnt_ht_crc32_error = (ret_value & 0xffff0000) >> 16;
  1194. fa_t->cnt_ht_crc32_ok = ret_value & 0xffff;
  1195. /* read VHT CRC32 counter */
  1196. ret_value = odm_get_bb_reg(dm, ODM_REG_VHT_CRC32_CNT_11AC, MASKDWORD);
  1197. fa_t->cnt_vht_crc32_error = (ret_value & 0xffff0000) >> 16;
  1198. fa_t->cnt_vht_crc32_ok = ret_value & 0xffff;
  1199. #if (RTL8881A_SUPPORT)
  1200. if (dm->support_ic_type == ODM_RTL8881A) {
  1201. u32 tmp = 0;
  1202. if (fa_t->cnt_ofdm_fail >= fa_t->cnt_ofdm_fail_pre) {
  1203. tmp = fa_t->cnt_ofdm_fail_pre;
  1204. fa_t->cnt_ofdm_fail_pre = fa_t->cnt_ofdm_fail;
  1205. fa_t->cnt_ofdm_fail = fa_t->cnt_ofdm_fail - tmp;
  1206. } else {
  1207. fa_t->cnt_ofdm_fail_pre = fa_t->cnt_ofdm_fail;
  1208. }
  1209. PHYDM_DBG(dm, DBG_FA_CNT,
  1210. "[8881]cnt_ofdm_fail{curr,pre}={%d,%d}\n",
  1211. fa_t->cnt_ofdm_fail_pre, tmp);
  1212. }
  1213. #endif
  1214. cck_enable = odm_get_bb_reg(dm, ODM_REG_BB_RX_PATH_11AC, BIT(28));
  1215. if (cck_enable) { /* @if(*dm->band_type == ODM_BAND_2_4G) */
  1216. fa_t->cnt_all = fa_t->cnt_ofdm_fail + fa_t->cnt_cck_fail;
  1217. fa_t->cnt_cca_all = fa_t->cnt_cck_cca + fa_t->cnt_ofdm_cca;
  1218. } else {
  1219. fa_t->cnt_all = fa_t->cnt_ofdm_fail;
  1220. fa_t->cnt_cca_all = fa_t->cnt_ofdm_cca;
  1221. }
  1222. }
  1223. #endif
  1224. void phydm_get_dbg_port_info(void *dm_void)
  1225. {
  1226. struct dm_struct *dm = (struct dm_struct *)dm_void;
  1227. struct phydm_fa_struct *fa_t = &dm->false_alm_cnt;
  1228. u32 dbg_port = dm->adaptivity.adaptivity_dbg_port;
  1229. u32 val = 0;
  1230. /*set debug port to 0x0*/
  1231. if (phydm_set_bb_dbg_port(dm, DBGPORT_PRI_1, 0x0)) {
  1232. fa_t->dbg_port0 = phydm_get_bb_dbg_port_val(dm);
  1233. phydm_release_bb_dbg_port(dm);
  1234. }
  1235. if (dm->support_ic_type & ODM_RTL8723D) {
  1236. val = odm_get_bb_reg(dm, R_0x9a0, BIT(29));
  1237. } else if (dm->support_ic_type & ODM_IC_JGR3_SERIES) {
  1238. val = odm_get_bb_reg(dm, R_0x2d38, BIT(24));
  1239. } else if (phydm_set_bb_dbg_port(dm, DBGPORT_PRI_1, dbg_port)) {
  1240. if (dm->support_ic_type & (ODM_RTL8723B | ODM_RTL8188E))
  1241. val = (phydm_get_bb_dbg_port_val(dm) & BIT(30)) >> 30;
  1242. else
  1243. val = (phydm_get_bb_dbg_port_val(dm) & BIT(29)) >> 29;
  1244. phydm_release_bb_dbg_port(dm);
  1245. }
  1246. fa_t->edcca_flag = (boolean)val;
  1247. PHYDM_DBG(dm, DBG_FA_CNT, "FA_Cnt: Dbg port 0x0 = 0x%x, EDCCA = %d\n\n",
  1248. fa_t->dbg_port0, fa_t->edcca_flag);
  1249. }
  1250. void phydm_false_alarm_counter_statistics(void *dm_void)
  1251. {
  1252. struct dm_struct *dm = (struct dm_struct *)dm_void;
  1253. struct phydm_fa_struct *fa_t = &dm->false_alm_cnt;
  1254. if (!(dm->support_ability & ODM_BB_FA_CNT))
  1255. return;
  1256. PHYDM_DBG(dm, DBG_FA_CNT, "%s======>\n", __func__);
  1257. if (dm->support_ic_type & ODM_IC_JGR3_SERIES) {
  1258. #ifdef PHYDM_IC_JGR3_SERIES_SUPPORT
  1259. phydm_fa_cnt_statistics_jgr3(dm);
  1260. #endif
  1261. } else if (dm->support_ic_type & ODM_IC_11N_SERIES) {
  1262. #if (ODM_IC_11N_SERIES_SUPPORT)
  1263. phydm_fa_cnt_statistics_n(dm);
  1264. #endif
  1265. } else if (dm->support_ic_type & ODM_IC_11AC_SERIES) {
  1266. #if (ODM_IC_11AC_SERIES_SUPPORT)
  1267. phydm_fa_cnt_statistics_ac(dm);
  1268. #endif
  1269. }
  1270. phydm_get_dbg_port_info(dm);
  1271. phydm_false_alarm_counter_reg_reset(dm_void);
  1272. fa_t->time_fa_all = fa_t->cnt_fast_fsync * 12 +
  1273. fa_t->cnt_sb_search_fail * 12 +
  1274. fa_t->cnt_parity_fail * 28 +
  1275. fa_t->cnt_rate_illegal * 28 +
  1276. fa_t->cnt_crc8_fail * 36 +
  1277. fa_t->cnt_crc8_fail_vht * 36 +
  1278. fa_t->cnt_mcs_fail_vht * 36 +
  1279. fa_t->cnt_mcs_fail * 32 +
  1280. fa_t->cnt_cck_fail * 80;
  1281. fa_t->cnt_crc32_error_all = fa_t->cnt_vht_crc32_error +
  1282. fa_t->cnt_ht_crc32_error +
  1283. fa_t->cnt_ofdm_crc32_error +
  1284. fa_t->cnt_cck_crc32_error;
  1285. fa_t->cnt_crc32_ok_all = fa_t->cnt_vht_crc32_ok +
  1286. fa_t->cnt_ht_crc32_ok +
  1287. fa_t->cnt_ofdm_crc32_ok +
  1288. fa_t->cnt_cck_crc32_ok;
  1289. PHYDM_DBG(dm, DBG_FA_CNT,
  1290. "[OFDM FA Detail-1] Parity=((%d)), Rate_Illegal=((%d)), HT_CRC8=((%d)), HT_MCS=((%d))\n",
  1291. fa_t->cnt_parity_fail, fa_t->cnt_rate_illegal,
  1292. fa_t->cnt_crc8_fail, fa_t->cnt_mcs_fail);
  1293. PHYDM_DBG(dm, DBG_FA_CNT,
  1294. "[OFDM FA Detail-2] Fast_Fsync=((%d)), SBD=((%d)), VHT_CRC8=((%d)), VHT_MCS=((%d))\n",
  1295. fa_t->cnt_fast_fsync, fa_t->cnt_sb_search_fail,
  1296. fa_t->cnt_crc8_fail_vht, fa_t->cnt_mcs_fail_vht);
  1297. PHYDM_DBG(dm, DBG_FA_CNT,
  1298. "[CCA Cnt] {CCK, OFDM, Total} = {%d, %d, %d}\n",
  1299. fa_t->cnt_cck_cca, fa_t->cnt_ofdm_cca, fa_t->cnt_cca_all);
  1300. PHYDM_DBG(dm, DBG_FA_CNT,
  1301. "[FA Cnt] {CCK, OFDM, Total} = {%d, %d, %d}\n",
  1302. fa_t->cnt_cck_fail, fa_t->cnt_ofdm_fail, fa_t->cnt_all);
  1303. PHYDM_DBG(dm, DBG_FA_CNT, "[CCK] CRC32 {error, ok}= {%d, %d}\n",
  1304. fa_t->cnt_cck_crc32_error, fa_t->cnt_cck_crc32_ok);
  1305. PHYDM_DBG(dm, DBG_FA_CNT, "[OFDM]CRC32 {error, ok}= {%d, %d}\n",
  1306. fa_t->cnt_ofdm_crc32_error, fa_t->cnt_ofdm_crc32_ok);
  1307. PHYDM_DBG(dm, DBG_FA_CNT, "[ HT ] CRC32 {error, ok}= {%d, %d}\n",
  1308. fa_t->cnt_ht_crc32_error, fa_t->cnt_ht_crc32_ok);
  1309. PHYDM_DBG(dm, DBG_FA_CNT, "[VHT] CRC32 {error, ok}= {%d, %d}\n",
  1310. fa_t->cnt_vht_crc32_error, fa_t->cnt_vht_crc32_ok);
  1311. PHYDM_DBG(dm, DBG_FA_CNT, "[TOTAL] CRC32 {error, ok}= {%d, %d}\n",
  1312. fa_t->cnt_crc32_error_all, fa_t->cnt_crc32_ok_all);
  1313. }
  1314. #ifdef PHYDM_TDMA_DIG_SUPPORT
  1315. void phydm_set_tdma_dig_timer(void *dm_void)
  1316. {
  1317. struct dm_struct *dm = (struct dm_struct *)dm_void;
  1318. u32 delta_time_us = dm->tdma_dig_timer_ms * 1000;
  1319. struct phydm_dig_struct *dig_t;
  1320. u32 timeout;
  1321. u32 current_time_stamp, diff_time_stamp, regb0;
  1322. dig_t = &dm->dm_dig_table;
  1323. /*some IC has no FREERUN_CUNT register, like 92E*/
  1324. if (dm->support_ic_type & ODM_RTL8197F)
  1325. current_time_stamp = odm_get_bb_reg(dm, R_0x568, 0xffffffff);
  1326. else
  1327. return;
  1328. timeout = current_time_stamp + delta_time_us;
  1329. diff_time_stamp = current_time_stamp - dig_t->cur_timestamp;
  1330. dig_t->pre_timestamp = dig_t->cur_timestamp;
  1331. dig_t->cur_timestamp = current_time_stamp;
  1332. /*@HIMR0, it shows HW interrupt mask*/
  1333. regb0 = odm_get_bb_reg(dm, R_0xb0, 0xffffffff);
  1334. PHYDM_DBG(dm, DBG_DIG, "Set next timer\n");
  1335. PHYDM_DBG(dm, DBG_DIG,
  1336. "curr_time_stamp=%d, delta_time_us=%d\n",
  1337. current_time_stamp, delta_time_us);
  1338. PHYDM_DBG(dm, DBG_DIG,
  1339. "timeout=%d, diff_time_stamp=%d, Reg0xb0 = 0x%x\n",
  1340. timeout, diff_time_stamp, regb0);
  1341. if (dm->support_ic_type & ODM_RTL8197F) /*REG_PS_TIMER2*/
  1342. odm_set_bb_reg(dm, R_0x588, 0xffffffff, timeout);
  1343. else {
  1344. PHYDM_DBG(dm, DBG_DIG, "NOT 97F, NOT start\n");
  1345. return;
  1346. }
  1347. }
  1348. void phydm_tdma_dig_timer_check(void *dm_void)
  1349. {
  1350. struct dm_struct *dm = (struct dm_struct *)dm_void;
  1351. struct phydm_dig_struct *dig_t;
  1352. dig_t = &dm->dm_dig_table;
  1353. PHYDM_DBG(dm, DBG_DIG, "tdma_dig_cnt=%d, pre_tdma_dig_cnt=%d\n",
  1354. dig_t->tdma_dig_cnt, dig_t->pre_tdma_dig_cnt);
  1355. if (dig_t->tdma_dig_cnt == 0 ||
  1356. dig_t->tdma_dig_cnt == dig_t->pre_tdma_dig_cnt) {
  1357. if (dm->support_ability & ODM_BB_DIG) {
  1358. #ifdef IS_USE_NEW_TDMA
  1359. if (dm->support_ic_type &
  1360. (ODM_RTL8198F | ODM_RTL8822C | ODM_RTL8814B)) {
  1361. PHYDM_DBG(dm, DBG_DIG,
  1362. "Check fail, Restart timer\n\n");
  1363. phydm_false_alarm_counter_reset(dm);
  1364. odm_set_timer(dm, &dm->tdma_dig_timer,
  1365. dm->tdma_dig_timer_ms);
  1366. } else {
  1367. PHYDM_DBG(dm, DBG_DIG,
  1368. "Not 98F/22C/14B no SW timer\n");
  1369. }
  1370. #else
  1371. /*@if interrupt mask info is got.*/
  1372. /*Reg0xb0 is no longer needed*/
  1373. #if 0
  1374. /*regb0 = odm_get_bb_reg(dm, R_0xb0, bMaskDWord);*/
  1375. #endif
  1376. PHYDM_DBG(dm, DBG_DIG,
  1377. "Check fail, Mask[0]=0x%x, restart timer\n",
  1378. *dm->interrupt_mask);
  1379. phydm_tdma_dig_add_interrupt_mask_handler(dm);
  1380. phydm_enable_rx_related_interrupt_handler(dm);
  1381. phydm_set_tdma_dig_timer(dm);
  1382. #endif
  1383. }
  1384. } else {
  1385. PHYDM_DBG(dm, DBG_DIG, "Check pass, update pre_tdma_dig_cnt\n");
  1386. }
  1387. dig_t->pre_tdma_dig_cnt = dig_t->tdma_dig_cnt;
  1388. }
  1389. /*@different IC/team may use different timer for tdma-dig*/
  1390. void phydm_tdma_dig_add_interrupt_mask_handler(void *dm_void)
  1391. {
  1392. struct dm_struct *dm = (struct dm_struct *)dm_void;
  1393. #if (DM_ODM_SUPPORT_TYPE == (ODM_AP))
  1394. if (dm->support_ic_type & ODM_RTL8197F) {
  1395. /*@HAL_INT_TYPE_PSTIMEOUT2*/
  1396. phydm_add_interrupt_mask_handler(dm, HAL_INT_TYPE_PSTIMEOUT2);
  1397. }
  1398. #elif (DM_ODM_SUPPORT_TYPE == (ODM_WIN))
  1399. #elif (DM_ODM_SUPPORT_TYPE == (ODM_CE))
  1400. #endif
  1401. }
  1402. /* will be triggered by HW timer*/
  1403. void phydm_tdma_dig(void *dm_void)
  1404. {
  1405. struct dm_struct *dm;
  1406. struct phydm_dig_struct *dig_t;
  1407. struct phydm_fa_struct *falm_cnt;
  1408. u32 reg_c50;
  1409. #if (RTL8198F_SUPPORT || RTL8822C_SUPPORT || RTL8814B_SUPPORT)
  1410. #ifdef IS_USE_NEW_TDMA
  1411. if (dm->support_ic_type &
  1412. (ODM_RTL8198F | ODM_RTL8822C | ODM_RTL8814B)) {
  1413. PHYDM_DBG(dm, DBG_DIG, "98F/22C/14B, new tdma\n");
  1414. return;
  1415. }
  1416. #endif
  1417. #endif
  1418. dm = (struct dm_struct *)dm_void;
  1419. dig_t = &dm->dm_dig_table;
  1420. falm_cnt = &dm->false_alm_cnt;
  1421. reg_c50 = odm_get_bb_reg(dm, R_0xc50, MASKBYTE0);
  1422. dig_t->tdma_dig_state =
  1423. dig_t->tdma_dig_cnt % dm->tdma_dig_state_number;
  1424. PHYDM_DBG(dm, DBG_DIG, "tdma_dig_state=%d, regc50=0x%x\n",
  1425. dig_t->tdma_dig_state, reg_c50);
  1426. dig_t->tdma_dig_cnt++;
  1427. if (dig_t->tdma_dig_state == 1) {
  1428. /* update IGI from tdma_dig_state == 0*/
  1429. if (dig_t->cur_ig_value_tdma == 0)
  1430. dig_t->cur_ig_value_tdma = dig_t->cur_ig_value;
  1431. odm_write_dig(dm, dig_t->cur_ig_value_tdma);
  1432. phydm_tdma_false_alarm_counter_check(dm);
  1433. PHYDM_DBG(dm, DBG_DIG, "tdma_dig_state=%d, reset FA counter\n",
  1434. dig_t->tdma_dig_state);
  1435. } else if (dig_t->tdma_dig_state == 0) {
  1436. /* update dig_t->CurIGValue,*/
  1437. /* @it may different from dig_t->cur_ig_value_tdma */
  1438. /* TDMA IGI upperbond @ L-state = */
  1439. /* rf_ft_var.tdma_dig_low_upper_bond = 0x26 */
  1440. if (dig_t->cur_ig_value >= dm->tdma_dig_low_upper_bond)
  1441. dig_t->low_ig_value = dm->tdma_dig_low_upper_bond;
  1442. else
  1443. dig_t->low_ig_value = dig_t->cur_ig_value;
  1444. odm_write_dig(dm, dig_t->low_ig_value);
  1445. phydm_tdma_false_alarm_counter_check(dm);
  1446. } else {
  1447. phydm_tdma_false_alarm_counter_check(dm);
  1448. }
  1449. }
  1450. /*@============================================================*/
  1451. /*@FASLE ALARM CHECK*/
  1452. /*@============================================================*/
  1453. void phydm_tdma_false_alarm_counter_check(void *dm_void)
  1454. {
  1455. struct dm_struct *dm;
  1456. struct phydm_fa_struct *falm_cnt;
  1457. struct phydm_fa_acc_struct *falm_cnt_acc;
  1458. struct phydm_dig_struct *dig_t;
  1459. boolean rssi_dump_en = 0;
  1460. u32 timestamp;
  1461. u8 tdma_dig_state_number;
  1462. u32 start_th = 0;
  1463. dm = (struct dm_struct *)dm_void;
  1464. falm_cnt = &dm->false_alm_cnt;
  1465. falm_cnt_acc = &dm->false_alm_cnt_acc;
  1466. dig_t = &dm->dm_dig_table;
  1467. if (dig_t->tdma_dig_state == 1)
  1468. phydm_false_alarm_counter_reset(dm);
  1469. /* Reset FalseAlarmCounterStatistics */
  1470. /* @fa_acc_1sec_tsf = fa_acc_1sec_tsf, keep */
  1471. /* @fa_end_tsf = fa_start_tsf = TSF */
  1472. else {
  1473. phydm_false_alarm_counter_statistics(dm);
  1474. if (dm->support_ic_type & ODM_RTL8197F) /*REG_FREERUN_CNT*/
  1475. timestamp = odm_get_bb_reg(dm, R_0x568, bMaskDWord);
  1476. else {
  1477. PHYDM_DBG(dm, DBG_DIG, "NOT 97F! NOT start\n");
  1478. return;
  1479. }
  1480. dig_t->fa_end_timestamp = timestamp;
  1481. dig_t->fa_acc_1sec_timestamp +=
  1482. (dig_t->fa_end_timestamp - dig_t->fa_start_timestamp);
  1483. /*prevent dumb*/
  1484. if (dm->tdma_dig_state_number == 1)
  1485. dm->tdma_dig_state_number = 2;
  1486. tdma_dig_state_number = dm->tdma_dig_state_number;
  1487. dig_t->sec_factor =
  1488. tdma_dig_state_number / (tdma_dig_state_number - 1);
  1489. /*@1sec = 1000000us*/
  1490. if (dig_t->sec_factor)
  1491. start_th = (u32)(1000000 / dig_t->sec_factor);
  1492. if (dig_t->fa_acc_1sec_timestamp >= start_th) {
  1493. rssi_dump_en = 1;
  1494. phydm_false_alarm_counter_acc(dm, rssi_dump_en);
  1495. PHYDM_DBG(dm, DBG_DIG,
  1496. "sec_factor=%d, total FA=%d, is_linked=%d\n",
  1497. dig_t->sec_factor, falm_cnt_acc->cnt_all,
  1498. dm->is_linked);
  1499. phydm_noisy_detection(dm);
  1500. #ifdef PHYDM_SUPPORT_CCKPD
  1501. phydm_cck_pd_th(dm);
  1502. #endif
  1503. phydm_dig(dm);
  1504. phydm_false_alarm_counter_acc_reset(dm);
  1505. /* Reset FalseAlarmCounterStatistics */
  1506. /* @fa_end_tsf = fa_start_tsf = TSF, keep */
  1507. /* @fa_acc_1sec_tsf = 0 */
  1508. phydm_false_alarm_counter_reset(dm);
  1509. } else {
  1510. phydm_false_alarm_counter_acc(dm, rssi_dump_en);
  1511. }
  1512. }
  1513. }
  1514. void phydm_false_alarm_counter_acc(void *dm_void, boolean rssi_dump_en)
  1515. {
  1516. struct dm_struct *dm = (struct dm_struct *)dm_void;
  1517. struct phydm_fa_struct *falm_cnt;
  1518. struct phydm_fa_acc_struct *falm_cnt_acc;
  1519. struct phydm_dig_struct *dig_t;
  1520. falm_cnt = &dm->false_alm_cnt;
  1521. falm_cnt_acc = &dm->false_alm_cnt_acc;
  1522. dig_t = &dm->dm_dig_table;
  1523. falm_cnt_acc->cnt_parity_fail += falm_cnt->cnt_parity_fail;
  1524. falm_cnt_acc->cnt_rate_illegal += falm_cnt->cnt_rate_illegal;
  1525. falm_cnt_acc->cnt_crc8_fail += falm_cnt->cnt_crc8_fail;
  1526. falm_cnt_acc->cnt_mcs_fail += falm_cnt->cnt_mcs_fail;
  1527. falm_cnt_acc->cnt_ofdm_fail += falm_cnt->cnt_ofdm_fail;
  1528. falm_cnt_acc->cnt_cck_fail += falm_cnt->cnt_cck_fail;
  1529. falm_cnt_acc->cnt_all += falm_cnt->cnt_all;
  1530. falm_cnt_acc->cnt_fast_fsync += falm_cnt->cnt_fast_fsync;
  1531. falm_cnt_acc->cnt_sb_search_fail += falm_cnt->cnt_sb_search_fail;
  1532. falm_cnt_acc->cnt_ofdm_cca += falm_cnt->cnt_ofdm_cca;
  1533. falm_cnt_acc->cnt_cck_cca += falm_cnt->cnt_cck_cca;
  1534. falm_cnt_acc->cnt_cca_all += falm_cnt->cnt_cca_all;
  1535. falm_cnt_acc->cnt_cck_crc32_error += falm_cnt->cnt_cck_crc32_error;
  1536. falm_cnt_acc->cnt_cck_crc32_ok += falm_cnt->cnt_cck_crc32_ok;
  1537. falm_cnt_acc->cnt_ofdm_crc32_error += falm_cnt->cnt_ofdm_crc32_error;
  1538. falm_cnt_acc->cnt_ofdm_crc32_ok += falm_cnt->cnt_ofdm_crc32_ok;
  1539. falm_cnt_acc->cnt_ht_crc32_error += falm_cnt->cnt_ht_crc32_error;
  1540. falm_cnt_acc->cnt_ht_crc32_ok += falm_cnt->cnt_ht_crc32_ok;
  1541. falm_cnt_acc->cnt_vht_crc32_error += falm_cnt->cnt_vht_crc32_error;
  1542. falm_cnt_acc->cnt_vht_crc32_ok += falm_cnt->cnt_vht_crc32_ok;
  1543. falm_cnt_acc->cnt_crc32_error_all += falm_cnt->cnt_crc32_error_all;
  1544. falm_cnt_acc->cnt_crc32_ok_all += falm_cnt->cnt_crc32_ok_all;
  1545. if (rssi_dump_en == 1) {
  1546. falm_cnt_acc->cnt_all_1sec =
  1547. falm_cnt_acc->cnt_all * dig_t->sec_factor;
  1548. falm_cnt_acc->cnt_cca_all_1sec =
  1549. falm_cnt_acc->cnt_cca_all * dig_t->sec_factor;
  1550. falm_cnt_acc->cnt_cck_fail_1sec =
  1551. falm_cnt_acc->cnt_cck_fail * dig_t->sec_factor;
  1552. }
  1553. }
  1554. void phydm_false_alarm_counter_acc_reset(void *dm_void)
  1555. {
  1556. struct dm_struct *dm = (struct dm_struct *)dm_void;
  1557. struct phydm_fa_acc_struct *falm_cnt_acc = NULL;
  1558. #ifdef IS_USE_NEW_TDMA
  1559. struct phydm_fa_acc_struct *falm_cnt_acc_low = NULL;
  1560. u32 tmp_cca_1sec = 0;
  1561. u32 tmp_fa_1sec = 0;
  1562. /*@clear L-fa_acc struct*/
  1563. falm_cnt_acc_low = &dm->false_alm_cnt_acc_low;
  1564. tmp_cca_1sec = falm_cnt_acc_low->cnt_cca_all_1sec;
  1565. tmp_fa_1sec = falm_cnt_acc_low->cnt_all_1sec;
  1566. odm_memory_set(dm, falm_cnt_acc_low, 0, sizeof(dm->false_alm_cnt_acc));
  1567. falm_cnt_acc_low->cnt_cca_all_1sec = tmp_cca_1sec;
  1568. falm_cnt_acc_low->cnt_all_1sec = tmp_fa_1sec;
  1569. /*@clear H-fa_acc struct*/
  1570. falm_cnt_acc = &dm->false_alm_cnt_acc;
  1571. tmp_cca_1sec = falm_cnt_acc->cnt_cca_all_1sec;
  1572. tmp_fa_1sec = falm_cnt_acc->cnt_all_1sec;
  1573. odm_memory_set(dm, falm_cnt_acc, 0, sizeof(dm->false_alm_cnt_acc));
  1574. falm_cnt_acc->cnt_cca_all_1sec = tmp_cca_1sec;
  1575. falm_cnt_acc->cnt_all_1sec = tmp_fa_1sec;
  1576. #else
  1577. falm_cnt_acc = &dm->false_alm_cnt_acc;
  1578. /* @Cnt_all_for_rssi_dump & Cnt_CCA_all_for_rssi_dump */
  1579. /* @do NOT need to be reset */
  1580. odm_memory_set(dm, falm_cnt_acc, 0, sizeof(falm_cnt_acc));
  1581. #endif
  1582. }
  1583. void phydm_false_alarm_counter_reset(void *dm_void)
  1584. {
  1585. struct dm_struct *dm = (struct dm_struct *)dm_void;
  1586. struct phydm_fa_struct *falm_cnt;
  1587. struct phydm_dig_struct *dig_t;
  1588. u32 timestamp;
  1589. falm_cnt = &dm->false_alm_cnt;
  1590. dig_t = &dm->dm_dig_table;
  1591. memset(falm_cnt, 0, sizeof(dm->false_alm_cnt));
  1592. phydm_false_alarm_counter_reg_reset(dm);
  1593. #ifdef IS_USE_NEW_TDMA
  1594. return;
  1595. #endif
  1596. if (dig_t->tdma_dig_state != 1)
  1597. dig_t->fa_acc_1sec_timestamp = 0;
  1598. else
  1599. dig_t->fa_acc_1sec_timestamp = dig_t->fa_acc_1sec_timestamp;
  1600. /*REG_FREERUN_CNT*/
  1601. timestamp = odm_get_bb_reg(dm, R_0x568, bMaskDWord);
  1602. dig_t->fa_start_timestamp = timestamp;
  1603. dig_t->fa_end_timestamp = timestamp;
  1604. }
  1605. #ifdef IS_USE_NEW_TDMA
  1606. void phydm_tdma_dig_timers(void *dm_void, u8 state)
  1607. {
  1608. #if (RTL8198F_SUPPORT || RTL8822C_SUPPORT || RTL8814B_SUPPORT)
  1609. struct dm_struct *dm = (struct dm_struct *)dm_void;
  1610. struct phydm_dig_struct *dig_t = &dm->dm_dig_table;
  1611. if (dm->support_ic_type &
  1612. (ODM_RTL8198F | ODM_RTL8822C | ODM_RTL8814B)) {
  1613. if (state == INIT_TDMA_DIG_TIMMER)
  1614. odm_initialize_timer(dm, &dm->tdma_dig_timer,
  1615. (void *)phydm_tdma_dig_cbk,
  1616. NULL, "phydm_tdma_dig_timer");
  1617. else if (state == CANCEL_TDMA_DIG_TIMMER)
  1618. odm_cancel_timer(dm, &dm->tdma_dig_timer);
  1619. else if (state == RELEASE_TDMA_DIG_TIMMER)
  1620. odm_release_timer(dm, &dm->tdma_dig_timer);
  1621. }
  1622. #endif
  1623. }
  1624. u8 get_new_igi_bound(struct dm_struct *dm, u8 igi, u32 fa_cnt, u8 *rx_gain_max,
  1625. u8 *rx_gain_min, boolean is_dfs_band)
  1626. {
  1627. struct phydm_dig_struct *dig_t = &dm->dm_dig_table;
  1628. u8 step[3] = {0};
  1629. u8 cur_igi = igi;
  1630. boolean first_connect = false, first_dis_connect = false;
  1631. first_connect = (dm->is_linked) && !dig_t->is_media_connect;
  1632. first_dis_connect = (!dm->is_linked) && dig_t->is_media_connect;
  1633. if (dm->is_linked) {
  1634. if (dm->pre_rssi_min <= dm->rssi_min) {
  1635. PHYDM_DBG(dm, DBG_DIG, "pre_rssi_min <= rssi_min\n");
  1636. step[0] = 2;
  1637. step[1] = 1;
  1638. step[2] = 2;
  1639. } else {
  1640. step[0] = 4;
  1641. step[1] = 2;
  1642. step[2] = 2;
  1643. }
  1644. } else {
  1645. step[0] = 2;
  1646. step[1] = 1;
  1647. step[2] = 2;
  1648. }
  1649. PHYDM_DBG(dm, DBG_DIG, "step = {-%d, +%d, +%d}\n", step[2], step[1],
  1650. step[0]);
  1651. if (first_connect) {
  1652. if (is_dfs_band) {
  1653. if (dm->rssi_min > DIG_MAX_DFS)
  1654. igi = DIG_MAX_DFS;
  1655. else
  1656. igi = dm->rssi_min;
  1657. PHYDM_DBG(dm, DBG_DIG, "DFS band:IgiMax=0x%x\n",
  1658. *rx_gain_max);
  1659. } else {
  1660. igi = *rx_gain_min;
  1661. }
  1662. #if (DM_ODM_SUPPORT_TYPE & (ODM_WIN | ODM_CE))
  1663. #if (RTL8812A_SUPPORT)
  1664. if (dm->support_ic_type == ODM_RTL8812)
  1665. odm_config_bb_with_header_file(dm,
  1666. CONFIG_BB_AGC_TAB_DIFF);
  1667. #endif
  1668. #endif
  1669. PHYDM_DBG(dm, DBG_DIG, "First connect: foce IGI=0x%x\n", igi);
  1670. } else if (dm->is_linked) {
  1671. PHYDM_DBG(dm, DBG_DIG, "Adjust IGI @ linked\n");
  1672. /* @4 Abnormal # beacon case */
  1673. #if (DM_ODM_SUPPORT_TYPE & (ODM_WIN | ODM_CE))
  1674. if (dm->phy_dbg_info.num_qry_beacon_pkt < 5 &&
  1675. fa_cnt < DM_DIG_FA_TH1 && dm->bsta_state &&
  1676. dm->support_ic_type != ODM_RTL8723D) {
  1677. *rx_gain_min = 0x1c;
  1678. igi = *rx_gain_min;
  1679. PHYDM_DBG(dm, DBG_DIG, "Beacon_num=%d,force igi=0x%x\n",
  1680. dm->phy_dbg_info.num_qry_beacon_pkt, igi);
  1681. } else {
  1682. igi = phydm_new_igi_by_fa(dm, igi, fa_cnt, step);
  1683. }
  1684. #else
  1685. igi = phydm_new_igi_by_fa(dm, igi, fa_cnt, step);
  1686. #endif
  1687. } else {
  1688. /* @2 Before link */
  1689. PHYDM_DBG(dm, DBG_DIG, "Adjust IGI before link\n");
  1690. if (first_dis_connect) {
  1691. igi = dig_t->dm_dig_min;
  1692. PHYDM_DBG(dm, DBG_DIG,
  1693. "First disconnect:foce IGI to lower bound\n");
  1694. } else {
  1695. PHYDM_DBG(dm, DBG_DIG, "Pre_IGI=((0x%x)), FA=((%d))\n",
  1696. igi, fa_cnt);
  1697. igi = phydm_new_igi_by_fa(dm, igi, fa_cnt, step);
  1698. }
  1699. }
  1700. /*@Check IGI by dyn-upper/lower bound */
  1701. if (igi < *rx_gain_min)
  1702. igi = *rx_gain_min;
  1703. if (igi > *rx_gain_max)
  1704. igi = *rx_gain_max;
  1705. PHYDM_DBG(dm, DBG_DIG, "fa_cnt = %d, IGI: 0x%x -> 0x%x\n",
  1706. fa_cnt, cur_igi, igi);
  1707. return igi;
  1708. }
  1709. /*@callback function triggered by SW timer*/
  1710. void phydm_tdma_dig_cbk(void *dm_void)
  1711. {
  1712. #if (RTL8198F_SUPPORT || RTL8822C_SUPPORT || RTL8814B_SUPPORT)
  1713. struct dm_struct *dm = (struct dm_struct *)dm_void;
  1714. struct phydm_dig_struct *dig_t = &dm->dm_dig_table;
  1715. if (phydm_dig_abort(dm) || (dm->original_dig_restore))
  1716. return;
  1717. /*@
  1718. *PHYDM_DBG(dm, DBG_DIG, "timer callback =======> tdma_dig_state=%d\n");
  1719. * dig_t->tdma_dig_state);
  1720. *PHYDM_DBG(dm, DBG_DIG, "tdma_h_igi=0x%x, tdma_l_igi=0x%x\n",
  1721. * dig_t->cur_ig_value_tdma,
  1722. * dig_t->low_ig_value);
  1723. */
  1724. phydm_tdma_fa_cnt_chk(dm);
  1725. /*@prevent dumb*/
  1726. if (dm->tdma_dig_state_number < 2)
  1727. dm->tdma_dig_state_number = 2;
  1728. /*@update state*/
  1729. dig_t->tdma_dig_cnt++;
  1730. dig_t->tdma_dig_state = dig_t->tdma_dig_cnt % dm->tdma_dig_state_number;
  1731. /*@
  1732. *PHYDM_DBG(dm, DBG_DIG, "enter state %d, dig count %d\n",
  1733. * dig_t->tdma_dig_state, dig_t->tdma_dig_cnt);
  1734. */
  1735. if (dig_t->tdma_dig_state == TDMA_DIG_LOW_STATE)
  1736. odm_write_dig(dm, dig_t->low_ig_value);
  1737. else if (dig_t->tdma_dig_state >= TDMA_DIG_HIGH_STATE)
  1738. odm_write_dig(dm, dig_t->cur_ig_value_tdma);
  1739. odm_set_timer(dm, &dm->tdma_dig_timer, dm->tdma_dig_timer_ms);
  1740. #endif
  1741. }
  1742. /*@============================================================*/
  1743. /*@FASLE ALARM CHECK*/
  1744. /*@============================================================*/
  1745. void phydm_tdma_fa_cnt_chk(void *dm_void)
  1746. {
  1747. struct dm_struct *dm = (struct dm_struct *)dm_void;
  1748. struct phydm_fa_struct *falm_cnt = &dm->false_alm_cnt;
  1749. struct phydm_fa_acc_struct *fa_t_acc, *fa_t_acc_low;
  1750. struct phydm_dig_struct *dig_t = NULL;
  1751. boolean rssi_dump_en = false;
  1752. u32 timestamp = 0;
  1753. u8 states_per_block = 0;
  1754. u8 cur_tdma_dig_state = 0;
  1755. u32 start_th = 0;
  1756. u8 state_diff = 0;
  1757. u32 tdma_dig_block_period_ms = 0;
  1758. u32 tdma_dig_block_cnt_thd = 0;
  1759. u32 timestamp_diff = 0;
  1760. if (!(dm->support_ic_type &
  1761. (ODM_RTL8198F | ODM_RTL8822C | ODM_RTL8814B))) {
  1762. PHYDM_DBG(dm, DBG_DIG, "Not 98F/22C/14B\n");
  1763. return;
  1764. }
  1765. fa_t_acc = &dm->false_alm_cnt_acc;
  1766. fa_t_acc_low = &dm->false_alm_cnt_acc_low;
  1767. dig_t = &dm->dm_dig_table;
  1768. states_per_block = dm->tdma_dig_state_number;
  1769. /*@calculate duration of a tdma block*/
  1770. tdma_dig_block_period_ms = dm->tdma_dig_timer_ms * states_per_block;
  1771. /*@
  1772. *caution!ONE_SEC_MS must be divisible by tdma_dig_block_period_ms,
  1773. *or FA will be fewer.
  1774. */
  1775. tdma_dig_block_cnt_thd = ONE_SEC_MS / tdma_dig_block_period_ms;
  1776. /*@tdma_dig_state == 0, collect H-state FA, else, collect L-state FA*/
  1777. if (dig_t->tdma_dig_state == TDMA_DIG_LOW_STATE)
  1778. cur_tdma_dig_state = TDMA_DIG_LOW_STATE;
  1779. else if (dig_t->tdma_dig_state >= TDMA_DIG_HIGH_STATE)
  1780. cur_tdma_dig_state = TDMA_DIG_HIGH_STATE;
  1781. /*@
  1782. *PHYDM_DBG(dm, DBG_DIG, "in state %d, dig count %d\n",
  1783. * cur_tdma_dig_state, dig_t->tdma_dig_cnt);
  1784. */
  1785. if (cur_tdma_dig_state == 0) {
  1786. /*@L-state indicates next block*/
  1787. dig_t->tdma_dig_block_cnt++;
  1788. /*@1sec dump check*/
  1789. if (dig_t->tdma_dig_block_cnt >= tdma_dig_block_cnt_thd)
  1790. rssi_dump_en = true;
  1791. /*@
  1792. *PHYDM_DBG(dm, DBG_DIG,"[L-state] tdma_dig_block_cnt=%d\n",
  1793. * dig_t->tdma_dig_block_cnt);
  1794. */
  1795. /*@collect FA till this block end*/
  1796. phydm_false_alarm_counter_statistics(dm);
  1797. phydm_fa_cnt_acc(dm, rssi_dump_en, cur_tdma_dig_state);
  1798. /*@1s L-FA collect end*/
  1799. /*@1sec dump reached*/
  1800. if (rssi_dump_en) {
  1801. /*@L-DIG*/
  1802. phydm_noisy_detection(dm);
  1803. #ifdef PHYDM_SUPPORT_CCKPD
  1804. phydm_cck_pd_th(dm);
  1805. #endif
  1806. PHYDM_DBG(dm, DBG_DIG, "run tdma L-state dig ====>\n");
  1807. phydm_tdma_low_dig(dm);
  1808. PHYDM_DBG(dm, DBG_DIG, "\n\n");
  1809. }
  1810. } else if (cur_tdma_dig_state == 1) {
  1811. /*@1sec dump check*/
  1812. if (dig_t->tdma_dig_block_cnt >= tdma_dig_block_cnt_thd)
  1813. rssi_dump_en = true;
  1814. /*@
  1815. *PHYDM_DBG(dm, DBG_DIG,"[H-state] tdma_dig_block_cnt=%d\n",
  1816. * dig_t->tdma_dig_block_cnt);
  1817. */
  1818. /*@collect FA till this block end*/
  1819. phydm_false_alarm_counter_statistics(dm);
  1820. phydm_fa_cnt_acc(dm, rssi_dump_en, cur_tdma_dig_state);
  1821. /*@1s H-FA collect end*/
  1822. /*@1sec dump reached*/
  1823. state_diff = dm->tdma_dig_state_number - dig_t->tdma_dig_state;
  1824. if (rssi_dump_en && (state_diff == 1)) {
  1825. /*@H-DIG*/
  1826. phydm_noisy_detection(dm);
  1827. #ifdef PHYDM_SUPPORT_CCKPD
  1828. phydm_cck_pd_th(dm);
  1829. #endif
  1830. PHYDM_DBG(dm, DBG_DIG, "run tdma H-state dig ====>\n");
  1831. phydm_tdma_high_dig(dm);
  1832. PHYDM_DBG(dm, DBG_DIG, "\n\n");
  1833. PHYDM_DBG(dm, DBG_DIG, "1 sec reached, is_linked=%d\n",
  1834. dm->is_linked);
  1835. PHYDM_DBG(dm, DBG_DIG, "1 sec L-CCA=%d, L-FA=%d\n",
  1836. fa_t_acc_low->cnt_cca_all_1sec,
  1837. fa_t_acc_low->cnt_all_1sec);
  1838. PHYDM_DBG(dm, DBG_DIG, "1 sec H-CCA=%d, H-FA=%d\n",
  1839. fa_t_acc->cnt_cca_all_1sec,
  1840. fa_t_acc->cnt_all_1sec);
  1841. PHYDM_DBG(dm, DBG_DIG,
  1842. "1 sec TOTAL-CCA=%d, TOTAL-FA=%d\n\n",
  1843. fa_t_acc->cnt_cca_all +
  1844. fa_t_acc_low->cnt_cca_all,
  1845. fa_t_acc->cnt_all + fa_t_acc_low->cnt_all);
  1846. /*@Reset AccFalseAlarmCounterStatistics */
  1847. phydm_false_alarm_counter_acc_reset(dm);
  1848. dig_t->tdma_dig_block_cnt = 0;
  1849. }
  1850. }
  1851. /*@Reset FalseAlarmCounterStatistics */
  1852. phydm_false_alarm_counter_reset(dm);
  1853. }
  1854. void phydm_tdma_low_dig(void *dm_void)
  1855. {
  1856. struct dm_struct *dm = (struct dm_struct *)dm_void;
  1857. struct phydm_dig_struct *dig_t = &dm->dm_dig_table;
  1858. struct phydm_fa_struct *falm_cnt = &dm->false_alm_cnt;
  1859. struct phydm_fa_acc_struct *falm_cnt_acc = &dm->false_alm_cnt_acc_low;
  1860. #ifdef CFG_DIG_DAMPING_CHK
  1861. struct phydm_dig_recorder_strcut *dig_rc = &dig_t->dig_recorder_t;
  1862. #endif
  1863. boolean first_connect, first_disconnect;
  1864. u8 igi = dig_t->cur_ig_value;
  1865. u8 new_igi = 0x20;
  1866. u8 tdma_l_igi = dig_t->low_ig_value;
  1867. u8 tdma_l_dym_min = dig_t->tdma_rx_gain_min[TDMA_DIG_LOW_STATE];
  1868. u8 tdma_l_dym_max = dig_t->tdma_rx_gain_max[TDMA_DIG_LOW_STATE];
  1869. u32 fa_cnt = falm_cnt->cnt_all;
  1870. boolean dfs_mode_en = false, is_performance = true;
  1871. u8 rssi_min = dm->rssi_min;
  1872. u8 igi_upper_rssi_min = 0;
  1873. u8 offset = 15;
  1874. if (!(dm->original_dig_restore)) {
  1875. if (tdma_l_igi == 0)
  1876. tdma_l_igi = igi;
  1877. fa_cnt = falm_cnt_acc->cnt_all_1sec;
  1878. }
  1879. if (phydm_dig_abort(dm)) {
  1880. dig_t->low_ig_value = phydm_get_igi(dm, BB_PATH_A);
  1881. return;
  1882. }
  1883. /*@Mode Decision*/
  1884. dfs_mode_en = false;
  1885. is_performance = true;
  1886. /* @Abs Boundary Decision*/
  1887. dig_t->dm_dig_max = DIG_MAX_COVERAGR; //0x26
  1888. dig_t->dm_dig_min = DIG_MIN_PERFORMANCE; //0x20
  1889. dig_t->dig_max_of_min = DIG_MAX_OF_MIN_COVERAGE; //0x22
  1890. if (dfs_mode_en) {
  1891. if (*dm->band_width == CHANNEL_WIDTH_20)
  1892. dig_t->dm_dig_min = DIG_MIN_DFS + 2;
  1893. else
  1894. dig_t->dm_dig_min = DIG_MIN_DFS;
  1895. } else {
  1896. if (dm->support_ic_type &
  1897. (ODM_RTL8814A | ODM_RTL8812 | ODM_RTL8821 | ODM_RTL8822B))
  1898. dig_t->dm_dig_min = 0x1c;
  1899. else if (dm->support_ic_type & ODM_RTL8197F)
  1900. dig_t->dm_dig_min = 0x1e; /*@For HW setting*/
  1901. }
  1902. PHYDM_DBG(dm, DBG_DIG, "Abs{Max, Min}={0x%x, 0x%x}, Max_of_min=0x%x\n",
  1903. dig_t->dm_dig_max, dig_t->dm_dig_min, dig_t->dig_max_of_min);
  1904. /* @Dyn Boundary by RSSI*/
  1905. if (!dm->is_linked) {
  1906. /*@if no link, always stay at lower bound*/
  1907. tdma_l_dym_max = 0x26;
  1908. tdma_l_dym_min = dig_t->dm_dig_min;
  1909. PHYDM_DBG(dm, DBG_DIG, "No-Link, Dyn{Max, Min}={0x%x, 0x%x}\n",
  1910. tdma_l_dym_max, tdma_l_dym_min);
  1911. } else {
  1912. PHYDM_DBG(dm, DBG_DIG, "rssi_min=%d, ofst=%d\n",
  1913. dm->rssi_min, offset);
  1914. /* @DIG lower bound in L-state*/
  1915. tdma_l_dym_min = dig_t->dm_dig_min;
  1916. #ifdef CFG_DIG_DAMPING_CHK
  1917. /*@Limit Dyn min by damping*/
  1918. if (dig_t->dig_dl_en &&
  1919. dig_rc->damping_limit_en &&
  1920. tdma_l_dym_min < dig_rc->damping_limit_val) {
  1921. PHYDM_DBG(dm, DBG_DIG,
  1922. "[Limit by Damping] dyn_min=0x%x -> 0x%x\n",
  1923. tdma_l_dym_min, dig_rc->damping_limit_val);
  1924. tdma_l_dym_min = dig_rc->damping_limit_val;
  1925. }
  1926. #endif
  1927. /*@DIG upper bound in L-state*/
  1928. igi_upper_rssi_min = rssi_min + offset;
  1929. if (igi_upper_rssi_min > dig_t->dm_dig_max)
  1930. tdma_l_dym_max = dig_t->dm_dig_max;
  1931. else if (igi_upper_rssi_min < dig_t->dm_dig_min)
  1932. tdma_l_dym_max = dig_t->dm_dig_min;
  1933. else
  1934. tdma_l_dym_max = igi_upper_rssi_min;
  1935. /* @1 Force Lower Bound for AntDiv */
  1936. /*@
  1937. *if (!dm->is_one_entry_only &&
  1938. *(dm->support_ability & ODM_BB_ANT_DIV) &&
  1939. *(dm->ant_div_type == CG_TRX_HW_ANTDIV ||
  1940. *dm->ant_div_type == CG_TRX_SMART_ANTDIV)) {
  1941. *if (dig_t->ant_div_rssi_max > dig_t->dig_max_of_min)
  1942. * dig_t->rx_gain_range_min = dig_t->dig_max_of_min;
  1943. *else
  1944. * dig_t->rx_gain_range_min = (u8)dig_t->ant_div_rssi_max;
  1945. *
  1946. *PHYDM_DBG(dm, DBG_DIG, "Force Dyn-Min=0x%x, RSSI_max=0x%x\n",
  1947. * dig_t->rx_gain_range_min, dig_t->ant_div_rssi_max);
  1948. *}
  1949. */
  1950. PHYDM_DBG(dm, DBG_DIG, "Dyn{Max, Min}={0x%x, 0x%x}\n",
  1951. tdma_l_dym_max, tdma_l_dym_min);
  1952. }
  1953. /*@Abnormal Case Check*/
  1954. /*@Abnormal lower bound case*/
  1955. if (tdma_l_dym_min > tdma_l_dym_max)
  1956. tdma_l_dym_min = tdma_l_dym_max;
  1957. PHYDM_DBG(dm, DBG_DIG,
  1958. "Abnoraml chk, force {Max, Min}={0x%x, 0x%x}\n",
  1959. tdma_l_dym_max, tdma_l_dym_min);
  1960. /*@False Alarm Threshold Decision*/
  1961. phydm_fa_threshold_check(dm, dfs_mode_en);
  1962. /*@Adjust Initial Gain by False Alarm*/
  1963. /*Select new IGI by FA */
  1964. if (!(dm->original_dig_restore)) {
  1965. tdma_l_igi = get_new_igi_bound(dm, tdma_l_igi, fa_cnt,
  1966. &tdma_l_dym_max,
  1967. &tdma_l_dym_min,
  1968. dfs_mode_en);
  1969. } else {
  1970. new_igi = phydm_get_new_igi(dm, igi, fa_cnt, dfs_mode_en);
  1971. }
  1972. /*Update status*/
  1973. if (!(dm->original_dig_restore)) {
  1974. dig_t->low_ig_value = tdma_l_igi;
  1975. dig_t->tdma_rx_gain_min[TDMA_DIG_LOW_STATE] = tdma_l_dym_min;
  1976. dig_t->tdma_rx_gain_max[TDMA_DIG_LOW_STATE] = tdma_l_dym_max;
  1977. #if 0
  1978. /*odm_write_dig(dm, tdma_l_igi);*/
  1979. #endif
  1980. } else {
  1981. odm_write_dig(dm, new_igi);
  1982. }
  1983. dig_t->is_media_connect = dm->is_linked;
  1984. }
  1985. void phydm_tdma_high_dig(void *dm_void)
  1986. {
  1987. struct dm_struct *dm = (struct dm_struct *)dm_void;
  1988. struct phydm_dig_struct *dig_t = &dm->dm_dig_table;
  1989. struct phydm_fa_struct *falm_cnt = &dm->false_alm_cnt;
  1990. struct phydm_fa_acc_struct *falm_cnt_acc = &dm->false_alm_cnt_acc;
  1991. #ifdef CFG_DIG_DAMPING_CHK
  1992. struct phydm_dig_recorder_strcut *dig_rc = &dig_t->dig_recorder_t;
  1993. #endif
  1994. boolean first_connect, first_disconnect;
  1995. u8 igi = dig_t->cur_ig_value;
  1996. u8 new_igi = 0x20;
  1997. u8 tdma_h_igi = dig_t->cur_ig_value_tdma;
  1998. u8 tdma_h_dym_min = dig_t->tdma_rx_gain_min[TDMA_DIG_HIGH_STATE];
  1999. u8 tdma_h_dym_max = dig_t->tdma_rx_gain_max[TDMA_DIG_HIGH_STATE];
  2000. u32 fa_cnt = falm_cnt->cnt_all;
  2001. boolean dfs_mode_en = false, is_performance = true;
  2002. u8 rssi_min = dm->rssi_min;
  2003. u8 igi_upper_rssi_min = 0;
  2004. u8 offset = 15;
  2005. if (!(dm->original_dig_restore)) {
  2006. if (tdma_h_igi == 0)
  2007. tdma_h_igi = igi;
  2008. fa_cnt = falm_cnt_acc->cnt_all_1sec;
  2009. }
  2010. if (phydm_dig_abort(dm)) {
  2011. dig_t->cur_ig_value_tdma = phydm_get_igi(dm, BB_PATH_A);
  2012. return;
  2013. }
  2014. /*@Mode Decision*/
  2015. dfs_mode_en = false;
  2016. is_performance = true;
  2017. /*@Abs Boundary Decision*/
  2018. dig_t->dig_max_of_min = DIG_MAX_OF_MIN_BALANCE_MODE; // 0x2a
  2019. if (!dm->is_linked) {
  2020. dig_t->dm_dig_max = DIG_MAX_COVERAGR;
  2021. dig_t->dm_dig_min = DIG_MIN_PERFORMANCE; // 0x20
  2022. } else if (dfs_mode_en) {
  2023. if (*dm->band_width == CHANNEL_WIDTH_20)
  2024. dig_t->dm_dig_min = DIG_MIN_DFS + 2;
  2025. else
  2026. dig_t->dm_dig_min = DIG_MIN_DFS;
  2027. dig_t->dig_max_of_min = DIG_MAX_OF_MIN_BALANCE_MODE;
  2028. dig_t->dm_dig_max = DIG_MAX_BALANCE_MODE;
  2029. } else {
  2030. if (*dm->bb_op_mode == PHYDM_BALANCE_MODE) {
  2031. /*service > 2 devices*/
  2032. dig_t->dm_dig_max = DIG_MAX_BALANCE_MODE;
  2033. #if (DIG_HW == 1)
  2034. dig_t->dig_max_of_min = DIG_MIN_COVERAGE;
  2035. #else
  2036. dig_t->dig_max_of_min = DIG_MAX_OF_MIN_BALANCE_MODE;
  2037. #endif
  2038. } else if (*dm->bb_op_mode == PHYDM_PERFORMANCE_MODE) {
  2039. /*service 1 devices*/
  2040. dig_t->dm_dig_max = DIG_MAX_PERFORMANCE_MODE;
  2041. dig_t->dig_max_of_min = DIG_MAX_OF_MIN_PERFORMANCE_MODE;
  2042. }
  2043. if (dm->support_ic_type &
  2044. (ODM_RTL8814A | ODM_RTL8812 | ODM_RTL8821 | ODM_RTL8822B))
  2045. dig_t->dm_dig_min = 0x1c;
  2046. else if (dm->support_ic_type & ODM_RTL8197F)
  2047. dig_t->dm_dig_min = 0x1e; /*@For HW setting*/
  2048. else
  2049. dig_t->dm_dig_min = DIG_MIN_PERFORMANCE;
  2050. }
  2051. PHYDM_DBG(dm, DBG_DIG, "Abs{Max, Min}={0x%x, 0x%x}, Max_of_min=0x%x\n",
  2052. dig_t->dm_dig_max, dig_t->dm_dig_min, dig_t->dig_max_of_min);
  2053. /*@Dyn Boundary by RSSI*/
  2054. if (!dm->is_linked) {
  2055. /*@if no link, always stay at lower bound*/
  2056. tdma_h_dym_max = dig_t->dig_max_of_min;
  2057. tdma_h_dym_min = dig_t->dm_dig_min;
  2058. PHYDM_DBG(dm, DBG_DIG, "No-Link, Dyn{Max, Min}={0x%x, 0x%x}\n",
  2059. tdma_h_dym_max, tdma_h_dym_min);
  2060. } else {
  2061. PHYDM_DBG(dm, DBG_DIG, "rssi_min=%d, ofst=%d\n",
  2062. dm->rssi_min, offset);
  2063. /* @DIG lower bound in H-state*/
  2064. if (rssi_min < dig_t->dm_dig_min)
  2065. tdma_h_dym_min = dig_t->dm_dig_min;
  2066. else
  2067. tdma_h_dym_min = rssi_min; // turbo not considered yet
  2068. #ifdef CFG_DIG_DAMPING_CHK
  2069. /*@Limit Dyn min by damping*/
  2070. if (dig_t->dig_dl_en &&
  2071. dig_rc->damping_limit_en &&
  2072. tdma_h_dym_min < dig_rc->damping_limit_val) {
  2073. PHYDM_DBG(dm, DBG_DIG,
  2074. "[Limit by Damping] dyn_min=0x%x -> 0x%x\n",
  2075. tdma_h_dym_min, dig_rc->damping_limit_val);
  2076. tdma_h_dym_min = dig_rc->damping_limit_val;
  2077. }
  2078. #endif
  2079. /*@DIG upper bound in H-state*/
  2080. igi_upper_rssi_min = rssi_min + offset;
  2081. if (igi_upper_rssi_min > dig_t->dm_dig_max)
  2082. tdma_h_dym_max = dig_t->dm_dig_max;
  2083. else
  2084. tdma_h_dym_max = igi_upper_rssi_min;
  2085. /* @1 Force Lower Bound for AntDiv */
  2086. /*@
  2087. *if (!dm->is_one_entry_only &&
  2088. *(dm->support_ability & ODM_BB_ANT_DIV) &&
  2089. *(dm->ant_div_type == CG_TRX_HW_ANTDIV ||
  2090. *dm->ant_div_type == CG_TRX_SMART_ANTDIV)) {
  2091. * if (dig_t->ant_div_rssi_max > dig_t->dig_max_of_min)
  2092. * dig_t->rx_gain_range_min = dig_t->dig_max_of_min;
  2093. * else
  2094. * dig_t->rx_gain_range_min = (u8)dig_t->ant_div_rssi_max;
  2095. */
  2096. /*@
  2097. *PHYDM_DBG(dm, DBG_DIG, "Force Dyn-Min=0x%x, RSSI_max=0x%x\n",
  2098. * dig_t->rx_gain_range_min, dig_t->ant_div_rssi_max);
  2099. *}
  2100. */
  2101. PHYDM_DBG(dm, DBG_DIG, "Dyn{Max, Min}={0x%x, 0x%x}\n",
  2102. tdma_h_dym_max, tdma_h_dym_min);
  2103. }
  2104. /*@Abnormal Case Check*/
  2105. /*@Abnormal low higher bound case*/
  2106. if (tdma_h_dym_max < dig_t->dm_dig_min)
  2107. tdma_h_dym_max = dig_t->dm_dig_min;
  2108. /*@Abnormal lower bound case*/
  2109. if (tdma_h_dym_min > tdma_h_dym_max)
  2110. tdma_h_dym_min = tdma_h_dym_max;
  2111. PHYDM_DBG(dm, DBG_DIG, "Abnoraml chk, force {Max, Min}={0x%x, 0x%x}\n",
  2112. tdma_h_dym_max, tdma_h_dym_min);
  2113. /*@False Alarm Threshold Decision*/
  2114. phydm_fa_threshold_check(dm, dfs_mode_en);
  2115. /*@Adjust Initial Gain by False Alarm*/
  2116. /*Select new IGI by FA */
  2117. if (!(dm->original_dig_restore)) {
  2118. tdma_h_igi = get_new_igi_bound(dm, tdma_h_igi, fa_cnt,
  2119. &tdma_h_dym_max,
  2120. &tdma_h_dym_min,
  2121. dfs_mode_en);
  2122. } else {
  2123. new_igi = phydm_get_new_igi(dm, igi, fa_cnt, dfs_mode_en);
  2124. }
  2125. /*Update status*/
  2126. if (!(dm->original_dig_restore)) {
  2127. dig_t->cur_ig_value_tdma = tdma_h_igi;
  2128. dig_t->tdma_rx_gain_min[TDMA_DIG_HIGH_STATE] = tdma_h_dym_min;
  2129. dig_t->tdma_rx_gain_max[TDMA_DIG_HIGH_STATE] = tdma_h_dym_max;
  2130. #if 0
  2131. /*odm_write_dig(dm, tdma_h_igi);*/
  2132. #endif
  2133. } else {
  2134. odm_write_dig(dm, new_igi);
  2135. }
  2136. dig_t->is_media_connect = dm->is_linked;
  2137. }
  2138. void phydm_fa_cnt_acc(void *dm_void, boolean rssi_dump_en,
  2139. u8 cur_tdma_dig_state)
  2140. {
  2141. struct dm_struct *dm = (struct dm_struct *)dm_void;
  2142. struct phydm_fa_struct *falm_cnt = NULL;
  2143. struct phydm_fa_acc_struct *falm_cnt_acc = NULL;
  2144. struct phydm_dig_struct *dig_t = NULL;
  2145. u8 factor_num = 0;
  2146. u8 factor_denum = 1;
  2147. u8 total_state_number;
  2148. dig_t = &dm->dm_dig_table;
  2149. falm_cnt = &dm->false_alm_cnt;
  2150. #ifdef IS_USE_NEW_TDMA
  2151. if (cur_tdma_dig_state == TDMA_DIG_LOW_STATE)
  2152. falm_cnt_acc = &dm->false_alm_cnt_acc_low;
  2153. else if (cur_tdma_dig_state == TDMA_DIG_HIGH_STATE)
  2154. #endif
  2155. falm_cnt_acc = &dm->false_alm_cnt_acc;
  2156. /*@
  2157. *PHYDM_DBG(dm, DBG_DIG,
  2158. * "[%s] ==> dig_state=%d, one_sec=%d\n", __func__,
  2159. * cur_tdma_dig_state, rssi_dump_en);
  2160. */
  2161. falm_cnt_acc->cnt_parity_fail += falm_cnt->cnt_parity_fail;
  2162. falm_cnt_acc->cnt_rate_illegal += falm_cnt->cnt_rate_illegal;
  2163. falm_cnt_acc->cnt_crc8_fail += falm_cnt->cnt_crc8_fail;
  2164. falm_cnt_acc->cnt_mcs_fail += falm_cnt->cnt_mcs_fail;
  2165. falm_cnt_acc->cnt_ofdm_fail += falm_cnt->cnt_ofdm_fail;
  2166. falm_cnt_acc->cnt_cck_fail += falm_cnt->cnt_cck_fail;
  2167. falm_cnt_acc->cnt_all += falm_cnt->cnt_all;
  2168. falm_cnt_acc->cnt_fast_fsync += falm_cnt->cnt_fast_fsync;
  2169. falm_cnt_acc->cnt_sb_search_fail += falm_cnt->cnt_sb_search_fail;
  2170. falm_cnt_acc->cnt_ofdm_cca += falm_cnt->cnt_ofdm_cca;
  2171. falm_cnt_acc->cnt_cck_cca += falm_cnt->cnt_cck_cca;
  2172. falm_cnt_acc->cnt_cca_all += falm_cnt->cnt_cca_all;
  2173. falm_cnt_acc->cnt_cck_crc32_error += falm_cnt->cnt_cck_crc32_error;
  2174. falm_cnt_acc->cnt_cck_crc32_ok += falm_cnt->cnt_cck_crc32_ok;
  2175. falm_cnt_acc->cnt_ofdm_crc32_error += falm_cnt->cnt_ofdm_crc32_error;
  2176. falm_cnt_acc->cnt_ofdm_crc32_ok += falm_cnt->cnt_ofdm_crc32_ok;
  2177. falm_cnt_acc->cnt_ht_crc32_error += falm_cnt->cnt_ht_crc32_error;
  2178. falm_cnt_acc->cnt_ht_crc32_ok += falm_cnt->cnt_ht_crc32_ok;
  2179. falm_cnt_acc->cnt_vht_crc32_error += falm_cnt->cnt_vht_crc32_error;
  2180. falm_cnt_acc->cnt_vht_crc32_ok += falm_cnt->cnt_vht_crc32_ok;
  2181. falm_cnt_acc->cnt_crc32_error_all += falm_cnt->cnt_crc32_error_all;
  2182. falm_cnt_acc->cnt_crc32_ok_all += falm_cnt->cnt_crc32_ok_all;
  2183. /*@
  2184. *PHYDM_DBG(dm, DBG_DIG,
  2185. * "[CCA Cnt] {CCK, OFDM, Total} = {%d, %d, %d}\n",
  2186. * falm_cnt->cnt_cck_cca,
  2187. * falm_cnt->cnt_ofdm_cca,
  2188. * falm_cnt->cnt_cca_all);
  2189. *PHYDM_DBG(dm, DBG_DIG,
  2190. * "[FA Cnt] {CCK, OFDM, Total} = {%d, %d, %d}\n",
  2191. * falm_cnt->cnt_cck_fail,
  2192. * falm_cnt->cnt_ofdm_fail,
  2193. * falm_cnt->cnt_all);
  2194. */
  2195. if (rssi_dump_en == 1) {
  2196. total_state_number = dm->tdma_dig_state_number;
  2197. if (cur_tdma_dig_state == TDMA_DIG_HIGH_STATE) {
  2198. factor_num = total_state_number;
  2199. factor_denum = total_state_number - 1;
  2200. } else if (cur_tdma_dig_state == TDMA_DIG_LOW_STATE) {
  2201. factor_num = total_state_number;
  2202. factor_denum = 1;
  2203. }
  2204. falm_cnt_acc->cnt_all_1sec =
  2205. falm_cnt_acc->cnt_all * factor_num / factor_denum;
  2206. falm_cnt_acc->cnt_cca_all_1sec =
  2207. falm_cnt_acc->cnt_cca_all * factor_num / factor_denum;
  2208. falm_cnt_acc->cnt_cck_fail_1sec =
  2209. falm_cnt_acc->cnt_cck_fail * factor_num / factor_denum;
  2210. /*@
  2211. *PHYDM_DBG(dm, DBG_DIG,
  2212. * "[ACC CCA Cnt] {CCK, OFDM, Total} = {%d, %d, %d}\n",
  2213. * falm_cnt_acc->cnt_cck_cca,
  2214. * falm_cnt_acc->cnt_ofdm_cca,
  2215. * falm_cnt_acc->cnt_cca_all);
  2216. *PHYDM_DBG(dm, DBG_DIG,
  2217. * "[ACC FA Cnt] {CCK, OFDM, Total} = {%d, %d, %d}\n\n",
  2218. * falm_cnt_acc->cnt_cck_fail,
  2219. * falm_cnt_acc->cnt_ofdm_fail,
  2220. * falm_cnt_acc->cnt_all);
  2221. */
  2222. }
  2223. }
  2224. #endif /*@#ifdef IS_USE_NEW_TDMA*/
  2225. #endif /*@#ifdef PHYDM_TDMA_DIG_SUPPORT*/
  2226. void phydm_dig_debug(void *dm_void, char input[][16], u32 *_used, char *output,
  2227. u32 *_out_len)
  2228. {
  2229. struct dm_struct *dm = (struct dm_struct *)dm_void;
  2230. struct phydm_dig_struct *dig_t = &dm->dm_dig_table;
  2231. char help[] = "-h";
  2232. char monitor[] = "-m";
  2233. u32 var1[10] = {0};
  2234. u32 used = *_used;
  2235. u32 out_len = *_out_len;
  2236. u8 i;
  2237. if ((strcmp(input[1], help) == 0)) {
  2238. PDM_SNPF(out_len, used, output + used, out_len - used,
  2239. "{0} {en} fa_th[0] fa_th[1] fa_th[2]\n");
  2240. PDM_SNPF(out_len, used, output + used, out_len - used,
  2241. "{1} {Damping Limit en}\n");
  2242. } else if ((strcmp(input[1], monitor) == 0)) {
  2243. PDM_SNPF(out_len, used, output + used, out_len - used,
  2244. "Read DIG fa_th[0:2]= {%d, %d, %d}\n", dig_t->fa_th[0],
  2245. dig_t->fa_th[1], dig_t->fa_th[2]);
  2246. } else {
  2247. PHYDM_SSCANF(input[1], DCMD_DECIMAL, &var1[0]);
  2248. for (i = 1; i < 10; i++)
  2249. PHYDM_SSCANF(input[i + 1], DCMD_DECIMAL, &var1[i]);
  2250. if (var1[0] == 0) {
  2251. if (var1[1] == 1) {
  2252. dig_t->is_dbg_fa_th = true;
  2253. dig_t->fa_th[0] = (u16)var1[2];
  2254. dig_t->fa_th[1] = (u16)var1[3];
  2255. dig_t->fa_th[2] = (u16)var1[4];
  2256. PDM_SNPF(out_len, used, output + used,
  2257. out_len - used,
  2258. "Set DIG fa_th[0:2]= {%d, %d, %d}\n",
  2259. dig_t->fa_th[0], dig_t->fa_th[1],
  2260. dig_t->fa_th[2]);
  2261. } else {
  2262. dig_t->is_dbg_fa_th = false;
  2263. }
  2264. }
  2265. #ifdef CFG_DIG_DAMPING_CHK
  2266. else if (var1[0] == 1) {
  2267. dig_t->dig_dl_en = (u8)var1[1];
  2268. /*@*/
  2269. }
  2270. #endif
  2271. }
  2272. *_used = used;
  2273. *_out_len = out_len;
  2274. }
  2275. #ifdef CONFIG_MCC_DM
  2276. #if (RTL8822B_SUPPORT)
  2277. void phydm_mcc_igi_clr(void *dm_void, u8 clr_port)
  2278. {
  2279. struct dm_struct *dm = (struct dm_struct *)dm_void;
  2280. struct _phydm_mcc_dm_ *mcc_dm = &dm->mcc_dm;
  2281. mcc_dm->mcc_rssi[clr_port] = 0xff;
  2282. mcc_dm->mcc_dm_val[0][clr_port] = 0xff; /* 0xc50 clr */
  2283. mcc_dm->mcc_dm_val[1][clr_port] = 0xff; /* 0xe50 clr */
  2284. }
  2285. void phydm_mcc_igi_chk(void *dm_void)
  2286. {
  2287. struct dm_struct *dm = (struct dm_struct *)dm_void;
  2288. struct _phydm_mcc_dm_ *mcc_dm = &dm->mcc_dm;
  2289. if (mcc_dm->mcc_dm_val[0][0] == 0xff &&
  2290. mcc_dm->mcc_dm_val[0][1] == 0xff) {
  2291. mcc_dm->mcc_dm_reg[0] = 0xffff;
  2292. mcc_dm->mcc_reg_id[0] = 0xff;
  2293. }
  2294. if (mcc_dm->mcc_dm_val[1][0] == 0xff &&
  2295. mcc_dm->mcc_dm_val[1][1] == 0xff) {
  2296. mcc_dm->mcc_dm_reg[1] = 0xffff;
  2297. mcc_dm->mcc_reg_id[1] = 0xff;
  2298. }
  2299. }
  2300. void phydm_mcc_igi_cal(void *dm_void)
  2301. {
  2302. struct dm_struct *dm = (struct dm_struct *)dm_void;
  2303. struct _phydm_mcc_dm_ *mcc_dm = &dm->mcc_dm;
  2304. struct phydm_dig_struct *dig_t = &dm->dm_dig_table;
  2305. u8 shift = 0;
  2306. u8 igi_val0, igi_val1;
  2307. if (mcc_dm->mcc_rssi[0] == 0xff)
  2308. phydm_mcc_igi_clr(dm, 0);
  2309. if (mcc_dm->mcc_rssi[1] == 0xff)
  2310. phydm_mcc_igi_clr(dm, 1);
  2311. phydm_mcc_igi_chk(dm);
  2312. igi_val0 = mcc_dm->mcc_rssi[0] - shift;
  2313. igi_val1 = mcc_dm->mcc_rssi[1] - shift;
  2314. phydm_fill_mcccmd(dm, 0, 0xc50, igi_val0, igi_val1);
  2315. phydm_fill_mcccmd(dm, 1, 0xe50, igi_val0, igi_val1);
  2316. PHYDM_DBG(dm, DBG_COMP_MCC, "RSSI_min: %d %d, MCC_igi: %d %d\n",
  2317. mcc_dm->mcc_rssi[0], mcc_dm->mcc_rssi[1],
  2318. mcc_dm->mcc_dm_val[0][0], mcc_dm->mcc_dm_val[0][1]);
  2319. }
  2320. #endif /*#if (RTL8822B_SUPPORT)*/
  2321. #endif /*#ifdef CONFIG_MCC_DM*/