phydm_phystatus.c 88 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089
  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. #include "mp_precomp.h"
  29. #include "phydm_precomp.h"
  30. void phydm_rx_statistic_cal(struct dm_struct *dm,
  31. struct phydm_phyinfo_struct *phy_info,
  32. u8 *phy_status_inf,
  33. struct phydm_perpkt_info_struct *pktinfo)
  34. {
  35. #if (ODM_PHY_STATUS_NEW_TYPE_SUPPORT == 1)
  36. struct phy_status_rpt_jaguar2_type1 *phy_sts = NULL;
  37. u8 phy_status_type = 0;
  38. u8 val = 0;
  39. #endif
  40. u8 is_mu_pkt = 0;
  41. struct odm_phy_dbg_info *dbg_i = &dm->phy_dbg_info;
  42. u8 rate = (pktinfo->data_rate & 0x7f);
  43. u8 bw_idx = phy_info->band_width;
  44. u8 offset = 0;
  45. #if (ODM_PHY_STATUS_NEW_TYPE_SUPPORT == 1)
  46. phy_sts = (struct phy_status_rpt_jaguar2_type1 *)phy_status_inf;
  47. phy_status_type = (*phy_status_inf & 0xf);
  48. #endif
  49. if (rate <= ODM_RATE54M) {
  50. dbg_i->num_qry_legacy_pkt[rate]++;
  51. } else if (rate <= ODM_RATEMCS31) {
  52. dbg_i->ht_pkt_not_zero = true;
  53. offset = rate - ODM_RATEMCS0;
  54. if (dm->support_ic_type & PHYSTS_2ND_TYPE_IC) {
  55. if (bw_idx == *dm->band_width) {
  56. dbg_i->num_qry_ht_pkt[offset]++;
  57. } else if (bw_idx == CHANNEL_WIDTH_20) {
  58. dbg_i->num_qry_pkt_sc_20m[offset]++;
  59. dbg_i->low_bw_20_occur = true;
  60. }
  61. } else {
  62. dbg_i->num_qry_ht_pkt[offset]++;
  63. }
  64. }
  65. #if ODM_IC_11AC_SERIES_SUPPORT
  66. else if (rate <= ODM_RATEVHTSS4MCS9) {
  67. offset = rate - ODM_RATEVHTSS1MCS0;
  68. #if (ODM_PHY_STATUS_NEW_TYPE_SUPPORT == 1)
  69. if ((dm->support_ic_type & PHYSTS_2ND_TYPE_IC) &&
  70. phy_status_type == 1 &&
  71. phy_sts->gid != 0 &&
  72. phy_sts->gid != 63) {
  73. is_mu_pkt = 1;
  74. /*@*/
  75. }
  76. #endif
  77. if (is_mu_pkt) {
  78. #if (ODM_PHY_STATUS_NEW_TYPE_SUPPORT == 1)
  79. dbg_i->num_mu_vht_pkt[offset]++;
  80. #else
  81. dbg_i->num_qry_vht_pkt[offset]++; /*@for debug*/
  82. #endif
  83. } else {
  84. dbg_i->vht_pkt_not_zero = true;
  85. if (dm->support_ic_type & PHYSTS_2ND_TYPE_IC) {
  86. if (bw_idx == *dm->band_width) {
  87. dbg_i->num_qry_vht_pkt[offset]++;
  88. } else if (bw_idx == CHANNEL_WIDTH_20) {
  89. dbg_i->num_qry_pkt_sc_20m[offset]++;
  90. dbg_i->low_bw_20_occur = true;
  91. } else {/*@if (bw_idx == CHANNEL_WIDTH_40)*/
  92. dbg_i->num_qry_pkt_sc_40m[offset]++;
  93. dbg_i->low_bw_40_occur = true;
  94. }
  95. } else {
  96. dbg_i->num_qry_vht_pkt[offset]++;
  97. }
  98. }
  99. #if (ODM_PHY_STATUS_NEW_TYPE_SUPPORT == 1)
  100. if (pktinfo->ppdu_cnt < 4) {
  101. if (is_mu_pkt)
  102. val = rate | BIT(7);
  103. else
  104. val = rate;
  105. dbg_i->num_of_ppdu[pktinfo->ppdu_cnt] = val;
  106. dbg_i->gid_num[pktinfo->ppdu_cnt] = phy_sts->gid;
  107. }
  108. #endif
  109. }
  110. #endif
  111. }
  112. void phydm_reset_phystatus_avg(struct dm_struct *dm)
  113. {
  114. struct phydm_phystatus_avg *dbg_avg = NULL;
  115. dbg_avg = &dm->phy_dbg_info.phystatus_statistic_avg;
  116. odm_memory_set(dm, &dbg_avg->rssi_cck_avg, 0,
  117. sizeof(struct phydm_phystatus_avg));
  118. }
  119. void phydm_reset_phystatus_statistic(struct dm_struct *dm)
  120. {
  121. struct phydm_phystatus_statistic *dbg_s = NULL;
  122. dbg_s = &dm->phy_dbg_info.physts_statistic_info;
  123. odm_memory_set(dm, &dbg_s->rssi_cck_sum, 0,
  124. sizeof(struct phydm_phystatus_statistic));
  125. }
  126. void phydm_avg_phystatus_index(void *dm_void,
  127. struct phydm_phyinfo_struct *phy_info,
  128. struct phydm_perpkt_info_struct *pktinfo)
  129. {
  130. struct dm_struct *dm = (struct dm_struct *)dm_void;
  131. struct odm_phy_dbg_info *dbg_i = &dm->phy_dbg_info;
  132. struct phydm_phystatus_statistic *dbg_s = &dbg_i->physts_statistic_info;
  133. u8 rssi[PHYSTS_PATH_NUM] = {0};
  134. u8 evm[PHYSTS_PATH_NUM] = {0};
  135. s8 snr[PHYSTS_PATH_NUM] = {0};
  136. u32 size = PHYSTS_PATH_NUM; /*size of path=4*/
  137. u16 size_th = PHY_HIST_SIZE - 1; /*size of threshold*/
  138. u16 val = 0, intvl = 0;
  139. u8 i = 0;
  140. odm_move_memory(dm, rssi, phy_info->rx_mimo_signal_strength, size);
  141. odm_move_memory(dm, evm, phy_info->rx_mimo_evm_dbm, size);
  142. odm_move_memory(dm, snr, phy_info->rx_snr, size);
  143. if (pktinfo->data_rate <= ODM_RATE11M) {
  144. /*RSSI*/
  145. dbg_s->rssi_cck_sum += rssi[0];
  146. dbg_s->rssi_cck_cnt++;
  147. return;
  148. } else if (pktinfo->data_rate <= ODM_RATE54M) {
  149. /*@evm*/
  150. dbg_s->evm_ofdm_sum += evm[0];
  151. /*SNR*/
  152. dbg_s->snr_ofdm_sum += snr[0];
  153. /*RSSI*/
  154. dbg_s->rssi_ofdm_sum += rssi[0];
  155. dbg_s->rssi_ofdm_cnt++;
  156. val = (u16)evm[0];
  157. intvl = phydm_find_intrvl(dm, val, dbg_i->evm_hist_th, size_th);
  158. dbg_s->evm_ofdm_hist[intvl]++;
  159. val = (u16)snr[0];
  160. intvl = phydm_find_intrvl(dm, val, dbg_i->snr_hist_th, size_th);
  161. dbg_s->snr_ofdm_hist[intvl]++;
  162. } else if (pktinfo->rate_ss == 1) {
  163. /*@===[1-SS]==================================================================*/
  164. /*@evm*/
  165. dbg_s->evm_1ss_sum += evm[0];
  166. /*SNR*/
  167. dbg_s->snr_1ss_sum += snr[0];
  168. /*RSSI*/
  169. dbg_s->rssi_1ss_sum += rssi[0];
  170. /*@EVM Histogram*/
  171. val = (u16)evm[0];
  172. intvl = phydm_find_intrvl(dm, val, dbg_i->evm_hist_th, size_th);
  173. dbg_s->evm_1ss_hist[intvl]++;
  174. /*SNR Histogram*/
  175. val = (u16)snr[0];
  176. intvl = phydm_find_intrvl(dm, val, dbg_i->snr_hist_th, size_th);
  177. dbg_s->snr_1ss_hist[intvl]++;
  178. dbg_s->rssi_1ss_cnt++;
  179. } else if (pktinfo->rate_ss == 2) {
  180. /*@===[2-SS]==================================================================*/
  181. #if (defined(PHYDM_COMPILE_ABOVE_2SS))
  182. for (i = 0; i < pktinfo->rate_ss; i++) {
  183. /*@evm*/
  184. dbg_s->evm_2ss_sum[i] += evm[i];
  185. /*SNR*/
  186. dbg_s->snr_2ss_sum[i] += snr[i];
  187. /*RSSI*/
  188. dbg_s->rssi_2ss_sum[i] += rssi[i];
  189. /*@EVM Histogram*/
  190. val = (u16)evm[i];
  191. intvl = phydm_find_intrvl(dm, val, dbg_i->evm_hist_th,
  192. size_th);
  193. dbg_s->evm_2ss_hist[i][intvl]++;
  194. /*SNR Histogram*/
  195. val = (u16)snr[i];
  196. intvl = phydm_find_intrvl(dm, val, dbg_i->snr_hist_th,
  197. size_th);
  198. dbg_s->snr_2ss_hist[i][intvl]++;
  199. }
  200. dbg_s->rssi_2ss_cnt++;
  201. #endif
  202. } else if (pktinfo->rate_ss == 3) {
  203. /*@===[3-SS]==================================================================*/
  204. #if (defined(PHYDM_COMPILE_ABOVE_3SS))
  205. for (i = 0; i < pktinfo->rate_ss; i++) {
  206. /*@evm*/
  207. dbg_s->evm_3ss_sum[i] += evm[i];
  208. /*SNR*/
  209. dbg_s->snr_3ss_sum[i] += snr[i];
  210. /*RSSI*/
  211. dbg_s->rssi_3ss_sum[i] += rssi[i];
  212. /*@EVM Histogram*/
  213. val = (u16)evm[i];
  214. intvl = phydm_find_intrvl(dm, val, dbg_i->evm_hist_th,
  215. size_th);
  216. dbg_s->evm_3ss_hist[i][intvl]++;
  217. /*SNR Histogram*/
  218. val = (u16)snr[i];
  219. intvl = phydm_find_intrvl(dm, val, dbg_i->snr_hist_th,
  220. size_th);
  221. dbg_s->snr_3ss_hist[i][intvl]++;
  222. }
  223. dbg_s->rssi_3ss_cnt++;
  224. #endif
  225. } else if (pktinfo->rate_ss == 4) {
  226. /*@===[4-SS]==================================================================*/
  227. #if (defined(PHYDM_COMPILE_ABOVE_4SS))
  228. for (i = 0; i < pktinfo->rate_ss; i++) {
  229. /*@evm*/
  230. dbg_s->evm_4ss_sum[i] += evm[i];
  231. /*SNR*/
  232. dbg_s->snr_4ss_sum[i] += snr[i];
  233. /*RSSI*/
  234. dbg_s->rssi_4ss_sum[i] += rssi[i];
  235. /*@EVM Histogram*/
  236. val = (u16)evm[i];
  237. intvl = phydm_find_intrvl(dm, val, dbg_i->evm_hist_th,
  238. size_th);
  239. dbg_s->evm_4ss_hist[i][intvl]++;
  240. /*SNR Histogram*/
  241. val = (u16)snr[i];
  242. intvl = phydm_find_intrvl(dm, val, dbg_i->snr_hist_th,
  243. size_th);
  244. dbg_s->snr_4ss_hist[i][intvl]++;
  245. }
  246. dbg_s->rssi_4ss_cnt++;
  247. #endif
  248. }
  249. }
  250. void phydm_avg_phystatus_init(void *dm_void)
  251. {
  252. struct dm_struct *dm = (struct dm_struct *)dm_void;
  253. struct odm_phy_dbg_info *dbg_i = &dm->phy_dbg_info;
  254. u16 snr_hist_th[PHY_HIST_SIZE - 1] = {5, 8, 11, 14, 17, 20, 23, 26,
  255. 29, 32, 35};
  256. u16 evm_hist_th[PHY_HIST_SIZE - 1] = {5, 8, 11, 14, 17, 20, 23, 26,
  257. 29, 32, 35};
  258. u32 size = (PHY_HIST_SIZE - 1) * 2;
  259. odm_move_memory(dm, dbg_i->snr_hist_th, snr_hist_th, size);
  260. odm_move_memory(dm, dbg_i->evm_hist_th, evm_hist_th, size);
  261. }
  262. u8 phydm_get_signal_quality(struct phydm_phyinfo_struct *phy_info,
  263. struct dm_struct *dm,
  264. struct phy_status_rpt_8192cd *phy_sts)
  265. {
  266. u8 sq_rpt;
  267. u8 result = 0;
  268. if (phy_info->rx_pwdb_all > 40 && !dm->is_in_hct_test) {
  269. result = 100;
  270. } else {
  271. sq_rpt = phy_sts->cck_sig_qual_ofdm_pwdb_all;
  272. if (sq_rpt > 64)
  273. result = 0;
  274. else if (sq_rpt < 20)
  275. result = 100;
  276. else
  277. result = ((64 - sq_rpt) * 100) / 44;
  278. }
  279. return result;
  280. }
  281. u8 phydm_pwr_2_percent(s8 ant_power)
  282. {
  283. if ((ant_power <= -100) || ant_power >= 20)
  284. return 0;
  285. else if (ant_power >= 0)
  286. return 100;
  287. else
  288. return 100 + ant_power;
  289. }
  290. #if (DM_ODM_SUPPORT_TYPE & ODM_WIN)
  291. #if 0 /*(DM_ODM_SUPPORT_TYPE == ODM_CE)*/
  292. s32 phydm_signal_scale_mapping_92c_series(struct dm_struct *dm, s32 curr_sig)
  293. {
  294. s32 ret_sig = 0;
  295. #if (DEV_BUS_TYPE == RT_PCI_INTERFACE)
  296. if (dm->support_interface == ODM_ITRF_PCIE) {
  297. /* step 1. Scale mapping. */
  298. if (curr_sig >= 61 && curr_sig <= 100)
  299. ret_sig = 90 + ((curr_sig - 60) / 4);
  300. else if (curr_sig >= 41 && curr_sig <= 60)
  301. ret_sig = 78 + ((curr_sig - 40) / 2);
  302. else if (curr_sig >= 31 && curr_sig <= 40)
  303. ret_sig = 66 + (curr_sig - 30);
  304. else if (curr_sig >= 21 && curr_sig <= 30)
  305. ret_sig = 54 + (curr_sig - 20);
  306. else if (curr_sig >= 5 && curr_sig <= 20)
  307. ret_sig = 42 + (((curr_sig - 5) * 2) / 3);
  308. else if (curr_sig == 4)
  309. ret_sig = 36;
  310. else if (curr_sig == 3)
  311. ret_sig = 27;
  312. else if (curr_sig == 2)
  313. ret_sig = 18;
  314. else if (curr_sig == 1)
  315. ret_sig = 9;
  316. else
  317. ret_sig = curr_sig;
  318. }
  319. #endif
  320. #if ((DEV_BUS_TYPE == RT_USB_INTERFACE) || (DEV_BUS_TYPE == RT_SDIO_INTERFACE))
  321. if (dm->support_interface == ODM_ITRF_USB ||
  322. dm->support_interface == ODM_ITRF_SDIO) {
  323. if (curr_sig >= 51 && curr_sig <= 100)
  324. ret_sig = 100;
  325. else if (curr_sig >= 41 && curr_sig <= 50)
  326. ret_sig = 80 + ((curr_sig - 40) * 2);
  327. else if (curr_sig >= 31 && curr_sig <= 40)
  328. ret_sig = 66 + (curr_sig - 30);
  329. else if (curr_sig >= 21 && curr_sig <= 30)
  330. ret_sig = 54 + (curr_sig - 20);
  331. else if (curr_sig >= 10 && curr_sig <= 20)
  332. ret_sig = 42 + (((curr_sig - 10) * 2) / 3);
  333. else if (curr_sig >= 5 && curr_sig <= 9)
  334. ret_sig = 22 + (((curr_sig - 5) * 3) / 2);
  335. else if (curr_sig >= 1 && curr_sig <= 4)
  336. ret_sig = 6 + (((curr_sig - 1) * 3) / 2);
  337. else
  338. ret_sig = curr_sig;
  339. }
  340. #endif
  341. return ret_sig;
  342. }
  343. s32 phydm_signal_scale_mapping(struct dm_struct *dm, s32 curr_sig)
  344. {
  345. #ifdef CONFIG_SIGNAL_SCALE_MAPPING
  346. return phydm_signal_scale_mapping_92c_series(dm, curr_sig);
  347. #else
  348. return curr_sig;
  349. #endif
  350. }
  351. #endif
  352. void phydm_process_signal_strength(struct dm_struct *dm,
  353. struct phydm_phyinfo_struct *phy_info,
  354. struct phydm_perpkt_info_struct *pktinfo)
  355. {
  356. u8 avg_rssi = 0, tmp_rssi = 0, best_rssi = 0, second_rssi = 0;
  357. u8 ss = 0; /*signal strenth after scale mapping*/
  358. u8 pwdb = phy_info->rx_pwdb_all;
  359. u8 i;
  360. /*use the best two RSSI only*/
  361. for (i = RF_PATH_A; i < PHYDM_MAX_RF_PATH; i++) {
  362. tmp_rssi = phy_info->rx_mimo_signal_strength[i];
  363. /*@Get the best two RSSI*/
  364. if (tmp_rssi > best_rssi && tmp_rssi > second_rssi) {
  365. second_rssi = best_rssi;
  366. best_rssi = tmp_rssi;
  367. } else if (tmp_rssi > second_rssi && tmp_rssi <= best_rssi) {
  368. second_rssi = tmp_rssi;
  369. }
  370. }
  371. if (best_rssi == 0)
  372. return;
  373. if (pktinfo->rate_ss == 1)
  374. avg_rssi = best_rssi;
  375. else
  376. avg_rssi = (best_rssi + second_rssi) >> 1;
  377. if (dm->support_ic_type & PHYSTS_2ND_TYPE_IC) {
  378. #if (ODM_PHY_STATUS_NEW_TYPE_SUPPORT == 1)
  379. /* Update signal strength to UI,
  380. * and phy_info->rx_pwdb_all is the maximum RSSI of all path
  381. */
  382. #if 1 /*(DM_ODM_SUPPORT_TYPE == ODM_WIN)*/
  383. ss = SignalScaleProc(dm->adapter, pwdb, false, false);
  384. #elif (DM_ODM_SUPPORT_TYPE == ODM_CE)
  385. ss = (u8)phydm_signal_scale_mapping(dm, pwdb);
  386. #endif
  387. #endif
  388. } else if (dm->support_ic_type & ODM_IC_11AC_SERIES) {
  389. #if ODM_IC_11AC_SERIES_SUPPORT
  390. if (pktinfo->is_cck_rate)
  391. #if 1/*(DM_ODM_SUPPORT_TYPE == ODM_WIN)*/
  392. ss = SignalScaleProc(dm->adapter, pwdb, 0, 1);
  393. #else
  394. ss = (u8)phydm_signal_scale_mapping(dm, pwdb);
  395. #endif
  396. else
  397. #if 1 /*(DM_ODM_SUPPORT_TYPE == ODM_WIN)*/
  398. ss = SignalScaleProc(dm->adapter, avg_rssi, 0, 1);
  399. #else
  400. ss = (u8)phydm_signal_scale_mapping(dm, avg_rssi);
  401. #endif
  402. #endif
  403. } else if (dm->support_ic_type & ODM_IC_11N_SERIES) {
  404. #if ODM_IC_11N_SERIES_SUPPORT
  405. if (pktinfo->is_cck_rate)
  406. #if 1/*(DM_ODM_SUPPORT_TYPE == ODM_WIN)*/
  407. ss = SignalScaleProc(dm->adapter, pwdb, 1, 1);
  408. #else
  409. ss = (u8)phydm_signal_scale_mapping(dm, pwdb);
  410. #endif
  411. else
  412. #if 1 /*(DM_ODM_SUPPORT_TYPE == ODM_WIN)*/
  413. ss = SignalScaleProc(dm->adapter, avg_rssi, 1, 0);
  414. #else
  415. ss = (u8)phydm_signal_scale_mapping(dm, avg_rssi);
  416. #endif
  417. #endif
  418. }
  419. phy_info->signal_strength = ss;
  420. }
  421. #endif
  422. #if (DM_ODM_SUPPORT_TYPE & ODM_WIN)
  423. static u8 phydm_sq_patch_lenovo(
  424. struct dm_struct *dm,
  425. u8 is_cck_rate,
  426. u8 pwdb_all,
  427. u8 path,
  428. u8 RSSI)
  429. {
  430. u8 sq = 0;
  431. if (is_cck_rate) {
  432. if (dm->support_ic_type & ODM_RTL8192E) {
  433. /*@
  434. * <Roger_Notes>
  435. * Expected signal strength and bars indication at Lenovo lab. 2013.04.11
  436. * 802.11n, 802.11b, 802.11g only at channel 6
  437. *
  438. * Attenuation (dB) OS Signal Bars RSSI by Xirrus (dBm)
  439. * 50 5 -49
  440. * 55 5 -49
  441. * 60 5 -50
  442. * 65 5 -51
  443. * 70 5 -52
  444. * 75 5 -54
  445. * 80 5 -55
  446. * 85 4 -60
  447. * 90 3 -63
  448. * 95 3 -65
  449. * 100 2 -67
  450. * 102 2 -67
  451. * 104 1 -70
  452. */
  453. if (pwdb_all >= 50)
  454. sq = 100;
  455. else if (pwdb_all >= 35 && pwdb_all < 50)
  456. sq = 80;
  457. else if (pwdb_all >= 31 && pwdb_all < 35)
  458. sq = 60;
  459. else if (pwdb_all >= 22 && pwdb_all < 31)
  460. sq = 40;
  461. else if (pwdb_all >= 18 && pwdb_all < 22)
  462. sq = 20;
  463. else
  464. sq = 10;
  465. } else {
  466. if (pwdb_all >= 50)
  467. sq = 100;
  468. else if (pwdb_all >= 35 && pwdb_all < 50)
  469. sq = 80;
  470. else if (pwdb_all >= 22 && pwdb_all < 35)
  471. sq = 60;
  472. else if (pwdb_all >= 18 && pwdb_all < 22)
  473. sq = 40;
  474. else
  475. sq = 10;
  476. }
  477. } else {
  478. /* OFDM rate */
  479. if (dm->support_ic_type & ODM_RTL8192E) {
  480. if (RSSI >= 45)
  481. sq = 100;
  482. else if (RSSI >= 22 && RSSI < 45)
  483. sq = 80;
  484. else if (RSSI >= 18 && RSSI < 22)
  485. sq = 40;
  486. else
  487. sq = 20;
  488. } else {
  489. if (RSSI >= 45)
  490. sq = 100;
  491. else if (RSSI >= 22 && RSSI < 45)
  492. sq = 80;
  493. else if (RSSI >= 18 && RSSI < 22)
  494. sq = 40;
  495. else
  496. sq = 20;
  497. }
  498. }
  499. return sq;
  500. }
  501. static u8 phydm_sq_patch_rt_cid_819x_acer(
  502. struct dm_struct *dm,
  503. u8 is_cck_rate,
  504. u8 pwdb_all,
  505. u8 path,
  506. u8 RSSI)
  507. {
  508. u8 sq = 0;
  509. if (is_cck_rate) {
  510. #if OS_WIN_FROM_WIN8(OS_VERSION)
  511. if (pwdb_all >= 50)
  512. sq = 100;
  513. else if (pwdb_all >= 35 && pwdb_all < 50)
  514. sq = 80;
  515. else if (pwdb_all >= 30 && pwdb_all < 35)
  516. sq = 60;
  517. else if (pwdb_all >= 25 && pwdb_all < 30)
  518. sq = 40;
  519. else if (pwdb_all >= 20 && pwdb_all < 25)
  520. sq = 20;
  521. else
  522. sq = 10;
  523. #else
  524. if (pwdb_all >= 50)
  525. sq = 100;
  526. else if (pwdb_all >= 35 && pwdb_all < 50)
  527. sq = 80;
  528. else if (pwdb_all >= 30 && pwdb_all < 35)
  529. sq = 60;
  530. else if (pwdb_all >= 25 && pwdb_all < 30)
  531. sq = 40;
  532. else if (pwdb_all >= 20 && pwdb_all < 25)
  533. sq = 20;
  534. else
  535. sq = 10;
  536. /* @Abnormal case, do not indicate the value above 20 on Win7 */
  537. if (pwdb_all == 0)
  538. sq = 20;
  539. #endif
  540. } else {
  541. /* OFDM rate */
  542. if (dm->support_ic_type & ODM_RTL8192E) {
  543. if (RSSI >= 45)
  544. sq = 100;
  545. else if (RSSI >= 22 && RSSI < 45)
  546. sq = 80;
  547. else if (RSSI >= 18 && RSSI < 22)
  548. sq = 40;
  549. else
  550. sq = 20;
  551. } else {
  552. if (RSSI >= 35)
  553. sq = 100;
  554. else if (RSSI >= 30 && RSSI < 35)
  555. sq = 80;
  556. else if (RSSI >= 25 && RSSI < 30)
  557. sq = 40;
  558. else
  559. sq = 20;
  560. }
  561. }
  562. return sq;
  563. }
  564. #endif
  565. static u8
  566. phydm_evm_2_percent(s8 value)
  567. {
  568. /* @-33dB~0dB to 0%~99% */
  569. s8 ret_val;
  570. ret_val = value;
  571. ret_val /= 2;
  572. /*@dbg_print("value=%d\n", value);*/
  573. #ifdef ODM_EVM_ENHANCE_ANTDIV
  574. if (ret_val >= 0)
  575. ret_val = 0;
  576. if (ret_val <= -40)
  577. ret_val = -40;
  578. ret_val = 0 - ret_val;
  579. ret_val *= 3;
  580. #else
  581. if (ret_val >= 0)
  582. ret_val = 0;
  583. if (ret_val <= -33)
  584. ret_val = -33;
  585. ret_val = 0 - ret_val;
  586. ret_val *= 3;
  587. if (ret_val == 99)
  588. ret_val = 100;
  589. #endif
  590. return (u8)ret_val;
  591. }
  592. static u8
  593. phydm_evm_dbm(s8 value)
  594. {
  595. s8 ret_val = value;
  596. /* @-33dB~0dB to 33dB ~ 0dB */
  597. if (ret_val == -128)
  598. ret_val = 127;
  599. else if (ret_val < 0)
  600. ret_val = 0 - ret_val;
  601. ret_val = ret_val >> 1;
  602. return (u8)ret_val;
  603. }
  604. static s16
  605. phydm_cfo(s8 value)
  606. {
  607. s16 ret_val;
  608. if (value < 0) {
  609. ret_val = 0 - value;
  610. ret_val = (ret_val << 1) + (ret_val >> 1); /*@2.5~=312.5/2^7 */
  611. ret_val = ret_val | BIT(12); /*set bit12 as 1 for negative cfo*/
  612. } else {
  613. ret_val = value;
  614. ret_val = (ret_val << 1) + (ret_val >> 1); /* @*2.5~=312.5/2^7*/
  615. }
  616. return ret_val;
  617. }
  618. s8 phydm_cck_rssi_convert(struct dm_struct *dm, u16 lna_idx, u8 vga_idx)
  619. {
  620. /*@phydm_get_cck_rssi_table_from_reg*/
  621. return (dm->cck_lna_gain_table[lna_idx] - (vga_idx << 1));
  622. }
  623. void phydm_get_cck_rssi_table_from_reg(struct dm_struct *dm)
  624. {
  625. u8 used_lna_idx_tmp;
  626. u32 reg_0xa80 = 0x7431, reg_0xabc = 0xcbe5edfd;
  627. u32 val = 0;
  628. u8 i;
  629. /*@example: {-53, -43, -33, -27, -19, -13, -3, 1}*/
  630. /*@{0xCB, 0xD5, 0xDF, 0xE5, 0xED, 0xF3, 0xFD, 0x2}*/
  631. PHYDM_DBG(dm, ODM_COMP_INIT, "CCK LNA Gain table init\n");
  632. if (!(dm->support_ic_type & (ODM_RTL8197F)))
  633. return;
  634. reg_0xa80 = odm_get_bb_reg(dm, R_0xa80, 0xFFFF);
  635. reg_0xabc = odm_get_bb_reg(dm, R_0xabc, MASKDWORD);
  636. PHYDM_DBG(dm, ODM_COMP_INIT, "reg_0xa80 = 0x%x\n", reg_0xa80);
  637. PHYDM_DBG(dm, ODM_COMP_INIT, "reg_0xabc = 0x%x\n", reg_0xabc);
  638. for (i = 0; i <= 3; i++) {
  639. used_lna_idx_tmp = (u8)((reg_0xa80 >> (4 * i)) & 0x7);
  640. val = (reg_0xabc >> (8 * i)) & 0xff;
  641. dm->cck_lna_gain_table[used_lna_idx_tmp] = (s8)val;
  642. }
  643. PHYDM_DBG(dm, ODM_COMP_INIT,
  644. "cck_lna_gain_table = {%d,%d,%d,%d,%d,%d,%d,%d}\n",
  645. dm->cck_lna_gain_table[0], dm->cck_lna_gain_table[1],
  646. dm->cck_lna_gain_table[2], dm->cck_lna_gain_table[3],
  647. dm->cck_lna_gain_table[4], dm->cck_lna_gain_table[5],
  648. dm->cck_lna_gain_table[6], dm->cck_lna_gain_table[7]);
  649. }
  650. s8 phydm_get_cck_rssi(void *dm_void, u8 lna_idx, u8 vga_idx)
  651. {
  652. struct dm_struct *dm = (struct dm_struct *)dm_void;
  653. s8 rx_pow = 0;
  654. switch (dm->support_ic_type) {
  655. #if (RTL8197F_SUPPORT == 1)
  656. case ODM_RTL8197F:
  657. rx_pow = phydm_cck_rssi_convert(dm, lna_idx, vga_idx);
  658. break;
  659. #endif
  660. #if (RTL8723D_SUPPORT == 1)
  661. case ODM_RTL8723D:
  662. rx_pow = phydm_cckrssi_8723d(dm, lna_idx, vga_idx);
  663. break;
  664. #endif
  665. #if (RTL8710B_SUPPORT == 1)
  666. case ODM_RTL8710B:
  667. rx_pow = phydm_cckrssi_8710b(dm, lna_idx, vga_idx);
  668. break;
  669. #endif
  670. #if (RTL8192F_SUPPORT == 1)
  671. case ODM_RTL8192F:
  672. rx_pow = phydm_cckrssi_8192f(dm, lna_idx, vga_idx);
  673. break;
  674. #endif
  675. #if (RTL8821C_SUPPORT == 1)
  676. case ODM_RTL8821C:
  677. rx_pow = phydm_cck_rssi_8821c(dm, lna_idx, vga_idx);
  678. break;
  679. #endif
  680. #if (RTL8195B_SUPPORT == 1)
  681. case ODM_RTL8195B:
  682. rx_pow = phydm_cck_rssi_8195B(dm, lna_idx, vga_idx);
  683. break;
  684. #endif
  685. #if (RTL8188E_SUPPORT == 1)
  686. case ODM_RTL8188E:
  687. rx_pow = phydm_cck_rssi_8188e(dm, lna_idx, vga_idx);
  688. break;
  689. #endif
  690. #if (RTL8192E_SUPPORT == 1)
  691. case ODM_RTL8192E:
  692. rx_pow = phydm_cck_rssi_8192e(dm, lna_idx, vga_idx);
  693. break;
  694. #endif
  695. #if (RTL8723B_SUPPORT == 1)
  696. case ODM_RTL8723B:
  697. rx_pow = phydm_cck_rssi_8723b(dm, lna_idx, vga_idx);
  698. break;
  699. #endif
  700. #if (RTL8703B_SUPPORT == 1)
  701. case ODM_RTL8703B:
  702. rx_pow = phydm_cck_rssi_8703b(dm, lna_idx, vga_idx);
  703. break;
  704. #endif
  705. #if (RTL8188F_SUPPORT == 1)
  706. case ODM_RTL8188F:
  707. rx_pow = phydm_cck_rssi_8188f(dm, lna_idx, vga_idx);
  708. break;
  709. #endif
  710. #if (RTL8195A_SUPPORT == 1)
  711. case ODM_RTL8195A:
  712. rx_pow = phydm_cck_rssi_8195a(dm, lna_idx, vga_idx);
  713. break;
  714. #endif
  715. #if (RTL8812A_SUPPORT == 1)
  716. case ODM_RTL8812:
  717. rx_pow = phydm_cck_rssi_8812a(dm, lna_idx, vga_idx);
  718. break;
  719. #endif
  720. #if (RTL8821A_SUPPORT == 1) || (RTL8881A_SUPPORT == 1)
  721. case ODM_RTL8821:
  722. case ODM_RTL8881A:
  723. rx_pow = phydm_cck_rssi_8821a(dm, lna_idx, vga_idx);
  724. break;
  725. #endif
  726. #if (RTL8814A_SUPPORT == 1)
  727. case ODM_RTL8814A:
  728. rx_pow = phydm_cck_rssi_8814a(dm, lna_idx, vga_idx);
  729. break;
  730. #endif
  731. default:
  732. break;
  733. }
  734. return rx_pow;
  735. }
  736. #if (ODM_IC_11N_SERIES_SUPPORT == 1)
  737. void phydm_phy_sts_n_parsing(struct dm_struct *dm,
  738. struct phydm_phyinfo_struct *phy_info,
  739. u8 *phy_status_inf,
  740. struct phydm_perpkt_info_struct *pktinfo)
  741. {
  742. u8 i = 0;
  743. s8 rx_pwr[4], rx_pwr_all = 0;
  744. u8 EVM, pwdb_all = 0, pwdb_all_bt = 0;
  745. u8 RSSI, total_rssi = 0;
  746. u8 rf_rx_num = 0;
  747. u8 lna_idx = 0;
  748. u8 vga_idx = 0;
  749. u8 cck_agc_rpt;
  750. s8 evm_tmp = 0;
  751. u8 sq = 0;
  752. u8 val_tmp = 0;
  753. s8 val_s8 = 0;
  754. struct phy_status_rpt_8192cd *phy_sts = NULL;
  755. phy_sts = (struct phy_status_rpt_8192cd *)phy_status_inf;
  756. if (pktinfo->is_cck_rate) {
  757. cck_agc_rpt = phy_sts->cck_agc_rpt_ofdm_cfosho_a;
  758. /*@3 bit LNA*/
  759. lna_idx = ((cck_agc_rpt & 0xE0) >> 5);
  760. vga_idx = (cck_agc_rpt & 0x1F);
  761. #if (RTL8703B_SUPPORT == 1)
  762. if (dm->support_ic_type & (ODM_RTL8703B) &&
  763. dm->cck_agc_report_type == 1) {
  764. /*@4 bit LNA*/
  765. if (phy_sts->cck_rpt_b_ofdm_cfosho_b & BIT(7))
  766. val_tmp = 1;
  767. else
  768. val_tmp = 0;
  769. lna_idx = (val_tmp << 3) | lna_idx;
  770. }
  771. #endif
  772. rx_pwr_all = phydm_get_cck_rssi(dm, lna_idx, vga_idx);
  773. PHYDM_DBG(dm, DBG_RSSI_MNTR,
  774. "ext_lna_gain (( %d )), lna_idx: (( 0x%x )), vga_idx: (( 0x%x )), rx_pwr_all: (( %d ))\n",
  775. dm->ext_lna_gain, lna_idx, vga_idx, rx_pwr_all);
  776. if (dm->board_type & ODM_BOARD_EXT_LNA)
  777. rx_pwr_all -= dm->ext_lna_gain;
  778. pwdb_all = phydm_pwr_2_percent(rx_pwr_all);
  779. if (pktinfo->is_to_self) {
  780. dm->cck_lna_idx = lna_idx;
  781. dm->cck_vga_idx = vga_idx;
  782. }
  783. phy_info->rx_pwdb_all = pwdb_all;
  784. phy_info->bt_rx_rssi_percentage = pwdb_all;
  785. phy_info->recv_signal_power = rx_pwr_all;
  786. /* @(3) Get Signal Quality (EVM) */
  787. #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
  788. if (dm->iot_table.win_patch_id == RT_CID_819X_LENOVO)
  789. sq = phydm_sq_patch_lenovo(dm, pktinfo->is_cck_rate, pwdb_all, 0, 0);
  790. else if (dm->iot_table.win_patch_id == RT_CID_819X_ACER)
  791. sq = phydm_sq_patch_rt_cid_819x_acer(dm, pktinfo->is_cck_rate, pwdb_all, 0, 0);
  792. else
  793. #endif
  794. sq = phydm_get_signal_quality(phy_info, dm, phy_sts);
  795. #if 0
  796. /* @dbg_print("cck sq = %d\n", sq); */
  797. #endif
  798. phy_info->signal_quality = sq;
  799. phy_info->rx_mimo_signal_quality[RF_PATH_A] = sq;
  800. phy_info->rx_mimo_signal_quality[RF_PATH_B] = -1;
  801. for (i = RF_PATH_A; i < PHYDM_MAX_RF_PATH; i++) {
  802. if (i == 0)
  803. phy_info->rx_mimo_signal_strength[0] = pwdb_all;
  804. else
  805. phy_info->rx_mimo_signal_strength[i] = 0;
  806. }
  807. } else { /* @2 is OFDM rate */
  808. /* @(1)Get RSSI for HT rate */
  809. for (i = RF_PATH_A; i < dm->num_rf_path; i++) {
  810. if (dm->rf_path_rx_enable & BIT(i))
  811. rf_rx_num++;
  812. val_s8 = phy_sts->path_agc[i].gain & 0x3F;
  813. rx_pwr[i] = (val_s8 * 2) - 110;
  814. if (pktinfo->is_to_self)
  815. dm->ofdm_agc_idx[i] = val_s8;
  816. phy_info->rx_pwr[i] = rx_pwr[i];
  817. RSSI = phydm_pwr_2_percent(rx_pwr[i]);
  818. total_rssi += RSSI;
  819. phy_info->rx_mimo_signal_strength[i] = (u8)RSSI;
  820. /* @Get Rx snr value in DB */
  821. val_s8 = (s8)(phy_sts->path_rxsnr[i] / 2);
  822. phy_info->rx_snr[i] = val_s8;
  823. /* Record Signal Strength for next packet */
  824. #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
  825. if (i == RF_PATH_A) {
  826. if (dm->iot_table.win_patch_id == RT_CID_819X_LENOVO) {
  827. phy_info->signal_quality = phydm_sq_patch_lenovo(dm, pktinfo->is_cck_rate, pwdb_all, i, RSSI);
  828. } else if (dm->iot_table.win_patch_id == RT_CID_819X_ACER)
  829. phy_info->signal_quality = phydm_sq_patch_rt_cid_819x_acer(dm, pktinfo->is_cck_rate, pwdb_all, 0, RSSI);
  830. }
  831. #endif
  832. }
  833. /* @(2)PWDB, Average PWDB calculated by hardware (for RA) */
  834. val_s8 = phy_sts->cck_sig_qual_ofdm_pwdb_all >> 1;
  835. rx_pwr_all = (val_s8 & 0x7f) - 110;
  836. pwdb_all = phydm_pwr_2_percent(rx_pwr_all);
  837. pwdb_all_bt = pwdb_all;
  838. phy_info->rx_pwdb_all = pwdb_all;
  839. phy_info->bt_rx_rssi_percentage = pwdb_all_bt;
  840. phy_info->rx_power = rx_pwr_all;
  841. phy_info->recv_signal_power = rx_pwr_all;
  842. /* @(3)EVM of HT rate */
  843. for (i = 0; i < pktinfo->rate_ss; i++) {
  844. /* @Do not use shift operation like "rx_evmX >>= 1"
  845. * because the compilor of free build environment
  846. * fill most significant bit to "zero" when doing shifting
  847. * operation which may change a negative
  848. * value to positive one, then the dbm value
  849. * (which is supposed to be negative) is not correct anymore.
  850. */
  851. EVM = phydm_evm_2_percent(phy_sts->stream_rxevm[i]);
  852. /*@Fill value in RFD, Get the 1st spatial stream only*/
  853. if (i == RF_PATH_A)
  854. phy_info->signal_quality = (u8)(EVM & 0xff);
  855. phy_info->rx_mimo_signal_quality[i] = (u8)(EVM & 0xff);
  856. if (phy_sts->stream_rxevm[i] < 0)
  857. evm_tmp = 0 - phy_sts->stream_rxevm[i];
  858. if (evm_tmp == 64)
  859. evm_tmp = 0;
  860. phy_info->rx_mimo_evm_dbm[i] = (u8)evm_tmp;
  861. }
  862. phydm_parsing_cfo(dm, pktinfo,
  863. phy_sts->path_cfotail, pktinfo->rate_ss);
  864. }
  865. #ifdef CONFIG_PHYDM_ANTENNA_DIVERSITY
  866. dm->dm_fat_table.antsel_rx_keep_0 = phy_sts->ant_sel;
  867. dm->dm_fat_table.antsel_rx_keep_1 = phy_sts->ant_sel_b;
  868. dm->dm_fat_table.antsel_rx_keep_2 = phy_sts->antsel_rx_keep_2;
  869. #endif
  870. }
  871. #endif
  872. #if ODM_IC_11AC_SERIES_SUPPORT
  873. void phydm_rx_physts_bw_parsing(struct phydm_phyinfo_struct *phy_info,
  874. struct phydm_perpkt_info_struct *
  875. pktinfo,
  876. struct phy_status_rpt_8812 *
  877. phy_sts)
  878. {
  879. if (pktinfo->data_rate <= ODM_RATE54M) {
  880. switch (phy_sts->r_RFMOD) {
  881. case 1:
  882. if (phy_sts->sub_chnl == 0)
  883. phy_info->band_width = 1;
  884. else
  885. phy_info->band_width = 0;
  886. break;
  887. case 2:
  888. if (phy_sts->sub_chnl == 0)
  889. phy_info->band_width = 2;
  890. else if (phy_sts->sub_chnl == 9 ||
  891. phy_sts->sub_chnl == 10)
  892. phy_info->band_width = 1;
  893. else
  894. phy_info->band_width = 0;
  895. break;
  896. default:
  897. case 0:
  898. phy_info->band_width = 0;
  899. break;
  900. }
  901. }
  902. }
  903. void phydm_get_sq(struct dm_struct *dm, struct phydm_phyinfo_struct *phy_info,
  904. u8 is_cck_rate)
  905. {
  906. u8 sq = 0;
  907. u8 pwdb_all = phy_info->rx_pwdb_all; /*precentage*/
  908. #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
  909. u8 rssi = phy_info->rx_mimo_signal_strength[0];
  910. #endif
  911. #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
  912. if (dm->iot_table.win_patch_id == RT_CID_819X_LENOVO) {
  913. if (is_cck_rate)
  914. sq = phydm_sq_patch_lenovo(dm, 1, pwdb_all, 0, 0);
  915. else
  916. sq = phydm_sq_patch_lenovo(dm, 0, pwdb_all, 0, rssi);
  917. } else
  918. #endif
  919. {
  920. if (is_cck_rate) {
  921. if (pwdb_all > 40 && !dm->is_in_hct_test) {
  922. sq = 100;
  923. } else {
  924. if (pwdb_all > 64)
  925. sq = 0;
  926. else if (pwdb_all < 20)
  927. sq = 100;
  928. else
  929. sq = ((64 - pwdb_all) * 100) / 44;
  930. }
  931. } else {
  932. sq = phy_info->rx_mimo_signal_quality[0];
  933. }
  934. }
  935. #if 0
  936. /* @dbg_print("cck sq = %d\n", sq); */
  937. #endif
  938. phy_info->signal_quality = sq;
  939. }
  940. void phydm_rx_physts_1st_type(struct dm_struct *dm,
  941. struct phydm_phyinfo_struct *phy_info,
  942. u8 *phy_status_inf,
  943. struct phydm_perpkt_info_struct *pktinfo)
  944. {
  945. u8 i = 0;
  946. s8 rx_pwr_db = 0;
  947. u8 val = 0; /*tmp value*/
  948. s8 val_s8 = 0; /*tmp value*/
  949. u8 rssi = 0; /*pre path RSSI*/
  950. u8 rf_rx_num = 0;
  951. u8 lna_idx = 0, vga_idx = 0;
  952. u8 cck_agc_rpt = 0;
  953. struct phy_status_rpt_8812 *phy_sts = NULL;
  954. #ifdef CONFIG_PHYDM_ANTENNA_DIVERSITY
  955. struct phydm_fat_struct *fat_tab = &dm->dm_fat_table;
  956. #endif
  957. phy_sts = (struct phy_status_rpt_8812 *)phy_status_inf;
  958. phydm_rx_physts_bw_parsing(phy_info, pktinfo, phy_sts);
  959. /* @== [CCK rate] ====================================================*/
  960. if (pktinfo->is_cck_rate) {
  961. cck_agc_rpt = phy_sts->cfosho[0];
  962. lna_idx = (cck_agc_rpt & 0xE0) >> 5;
  963. vga_idx = cck_agc_rpt & 0x1F;
  964. rx_pwr_db = phydm_get_cck_rssi(dm, lna_idx, vga_idx);
  965. rssi = phydm_pwr_2_percent(rx_pwr_db);
  966. if (dm->support_ic_type == ODM_RTL8812 &&
  967. !dm->is_cck_high_power) {
  968. if (rssi >= 80) {
  969. rssi = ((rssi - 80) << 1) +
  970. ((rssi - 80) >> 1) + 80;
  971. } else if ((rssi <= 78) && (rssi >= 20)) {
  972. rssi += 3;
  973. }
  974. }
  975. dm->cck_lna_idx = lna_idx;
  976. dm->cck_vga_idx = vga_idx;
  977. phy_info->rx_pwdb_all = rssi;
  978. phy_info->rx_mimo_signal_strength[0] = rssi;
  979. } else {
  980. /* @== [OFDM rate] ===================================================*/
  981. for (i = RF_PATH_A; i < dm->num_rf_path; i++) {
  982. /*@[RSSI]*/
  983. if (dm->rf_path_rx_enable & BIT(i))
  984. rf_rx_num++;
  985. if (i < RF_PATH_C)
  986. val = phy_sts->gain_trsw[i];
  987. else
  988. val = phy_sts->gain_trsw_cd[i - 2];
  989. phy_info->rx_pwr[i] = (val & 0x7F) - 110;
  990. rssi = phydm_pwr_2_percent(phy_info->rx_pwr[i]);
  991. phy_info->rx_mimo_signal_strength[i] = rssi;
  992. /*@[SNR]*/
  993. if (i < RF_PATH_C)
  994. val_s8 = phy_sts->rxsnr[i];
  995. else if (dm->support_ic_type & (ODM_RTL8814A))
  996. val_s8 = (s8)phy_sts->csi_current[i - 2];
  997. phy_info->rx_snr[i] = val_s8 >> 1;
  998. /*@[CFO_short & CFO_tail]*/
  999. if (i < RF_PATH_C) {
  1000. val_s8 = phy_sts->cfosho[i];
  1001. phy_info->cfo_short[i] = phydm_cfo(val_s8);
  1002. val_s8 = phy_sts->cfotail[i];
  1003. phy_info->cfo_tail[i] = phydm_cfo(val_s8);
  1004. }
  1005. if (i < RF_PATH_C && pktinfo->is_to_self)
  1006. dm->ofdm_agc_idx[i] = phy_sts->gain_trsw[i];
  1007. }
  1008. /* @== [PWDB] ========================================================*/
  1009. /*@(Avg PWDB calculated by hardware*/
  1010. if (!dm->is_mp_chip) /*@8812, 8821*/
  1011. val = phy_sts->pwdb_all;
  1012. else
  1013. val = phy_sts->pwdb_all >> 1; /*old fomula*/
  1014. rx_pwr_db = (val & 0x7f) - 110;
  1015. phy_info->rx_pwdb_all = phydm_pwr_2_percent(rx_pwr_db);
  1016. /*@(4)EVM of OFDM rate*/
  1017. for (i = 0; i < pktinfo->rate_ss; i++) {
  1018. if (!pktinfo->is_cck_rate &&
  1019. pktinfo->data_rate <= ODM_RATE54M) {
  1020. val_s8 = phy_sts->sigevm;
  1021. } else if (i < RF_PATH_C) {
  1022. if (phy_sts->rxevm[i] == -128)
  1023. phy_sts->rxevm[i] = -25;
  1024. val_s8 = phy_sts->rxevm[i];
  1025. } else {
  1026. if (phy_sts->rxevm_cd[i - 2] == -128)
  1027. phy_sts->rxevm_cd[i - 2] = -25;
  1028. val_s8 = phy_sts->rxevm_cd[i - 2];
  1029. }
  1030. /*@[EVM to 0~100%]*/
  1031. val = phydm_evm_2_percent(val_s8);
  1032. phy_info->rx_mimo_signal_quality[i] = val;
  1033. /*@[EVM dBm]*/
  1034. phy_info->rx_mimo_evm_dbm[i] = phydm_evm_dbm(val_s8);
  1035. }
  1036. phydm_parsing_cfo(dm, pktinfo,
  1037. phy_sts->cfotail, pktinfo->rate_ss);
  1038. }
  1039. /* @== [General Info] ================================================*/
  1040. phy_info->rx_power = rx_pwr_db;
  1041. phy_info->bt_rx_rssi_percentage = phy_info->rx_pwdb_all;
  1042. phy_info->recv_signal_power = phy_info->rx_power;
  1043. phydm_get_sq(dm, phy_info, pktinfo->is_cck_rate);
  1044. dm->rx_pwdb_ave = dm->rx_pwdb_ave + phy_info->rx_pwdb_all;
  1045. #ifdef CONFIG_PHYDM_ANTENNA_DIVERSITY
  1046. fat_tab->hw_antsw_occur = phy_sts->hw_antsw_occur;
  1047. dm->dm_fat_table.antsel_rx_keep_0 = phy_sts->antidx_anta;
  1048. dm->dm_fat_table.antsel_rx_keep_1 = phy_sts->antidx_antb;
  1049. dm->dm_fat_table.antsel_rx_keep_2 = phy_sts->antidx_antc;
  1050. dm->dm_fat_table.antsel_rx_keep_3 = phy_sts->antidx_antd;
  1051. #endif
  1052. }
  1053. #endif
  1054. void phydm_reset_rssi_for_dm(struct dm_struct *dm, u8 station_id)
  1055. {
  1056. struct cmn_sta_info *sta;
  1057. sta = dm->phydm_sta_info[station_id];
  1058. if (!is_sta_active(sta))
  1059. return;
  1060. PHYDM_DBG(dm, DBG_RSSI_MNTR, "Reset RSSI for macid = (( %d ))\n",
  1061. station_id);
  1062. sta->rssi_stat.rssi_cck = -1;
  1063. sta->rssi_stat.rssi_ofdm = -1;
  1064. sta->rssi_stat.rssi = -1;
  1065. sta->rssi_stat.ofdm_pkt_cnt = 0;
  1066. sta->rssi_stat.cck_pkt_cnt = 0;
  1067. sta->rssi_stat.cck_sum_power = 0;
  1068. sta->rssi_stat.is_send_rssi = RA_RSSI_STATE_INIT;
  1069. sta->rssi_stat.packet_map = 0;
  1070. sta->rssi_stat.valid_bit = 0;
  1071. }
  1072. #if (ODM_IC_11N_SERIES_SUPPORT || ODM_IC_11AC_SERIES_SUPPORT)
  1073. s32 phydm_get_rssi_8814_ofdm(struct dm_struct *dm, u8 *rssi_in)
  1074. {
  1075. s32 rssi_avg;
  1076. u8 rx_count = 0;
  1077. u32 rssi_linear = 0;
  1078. if (dm->rx_ant_status & BB_PATH_A) {
  1079. rx_count++;
  1080. rssi_linear += phydm_db_2_linear(rssi_in[RF_PATH_A]);
  1081. }
  1082. if (dm->rx_ant_status & BB_PATH_B) {
  1083. rx_count++;
  1084. rssi_linear += phydm_db_2_linear(rssi_in[RF_PATH_B]);
  1085. }
  1086. if (dm->rx_ant_status & BB_PATH_C) {
  1087. rx_count++;
  1088. rssi_linear += phydm_db_2_linear(rssi_in[RF_PATH_C]);
  1089. }
  1090. if (dm->rx_ant_status & BB_PATH_D) {
  1091. rx_count++;
  1092. rssi_linear += phydm_db_2_linear(rssi_in[RF_PATH_D]);
  1093. }
  1094. /* @Calculate average RSSI */
  1095. switch (rx_count) {
  1096. case 2:
  1097. rssi_linear = DIVIDED_2(rssi_linear);
  1098. break;
  1099. case 3:
  1100. rssi_linear = DIVIDED_3(rssi_linear);
  1101. break;
  1102. case 4:
  1103. rssi_linear = DIVIDED_4(rssi_linear);
  1104. break;
  1105. }
  1106. rssi_avg = odm_convert_to_db(rssi_linear);
  1107. return rssi_avg;
  1108. }
  1109. void phydm_process_rssi_for_dm(struct dm_struct *dm,
  1110. struct phydm_phyinfo_struct *phy_info,
  1111. struct phydm_perpkt_info_struct *pktinfo)
  1112. {
  1113. s32 rssi_ave = 0; /*@average among all paths*/
  1114. s8 rssi_all = 0; /*@average value of CCK & OFDM*/
  1115. s8 rssi_cck_tmp = 0, rssi_ofdm_tmp = 0;
  1116. u8 i = 0;
  1117. u8 rssi_max = 0, rssi_min = 0;
  1118. u32 w1 = 0, w2 = 0; /*weighting*/
  1119. u8 send_rssi_2_fw = 0;
  1120. u8 *rssi_tmp = NULL;
  1121. u8 val_tmp = 0;
  1122. struct cmn_sta_info *sta = NULL;
  1123. struct rssi_info *rssi_t = NULL;
  1124. #ifdef CONFIG_PHYDM_ANTENNA_DIVERSITY
  1125. #if (DM_ODM_SUPPORT_TYPE & (ODM_WIN))
  1126. struct phydm_fat_struct *fat_tab = &dm->dm_fat_table;
  1127. #endif
  1128. #endif
  1129. if (pktinfo->station_id >= ODM_ASSOCIATE_ENTRY_NUM)
  1130. return;
  1131. #ifdef CONFIG_S0S1_SW_ANTENNA_DIVERSITY
  1132. odm_s0s1_sw_ant_div_by_ctrl_frame_process_rssi(dm, phy_info, pktinfo);
  1133. #endif
  1134. sta = dm->phydm_sta_info[pktinfo->station_id];
  1135. if (!is_sta_active(sta))
  1136. return;
  1137. rssi_t = &sta->rssi_stat;
  1138. #ifdef CONFIG_PHYDM_ANTENNA_DIVERSITY
  1139. #if (DM_ODM_SUPPORT_TYPE & (ODM_WIN))
  1140. if ((dm->support_ability & ODM_BB_ANT_DIV) &&
  1141. fat_tab->enable_ctrl_frame_antdiv) {
  1142. if (pktinfo->is_packet_match_bssid)
  1143. dm->data_frame_num++;
  1144. if (fat_tab->use_ctrl_frame_antdiv) {
  1145. if (!pktinfo->is_to_self) /*@data frame + CTRL frame*/
  1146. return;
  1147. } else {
  1148. /*@data frame only*/
  1149. if (!pktinfo->is_packet_match_bssid)
  1150. return;
  1151. }
  1152. } else
  1153. #endif
  1154. #endif
  1155. {
  1156. if (!pktinfo->is_packet_match_bssid) /*@data frame only*/
  1157. return;
  1158. }
  1159. if (pktinfo->is_packet_beacon) {
  1160. dm->phy_dbg_info.num_qry_beacon_pkt++;
  1161. dm->phy_dbg_info.beacon_phy_rate = pktinfo->data_rate;
  1162. }
  1163. /* @--------------Statistic for antenna/path diversity--------------- */
  1164. #if (defined(CONFIG_PHYDM_ANTENNA_DIVERSITY))
  1165. if (dm->support_ability & ODM_BB_ANT_DIV)
  1166. odm_process_rssi_for_ant_div(dm, phy_info, pktinfo);
  1167. #endif
  1168. #if (defined(CONFIG_PATH_DIVERSITY))
  1169. if (dm->support_ability & ODM_BB_PATH_DIV)
  1170. phydm_process_rssi_for_path_div(dm, phy_info, pktinfo);
  1171. #endif
  1172. /* @----------------------------------------------------------------- */
  1173. rssi_cck_tmp = rssi_t->rssi_cck;
  1174. rssi_ofdm_tmp = rssi_t->rssi_ofdm;
  1175. rssi_all = rssi_t->rssi;
  1176. if (!(pktinfo->is_packet_to_self || pktinfo->is_packet_beacon))
  1177. return;
  1178. if (!pktinfo->is_cck_rate) {
  1179. /* @=== [ofdm RSSI] ======================================================== */
  1180. rssi_tmp = phy_info->rx_mimo_signal_strength;
  1181. #if (RTL8814A_SUPPORT == 1)
  1182. if (dm->support_ic_type & (ODM_RTL8814A)) {
  1183. rssi_ave = phydm_get_rssi_8814_ofdm(dm, rssi_tmp);
  1184. } else
  1185. #endif
  1186. {
  1187. if (rssi_tmp[RF_PATH_B] == 0) {
  1188. rssi_ave = rssi_tmp[RF_PATH_A];
  1189. } else {
  1190. if (rssi_tmp[RF_PATH_A] > rssi_tmp[RF_PATH_B]) {
  1191. rssi_max = rssi_tmp[RF_PATH_A];
  1192. rssi_min = rssi_tmp[RF_PATH_B];
  1193. } else {
  1194. rssi_max = rssi_tmp[RF_PATH_B];
  1195. rssi_min = rssi_tmp[RF_PATH_A];
  1196. }
  1197. if ((rssi_max - rssi_min) < 3)
  1198. rssi_ave = rssi_max;
  1199. else if ((rssi_max - rssi_min) < 6)
  1200. rssi_ave = rssi_max - 1;
  1201. else if ((rssi_max - rssi_min) < 10)
  1202. rssi_ave = rssi_max - 2;
  1203. else
  1204. rssi_ave = rssi_max - 3;
  1205. }
  1206. }
  1207. /* OFDM MA RSSI */
  1208. if (rssi_ofdm_tmp <= 0) { /* @initialize */
  1209. rssi_ofdm_tmp = (s8)phy_info->rx_pwdb_all;
  1210. } else {
  1211. rssi_ofdm_tmp = (s8)WEIGHTING_AVG(rssi_ofdm_tmp,
  1212. RX_SMOOTH_FACTOR - 1,
  1213. rssi_ave, 1);
  1214. if (phy_info->rx_pwdb_all > (u32)rssi_ofdm_tmp)
  1215. rssi_ofdm_tmp++;
  1216. }
  1217. PHYDM_DBG(dm, DBG_RSSI_MNTR, "rssi_ofdm=%d\n", rssi_ofdm_tmp);
  1218. if (rssi_t->ofdm_pkt_cnt != 64) {
  1219. i = 63;
  1220. val_tmp = (u8)((rssi_t->packet_map >> i) & BIT(0));
  1221. rssi_t->ofdm_pkt_cnt -= val_tmp - 1;
  1222. }
  1223. rssi_t->packet_map = (rssi_t->packet_map << 1) | BIT(0);
  1224. } else {
  1225. /* @=== [cck RSSI] ========================================================= */
  1226. rssi_ave = phy_info->rx_pwdb_all;
  1227. if (rssi_t->cck_pkt_cnt <= 63)
  1228. rssi_t->cck_pkt_cnt++;
  1229. /* @1 Process CCK RSSI */
  1230. if (rssi_cck_tmp <= 0) { /* @initialize */
  1231. rssi_cck_tmp = (s8)phy_info->rx_pwdb_all;
  1232. rssi_t->cck_sum_power = (u16)phy_info->rx_pwdb_all;
  1233. rssi_t->cck_pkt_cnt = 1; /*reset*/
  1234. PHYDM_DBG(dm, DBG_RSSI_MNTR, "[1]CCK_INIT\n");
  1235. } else if (rssi_t->cck_pkt_cnt <= CCK_RSSI_INIT_COUNT) {
  1236. rssi_t->cck_sum_power = rssi_t->cck_sum_power +
  1237. (u16)phy_info->rx_pwdb_all;
  1238. rssi_cck_tmp = rssi_t->cck_sum_power /
  1239. rssi_t->cck_pkt_cnt;
  1240. PHYDM_DBG(dm, DBG_RSSI_MNTR,
  1241. "[2]SumPow=%d, cck_pkt=%d\n",
  1242. rssi_t->cck_sum_power, rssi_t->cck_pkt_cnt);
  1243. } else {
  1244. rssi_cck_tmp = (s8)WEIGHTING_AVG(rssi_cck_tmp,
  1245. RX_SMOOTH_FACTOR - 1,
  1246. phy_info->rx_pwdb_all,
  1247. 1);
  1248. if (phy_info->rx_pwdb_all > (u32)rssi_cck_tmp)
  1249. rssi_cck_tmp++;
  1250. }
  1251. PHYDM_DBG(dm, DBG_RSSI_MNTR, "rssi_cck=%d\n", rssi_cck_tmp);
  1252. i = 63;
  1253. val_tmp = (u8)((rssi_t->packet_map >> i) & BIT(0));
  1254. rssi_t->ofdm_pkt_cnt -= val_tmp;
  1255. rssi_t->packet_map = rssi_t->packet_map << 1;
  1256. }
  1257. /* @=== [ofdm + cck weighting RSSI] ========================================= */
  1258. if (rssi_t->ofdm_pkt_cnt == 64) {
  1259. rssi_all = rssi_ofdm_tmp;
  1260. } else {
  1261. if (rssi_t->valid_bit < 64)
  1262. rssi_t->valid_bit++;
  1263. if (rssi_t->valid_bit == 64) {
  1264. if (rssi_t->ofdm_pkt_cnt > 4)
  1265. w1 = 64;
  1266. else
  1267. w1 = (u32)(rssi_t->ofdm_pkt_cnt << 4);
  1268. w2 = 64 - w1;
  1269. rssi_all = (s8)((w1 * (u32)rssi_ofdm_tmp +
  1270. w2 * (u32)rssi_cck_tmp) >> 6);
  1271. } else if (rssi_t->valid_bit != 0) { /*@(valid_bit > 64)*/
  1272. w1 = (u32)rssi_t->ofdm_pkt_cnt;
  1273. w2 = (u32)(rssi_t->valid_bit - rssi_t->ofdm_pkt_cnt);
  1274. rssi_all = (s8)WEIGHTING_AVG((u32)rssi_ofdm_tmp, w1,
  1275. (u32)rssi_cck_tmp, w2);
  1276. } else {
  1277. rssi_all = 0;
  1278. }
  1279. }
  1280. PHYDM_DBG(dm, DBG_RSSI_MNTR, "rssi=%d,w1=%d,w2=%d\n", rssi_all, w1, w2);
  1281. if ((rssi_t->ofdm_pkt_cnt >= 1 || rssi_t->cck_pkt_cnt >= 5) &&
  1282. rssi_t->is_send_rssi == RA_RSSI_STATE_INIT) {
  1283. send_rssi_2_fw = 1;
  1284. rssi_t->is_send_rssi = RA_RSSI_STATE_SEND;
  1285. }
  1286. rssi_t->rssi_cck = rssi_cck_tmp;
  1287. rssi_t->rssi_ofdm = rssi_ofdm_tmp;
  1288. rssi_t->rssi = rssi_all;
  1289. if (send_rssi_2_fw) { /* Trigger init rate by RSSI */
  1290. if (rssi_t->ofdm_pkt_cnt != 0)
  1291. rssi_t->rssi = rssi_ofdm_tmp;
  1292. PHYDM_DBG(dm, DBG_RSSI_MNTR,
  1293. "[Send to FW] PWDB=%d, ofdm_pkt=%d, cck_pkt=%d\n",
  1294. rssi_all, rssi_t->ofdm_pkt_cnt, rssi_t->cck_pkt_cnt);
  1295. }
  1296. #if 0
  1297. /* @dbg_print("ofdm_pkt=%d, weighting=%d\n", ofdm_pkt_cnt, weighting);*/
  1298. /* @dbg_print("rssi_ofdm_tmp=%d, rssi_all=%d, rssi_cck_tmp=%d\n", */
  1299. /* rssi_ofdm_tmp, rssi_all, rssi_cck_tmp); */
  1300. #endif
  1301. }
  1302. #endif
  1303. #ifdef PHYSTS_3RD_TYPE_SUPPORT
  1304. void phydm_print_phystat_jaguar3(struct dm_struct *dm, u8 *phy_sts,
  1305. struct phydm_perpkt_info_struct *pktinfo,
  1306. struct phydm_phyinfo_struct *phy_info)
  1307. {
  1308. struct phy_status_rpt_jaguar3_type0 *rpt0 = NULL;
  1309. struct phy_status_rpt_jaguar3_type1 *rpt1 = NULL;
  1310. struct phy_status_rpt_jaguar3_type2_type3 *rpt2 = NULL;
  1311. struct phy_status_rpt_jaguar3_type4 *rpt3 = NULL;
  1312. struct phy_status_rpt_jaguar3_type5 *rpt4 = NULL;
  1313. struct odm_phy_dbg_info *dbg = &dm->phy_dbg_info;
  1314. u8 phy_status_page_num = (*phy_sts & 0xf);
  1315. u32 phy_status_tmp[PHY_STATUS_JRGUAR3_DW_LEN] = {0};
  1316. u8 i;
  1317. u32 size = PHY_STATUS_JRGUAR3_DW_LEN << 2;
  1318. rpt0 = (struct phy_status_rpt_jaguar3_type0 *)phy_sts;
  1319. rpt1 = (struct phy_status_rpt_jaguar3_type1 *)phy_sts;
  1320. rpt2 = (struct phy_status_rpt_jaguar3_type2_type3 *)phy_sts;
  1321. rpt3 = (struct phy_status_rpt_jaguar3_type4 *)phy_sts;
  1322. rpt4 = (struct phy_status_rpt_jaguar3_type5 *)phy_sts;
  1323. odm_move_memory(dm, phy_status_tmp, phy_sts, size);
  1324. if (!(dm->debug_components & DBG_PHY_STATUS))
  1325. return;
  1326. if (dbg->show_phy_sts_all_pkt == 0) {
  1327. if (!pktinfo->is_packet_match_bssid)
  1328. return;
  1329. }
  1330. dbg->show_phy_sts_cnt++;
  1331. if (dbg->show_phy_sts_max_cnt != SHOW_PHY_STATUS_UNLIMITED) {
  1332. if (dbg->show_phy_sts_cnt > dbg->show_phy_sts_max_cnt)
  1333. return;
  1334. }
  1335. pr_debug("Phy Status Rpt: OFDM_%d\n", phy_status_page_num);
  1336. pr_debug("StaID=%d, RxRate = 0x%x match_bssid=%d\n",
  1337. pktinfo->station_id, pktinfo->data_rate,
  1338. pktinfo->is_packet_match_bssid);
  1339. for (i = 0; i < PHY_STATUS_JRGUAR3_DW_LEN; i++)
  1340. pr_debug("Offset[%d:%d] = 0x%x\n",
  1341. ((4 * i) + 3), (4 * i), phy_status_tmp[i]);
  1342. if (phy_status_page_num == 0) { /* @CCK(default) */
  1343. pr_debug("[0] Pkt_cnt=%d, Channel_msb=%d, Pwdb_a=%d, Gain_a=%d, TRSW=%d, AGC_table_b=%d, AGC_table_c=%d,\n",
  1344. rpt0->pkt_cnt, rpt0->channel_msb, rpt0->pwdb_a,
  1345. rpt0->gain_a, rpt0->trsw, rpt0->agc_table_b,
  1346. rpt0->agc_table_c);
  1347. pr_debug("[4] Path_Sel_o=%d, Gnt_BT_keep_cnt=%d, HW_AntSW_occur_keep_cck=%d,\n Band=%d, Channel=%d, AGC_table_a=%d, l_RXSC=%d, AGC_table_d=%d\n",
  1348. rpt0->path_sel_o, rpt0->gnt_bt_keep_cck,
  1349. rpt0->hw_antsw_occur_keep_cck, rpt0->band,
  1350. rpt0->channel, rpt0->agc_table_a, rpt0->l_rxsc,
  1351. rpt0->agc_table_d);
  1352. pr_debug("[8] AntIdx={%d, %d, %d, %d}, Length=%d\n",
  1353. rpt0->antidx_d, rpt0->antidx_c, rpt0->antidx_b,
  1354. rpt0->antidx_a, rpt0->length);
  1355. pr_debug("[12] MF_off=%d, SQloss=%d, lockbit=%d, raterr=%d, rxrate=%d, lna_h_a=%d, CCK_BB_power_a=%d, lna_l_a=%d, vga_a=%d, sq=%d\n",
  1356. rpt0->mf_off, rpt0->sqloss, rpt0->lockbit,
  1357. rpt0->raterr, rpt0->rxrate, rpt0->lna_h_a,
  1358. rpt0->bb_power_a, rpt0->lna_l_a, rpt0->vga_a,
  1359. rpt0->signal_quality);
  1360. pr_debug("[16] Gain_b=%d, lna_h_b=%d, CCK_BB_power_b=%d, lna_l_b=%d, vga_b=%d, Pwdb_b=%d\n",
  1361. rpt0->gain_b, rpt0->lna_h_b, rpt0->bb_power_b,
  1362. rpt0->lna_l_b, rpt0->vga_b, rpt0->pwdb_b);
  1363. pr_debug("[20] Gain_c=%d, lna_h_c=%d, CCK_BB_power_c=%d, lna_l_c=%d, vga_c=%d, Pwdb_c=%d\n",
  1364. rpt0->gain_c, rpt0->lna_h_c, rpt0->bb_power_c,
  1365. rpt0->lna_l_c, rpt0->vga_c, rpt0->pwdb_c);
  1366. pr_debug("[24] Gain_d=%d, lna_h_d=%d, CCK_BB_power_d=%d, lna_l_d=%d, vga_d=%d, Pwdb_d=%d\n",
  1367. rpt0->gain_c, rpt0->lna_h_c, rpt0->bb_power_c,
  1368. rpt0->lna_l_c, rpt0->vga_c, rpt0->pwdb_c);
  1369. } else if (phy_status_page_num == 1) {
  1370. pr_debug("[0] pwdb[C:A]={%d, %d, %d}, Channel_pri_msb=%d, Pkt_cnt=%d,\n",
  1371. rpt1->pwdb_c, rpt1->pwdb_b, rpt1->pwdb_a,
  1372. rpt1->channel_pri_msb, rpt1->pkt_cnt);
  1373. pr_debug("[4] BF: %d, stbc=%d, ldpc=%d, gnt_bt=%d, band=%d, Ch_pri_lsb=%d, rxsc[ht, l]={%d, %d}, pwdb[D]=%d\n",
  1374. rpt1->beamformed, rpt1->stbc, rpt1->ldpc, rpt1->gnt_bt,
  1375. rpt1->band, rpt1->channel_pri_lsb, rpt1->ht_rxsc,
  1376. rpt1->l_rxsc, rpt1->pwdb_d);
  1377. pr_debug("[8] AntIdx[D:A]={%d, %d, %d, %d}, HW_AntSW_occur[D:A]={%d, %d, %d,%d}, Channel_sec[msb,lsb]={%d, %d}\n",
  1378. rpt1->antidx_d, rpt1->antidx_c,
  1379. rpt1->antidx_b, rpt1->antidx_a,
  1380. rpt1->hw_antsw_occur_d, rpt1->hw_antsw_occur_c,
  1381. rpt1->hw_antsw_occur_b, rpt1->hw_antsw_occur_a,
  1382. rpt1->channel_sec_msb, rpt1->channel_sec_lsb);
  1383. pr_debug("[12] GID=%d, PAID[msb,lsb]={%d,%d}\n",
  1384. rpt1->gid, rpt1->paid_msb, rpt1->paid);
  1385. pr_debug("[16] RX_EVM[D:A]={%d, %d, %d, %d}\n",
  1386. rpt1->rxevm[3], rpt1->rxevm[2],
  1387. rpt1->rxevm[1], rpt1->rxevm[0]);
  1388. pr_debug("[20] CFO_tail[D:A]={%d, %d, %d, %d}\n",
  1389. rpt1->cfo_tail[3], rpt1->cfo_tail[2],
  1390. rpt1->cfo_tail[1], rpt1->cfo_tail[0]);
  1391. pr_debug("[24] RX_SNR[D:A]={%d, %d, %d, %d}\n\n",
  1392. rpt1->rxsnr[3], rpt1->rxsnr[2],
  1393. rpt1->rxsnr[1], rpt1->rxsnr[0]);
  1394. } else if (phy_status_page_num == 2 || phy_status_page_num == 3) {
  1395. pr_debug("[0] pwdb[C:A]={%d, %d, %d}, Channel_mdb=%d, Pkt_cnt=%d\n",
  1396. rpt2->pwdb[2], rpt2->pwdb[1], rpt2->pwdb[0],
  1397. rpt2->channel_msb, rpt2->pkt_cnt);
  1398. pr_debug("[4] BF=%d, STBC=%d, LDPC=%d, Gnt_BT=%d, band=%d, CH_lsb=%d, rxsc[ht, l]={%d, %d}, pwdb_D=%d\n",
  1399. rpt2->beamformed, rpt2->stbc, rpt2->ldpc, rpt2->gnt_bt,
  1400. rpt2->band, rpt2->channel_lsb,
  1401. rpt2->ht_rxsc, rpt2->l_rxsc, rpt2->pwdb[3]);
  1402. pr_debug("[8] AgcTab[D:A]={%d, %d, %d, %d}, pwed_th=%d, shift_l_map=%d\n",
  1403. rpt2->agc_table_d, rpt2->agc_table_c,
  1404. rpt2->agc_table_b, rpt2->agc_table_a,
  1405. rpt2->pwed_th, rpt2->shift_l_map);
  1406. pr_debug("[12] AvgNoisePowerdB=%d, mp_gain_c[msb, lsb]={%d, %d}, mp_gain_b[msb, lsb]={%d, %d}, mp_gain_a=%d, cnt_cca2agc_rdy=%d\n",
  1407. rpt2->avg_noise_pwr_lsb, rpt2->mp_gain_c_msb,
  1408. rpt2->mp_gain_c_lsb, rpt2->mp_gain_b_msb,
  1409. rpt2->mp_gain_b_lsb, rpt2->mp_gain_a,
  1410. rpt2->cnt_cca2agc_rdy);
  1411. pr_debug("[16] HT AAGC gain[B:A]={%d, %d}, AAGC step[D:A]={%d, %d, %d, %d}, IsFreqSelectFadimg=%d, mp_gain_d=%d\n",
  1412. rpt2->ht_aagc_gain[1], rpt2->ht_aagc_gain[0],
  1413. rpt2->aagc_step_d, rpt2->aagc_step_c,
  1414. rpt2->aagc_step_b, rpt2->aagc_step_a,
  1415. rpt2->is_freq_select_fading, rpt2->mp_gain_d);
  1416. pr_debug("[20] DAGC gain ant[B:A]={%d, %d}, HT AAGC gain[D:C]={%d, %d}\n",
  1417. rpt2->dagc_gain[1], rpt2->dagc_gain[0],
  1418. rpt2->ht_aagc_gain[3], rpt2->ht_aagc_gain[2]);
  1419. pr_debug("[24] AvgNoisePwerdB=%d, syn_count[msb, lsb]={%d, %d}, counter=%d, DAGC gain ant[D:C]={%d, %d}\n",
  1420. rpt2->avg_noise_pwr_msb, rpt2->syn_count_msb,
  1421. rpt2->syn_count_lsb, rpt2->counter,
  1422. rpt2->dagc_gain[3], rpt2->dagc_gain[2]);
  1423. } else if (phy_status_page_num == 4) { /*type 4*/
  1424. pr_debug("[0] pwdb[C:A]={%d, %d, %d}, Channel_mdb=%d, Pkt_cnt=%d\n",
  1425. rpt3->pwdb[2], rpt3->pwdb[1], rpt3->pwdb[0],
  1426. rpt3->channel_msb, rpt3->pkt_cnt);
  1427. pr_debug("[4] BF=%d, STBC=%d, LDPC=%d, GNT_BT=%d, band=%d, CH_pri=%d, rxsc[ht, l]={%d, %d}, pwdb_D=%d\n",
  1428. rpt3->beamformed, rpt3->stbc, rpt3->ldpc, rpt3->gnt_bt,
  1429. rpt3->band, rpt3->channel_lsb, rpt3->ht_rxsc,
  1430. rpt3->l_rxsc, rpt3->pwdb[3]);
  1431. pr_debug("[8] AntIdx[D:A]={%d, %d, %d, %d}, HW_AntSW_occur[D:A]={%d, %d, %d, %d}, Training_done[D:A]={%d, %d, %d, %d},\n BadToneCnt_CN_excess_0=%d, BadToneCnt_min_eign_0=%d\n",
  1432. rpt3->antidx_d, rpt3->antidx_c,
  1433. rpt3->antidx_b, rpt3->antidx_a,
  1434. rpt3->hw_antsw_occur_d, rpt3->hw_antsw_occur_c,
  1435. rpt3->hw_antsw_occur_b, rpt3->hw_antsw_occur_a,
  1436. rpt3->training_done_d, rpt3->training_done_c,
  1437. rpt3->training_done_b, rpt3->training_done_a,
  1438. rpt3->bad_tone_cnt_cn_excess_0,
  1439. rpt3->bad_tone_cnt_min_eign_0);
  1440. pr_debug("[12] avg_cond_num_1_msb=%d, avg_cond_num_1_lsb=%d, avg_cond_num_0=%d, bad_tone_cnt_cn_excess_1=%d, bad_tone_cnt_min_eign_1=%d, Tx_pkt_cnt=%d\n",
  1441. rpt3->avg_cond_num_1_msb, rpt3->avg_cond_num_1_lsb,
  1442. rpt3->avg_cond_num_0, rpt3->bad_tone_cnt_cn_excess_1,
  1443. rpt3->bad_tone_cnt_min_eign_1, rpt3->tx_pkt_cnt);
  1444. pr_debug("[16] Stream RXEVM[D:A]={%d, %d, %d, %d}\n",
  1445. rpt3->rxevm[3], rpt3->rxevm[2],
  1446. rpt3->rxevm[1], rpt3->rxevm[0]);
  1447. pr_debug("[20] Eigenvalue[D:A]={%d, %d, %d, %d}\n",
  1448. rpt3->eigenvalue[3], rpt3->eigenvalue[2],
  1449. rpt3->eigenvalue[1], rpt3->eigenvalue[0]);
  1450. pr_debug("[24] RX SNR[D:A]={%d, %d, %d, %d}\n",
  1451. rpt3->rxsnr[3], rpt3->rxsnr[2],
  1452. rpt3->rxsnr[1], rpt3->rxsnr[0]);
  1453. } else if (phy_status_page_num == 5) { /*type 5*/
  1454. pr_debug("[0] pwdb[C:A]={%d, %d, %d}, Channel_mdb=%d, Pkt_cnt=%d\n",
  1455. rpt4->pwdb[2], rpt4->pwdb[1], rpt4->pwdb[0],
  1456. rpt4->channel_msb, rpt4->pkt_cnt);
  1457. pr_debug("[4] BF=%d, STBC=%d, LDPC=%d, GNT_BT=%d, band=%d, CH_pri=%d, rxsc[ht, l]={%d, %d}, pwdb_D=%d\n",
  1458. rpt4->beamformed, rpt4->stbc, rpt4->ldpc, rpt4->gnt_bt,
  1459. rpt4->band, rpt4->channel_lsb, rpt4->ht_rxsc,
  1460. rpt4->l_rxsc, rpt4->pwdb[3]);
  1461. pr_debug("[8] AntIdx[D:A]={%d, %d, %d, %d}, HW_AntSW_occur[D:A]={%d, %d, %d, %d}\n",
  1462. rpt4->antidx_d, rpt4->antidx_c,
  1463. rpt4->antidx_b, rpt4->antidx_a,
  1464. rpt4->hw_antsw_occur_d, rpt4->hw_antsw_occur_c,
  1465. rpt4->hw_antsw_occur_b, rpt4->hw_antsw_occur_a);
  1466. pr_debug("[12] Inf_posD[1,0]={%d, %d}, Inf_posC[1,0]={%d, %d}, Inf_posB[1,0]={%d, %d}, Inf_posA[1,0]={%d, %d}, Tx_pkt_cnt=%d\n",
  1467. rpt4->inf_pos_1_D_flg, rpt4->inf_pos_0_D_flg,
  1468. rpt4->inf_pos_1_C_flg, rpt4->inf_pos_0_C_flg,
  1469. rpt4->inf_pos_1_B_flg, rpt4->inf_pos_0_B_flg,
  1470. rpt4->inf_pos_1_A_flg, rpt4->inf_pos_0_A_flg,
  1471. rpt4->tx_pkt_cnt);
  1472. pr_debug("[16] Inf_pos_B[1,0]={%d, %d}, Inf_pos_A[1,0]={%d, %d}\n",
  1473. rpt4->inf_pos_1_b, rpt4->inf_pos_0_b,
  1474. rpt4->inf_pos_1_a, rpt4->inf_pos_0_a);
  1475. pr_debug("[20] Inf_pos_D[1,0]={%d, %d}, Inf_pos_C[1,0]={%d, %d}\n",
  1476. rpt4->inf_pos_1_d, rpt4->inf_pos_0_d,
  1477. rpt4->inf_pos_1_c, rpt4->inf_pos_0_c);
  1478. }
  1479. }
  1480. void phydm_reset_phy_info_3rd(struct dm_struct *phydm,
  1481. struct phydm_phyinfo_struct *phy_info)
  1482. {
  1483. phy_info->rx_pwdb_all = 0;
  1484. phy_info->signal_quality = 0;
  1485. phy_info->band_width = 0;
  1486. phy_info->rx_count = 0;
  1487. odm_memory_set(phydm, phy_info->rx_mimo_signal_quality, 0, 4);
  1488. odm_memory_set(phydm, phy_info->rx_mimo_signal_strength, 0, 4);
  1489. odm_memory_set(phydm, phy_info->rx_snr, 0, 4);
  1490. phy_info->rx_power = -110;
  1491. phy_info->recv_signal_power = -110;
  1492. phy_info->bt_rx_rssi_percentage = 0;
  1493. phy_info->signal_strength = 0;
  1494. phy_info->channel = 0;
  1495. phy_info->is_mu_packet = 0;
  1496. phy_info->is_beamformed = 0;
  1497. phy_info->rxsc = 0;
  1498. odm_memory_set(phydm, phy_info->rx_pwr, -110, 4);
  1499. odm_memory_set(phydm, phy_info->cfo_short, 0, 8);
  1500. odm_memory_set(phydm, phy_info->cfo_tail, 0, 8);
  1501. odm_memory_set(phydm, phy_info->rx_mimo_evm_dbm, 0, 4);
  1502. }
  1503. phydm_per_path_info_3rd(u8 rx_path, s8 pwr, s8 rx_evm, s8 cfo_tail, s8 rx_snr,
  1504. struct phydm_phyinfo_struct *phy_info)
  1505. {
  1506. u8 evm_dbm = 0;
  1507. u8 evm_percentage = 0;
  1508. /* SNR is S(8,1), EVM is S(8,1), CFO is S(8,7) */
  1509. if (rx_evm < 0) {
  1510. /* @Calculate EVM in dBm */
  1511. evm_dbm = ((u8)(0 - rx_evm) >> 1);
  1512. if (evm_dbm == 64)
  1513. evm_dbm = 0; /*@if 1SS rate, evm_dbm [2nd stream] =64*/
  1514. if (evm_dbm != 0) {
  1515. /* @Convert EVM to 0%~100% percentage */
  1516. if (evm_dbm >= 34)
  1517. evm_percentage = 100;
  1518. else
  1519. evm_percentage = (evm_dbm << 1) + (evm_dbm);
  1520. }
  1521. }
  1522. phy_info->rx_pwr[rx_path] = pwr;
  1523. /*@CFO(kHz) = CFO_tail * 312.5(kHz) / 2^7 ~= CFO tail * 5/2 (kHz)*/
  1524. phy_info->cfo_tail[rx_path] = (cfo_tail * 5) >> 1;
  1525. phy_info->rx_mimo_evm_dbm[rx_path] = evm_dbm;
  1526. phy_info->rx_mimo_signal_strength[rx_path] = phydm_pwr_2_percent(pwr);
  1527. phy_info->rx_mimo_signal_quality[rx_path] = evm_percentage;
  1528. phy_info->rx_snr[rx_path] = rx_snr >> 1;
  1529. }
  1530. void phydm_common_phy_info_3rd(s8 rx_power, u8 channel, boolean is_beamformed,
  1531. boolean is_mu_packet, u8 bandwidth,
  1532. u8 signal_quality, u8 rxsc,
  1533. struct phydm_phyinfo_struct *phy_info)
  1534. {
  1535. phy_info->rx_power = rx_power; /* RSSI in dB */
  1536. phy_info->recv_signal_power = rx_power; /* RSSI in dB */
  1537. phy_info->channel = channel; /* @channel number */
  1538. phy_info->is_beamformed = is_beamformed; /* @apply BF */
  1539. phy_info->is_mu_packet = is_mu_packet; /* @MU packet */
  1540. phy_info->rxsc = rxsc;
  1541. phy_info->rx_pwdb_all = phydm_pwr_2_percent(rx_power); /*percentage */
  1542. phy_info->signal_quality = signal_quality; /* signal quality */
  1543. phy_info->band_width = bandwidth; /* @bandwidth */
  1544. #if 0
  1545. /* @if (pktinfo->is_packet_match_bssid) */
  1546. {
  1547. dbg_print("rx_pwdb_all = %d, rx_power = %d, recv_signal_power = %d\n", phy_info->rx_pwdb_all, phy_info->rx_power, phy_info->recv_signal_power);
  1548. dbg_print("signal_quality = %d\n", phy_info->signal_quality);
  1549. dbg_print("is_beamformed = %d, is_mu_packet = %d, rx_count = %d\n", phy_info->is_beamformed, phy_info->is_mu_packet, phy_info->rx_count + 1);
  1550. dbg_print("channel = %d, rxsc = %d, band_width = %d\n", channel, rxsc, bandwidth);
  1551. }
  1552. #endif
  1553. }
  1554. void phydm_get_physts_jarguar3_0(struct dm_struct *dm, u8 *phy_status_inf,
  1555. struct phydm_perpkt_info_struct *pktinfo,
  1556. struct phydm_phyinfo_struct *phy_info)
  1557. {
  1558. /* type 0 is used for cck packet */
  1559. struct phy_status_rpt_jaguar3_type0 *phy_sts = NULL;
  1560. u8 sq = 0, i;
  1561. s8 rx_power[4];
  1562. s8 rx_pwr_db_max = -120;
  1563. phy_sts = (struct phy_status_rpt_jaguar3_type0 *)phy_status_inf;
  1564. /* Setting the RX power: agc_idx -110 dBm*/
  1565. rx_power[0] = phy_sts->pwdb_a - 110;
  1566. rx_power[1] = phy_sts->pwdb_b - 110;
  1567. rx_power[2] = phy_sts->pwdb_c - 110;
  1568. rx_power[3] = phy_sts->pwdb_d - 110;
  1569. for (i = RF_PATH_A; i < PHYDM_MAX_RF_PATH; i++) {
  1570. if (rx_power[i] > rx_pwr_db_max)
  1571. rx_pwr_db_max = rx_power[0]; /*only one path*/
  1572. }
  1573. if (pktinfo->is_to_self) {
  1574. dm->ofdm_agc_idx[0] = phy_sts->pwdb_a;
  1575. dm->ofdm_agc_idx[1] = phy_sts->pwdb_b;
  1576. dm->ofdm_agc_idx[2] = phy_sts->pwdb_c;
  1577. dm->ofdm_agc_idx[3] = phy_sts->pwdb_d;
  1578. }
  1579. /* @Calculate Signal Quality*/
  1580. if (phy_sts->signal_quality >= 64) {
  1581. sq = 0;
  1582. } else if (phy_sts->signal_quality <= 20) {
  1583. sq = 100;
  1584. } else {
  1585. /* @mapping to 2~99% */
  1586. sq = 64 - phy_sts->signal_quality;
  1587. sq = ((sq << 3) + sq) >> 2;
  1588. }
  1589. /* @Modify CCK PWDB if old AGC */
  1590. if (!dm->cck_new_agc) {
  1591. u8 lna_idx[4], vga_idx[4];
  1592. lna_idx[0] = ((phy_sts->lna_h_a << 3) | phy_sts->lna_l_a);
  1593. vga_idx[0] = phy_sts->vga_a;
  1594. lna_idx[1] = ((phy_sts->lna_h_b << 3) | phy_sts->lna_l_b);
  1595. vga_idx[1] = phy_sts->vga_b;
  1596. lna_idx[2] = ((phy_sts->lna_h_c << 3) | phy_sts->lna_l_c);
  1597. vga_idx[2] = phy_sts->vga_c;
  1598. lna_idx[3] = ((phy_sts->lna_h_d << 3) | phy_sts->lna_l_d);
  1599. vga_idx[3] = phy_sts->vga_d;
  1600. #if (RTL8198F_SUPPORT)
  1601. /*phydm_cck_rssi_8198f*/
  1602. #endif
  1603. }
  1604. /*@CCK no STBC and LDPC*/
  1605. dm->phy_dbg_info.is_ldpc_pkt = false;
  1606. dm->phy_dbg_info.is_stbc_pkt = false;
  1607. /* Update Common information */
  1608. phydm_common_phy_info_3rd(rx_pwr_db_max, phy_sts->channel, false,
  1609. false, CHANNEL_WIDTH_20, sq,
  1610. phy_sts->l_rxsc, phy_info);
  1611. /* Update CCK pwdb */
  1612. /* Update per-path information */
  1613. phydm_per_path_info_3rd(RF_PATH_A, rx_power[0], 0, 0, 0, phy_info);
  1614. phydm_per_path_info_3rd(RF_PATH_B, rx_power[1], 0, 0, 0, phy_info);
  1615. phydm_per_path_info_3rd(RF_PATH_C, rx_power[2], 0, 0, 0, phy_info);
  1616. phydm_per_path_info_3rd(RF_PATH_D, rx_power[3], 0, 0, 0, phy_info);
  1617. #ifdef CONFIG_PHYDM_ANTENNA_DIVERSITY
  1618. dm->dm_fat_table.antsel_rx_keep_0 = phy_sts->antidx_a;
  1619. dm->dm_fat_table.antsel_rx_keep_1 = phy_sts->antidx_b;
  1620. dm->dm_fat_table.antsel_rx_keep_2 = phy_sts->antidx_c;
  1621. dm->dm_fat_table.antsel_rx_keep_3 = phy_sts->antidx_d;
  1622. #endif
  1623. }
  1624. void phydm_get_physts_jarguar3_1(struct dm_struct *dm, u8 *phy_status_inf,
  1625. struct phydm_perpkt_info_struct *pktinfo,
  1626. struct phydm_phyinfo_struct *phy_info)
  1627. {
  1628. /* type 1 is used for ofdm packet */
  1629. struct phy_status_rpt_jaguar3_type1 *phy_sts = NULL;
  1630. struct odm_phy_dbg_info *dbg_i = &dm->phy_dbg_info;
  1631. s8 rx_pwr_db = -120;
  1632. s8 rx_path_pwr_db;
  1633. u8 i, rxsc, bw = CHANNEL_WIDTH_20, rx_cnt = 0;
  1634. u8 pwdb[4];
  1635. boolean is_mu;
  1636. phy_sts = (struct phy_status_rpt_jaguar3_type1 *)phy_status_inf;
  1637. pwdb[0] = phy_sts->pwdb_a;
  1638. pwdb[1] = phy_sts->pwdb_b;
  1639. pwdb[2] = phy_sts->pwdb_c;
  1640. pwdb[3] = phy_sts->pwdb_d;
  1641. /* Update per-path information */
  1642. for (i = RF_PATH_A; i < PHYDM_MAX_RF_PATH; i++) {
  1643. if (dm->rx_ant_status & BIT(i)) {
  1644. rx_cnt++; /* @check the number of the ant */
  1645. if (rx_cnt > dm->num_rf_path)
  1646. break;
  1647. /* Update per-path information
  1648. * (RSSI_dB RSSI_percentage EVM SNR CFO sq)
  1649. */
  1650. /* @EVM report is reported by stream, not path */
  1651. rx_path_pwr_db = pwdb[i] - 110; /* per-path pw (dB)*/
  1652. if (pktinfo->is_to_self)
  1653. dm->ofdm_agc_idx[i] = pwdb[i];
  1654. phydm_per_path_info_3rd(i, rx_path_pwr_db,
  1655. phy_sts->rxevm[rx_cnt - 1],
  1656. phy_sts->cfo_tail[i],
  1657. phy_sts->rxsnr[i], phy_info);
  1658. /* search maximum pwdb */
  1659. if (rx_path_pwr_db > rx_pwr_db)
  1660. rx_pwr_db = rx_path_pwr_db;
  1661. }
  1662. }
  1663. /* @mapping RX counter from 1~4 to 0~3 */
  1664. if (rx_cnt > 0)
  1665. phy_info->rx_count = rx_cnt - 1;
  1666. /* @Check if MU packet or not */
  1667. if (phy_sts->gid != 0 && phy_sts->gid != 63) {
  1668. is_mu = true;
  1669. dbg_i->num_qry_mu_pkt++;
  1670. } else {
  1671. is_mu = false;
  1672. }
  1673. /* @count BF packet */
  1674. dbg_i->num_qry_bf_pkt = dbg_i->num_qry_bf_pkt + phy_sts->beamformed;
  1675. /*STBC or LDPC pkt*/
  1676. dbg_i->is_ldpc_pkt = phy_sts->ldpc;
  1677. dbg_i->is_stbc_pkt = phy_sts->stbc;
  1678. /* @Check sub-channel */
  1679. if (pktinfo->data_rate > ODM_RATE11M &&
  1680. pktinfo->data_rate < ODM_RATEMCS0)
  1681. rxsc = phy_sts->l_rxsc; /*@Legacy*/
  1682. else
  1683. rxsc = phy_sts->ht_rxsc; /* @HT and VHT */
  1684. /* @Check RX bandwidth */
  1685. if (dm->support_ic_type & ODM_IC_JGR3_SERIES) {
  1686. if (rxsc >= 1 && rxsc <= 8)
  1687. bw = CHANNEL_WIDTH_20;
  1688. else if ((rxsc >= 9) && (rxsc <= 12))
  1689. bw = CHANNEL_WIDTH_40;
  1690. else if (rxsc >= 13)
  1691. bw = CHANNEL_WIDTH_80;
  1692. }
  1693. /* Update packet information */
  1694. /* RX power choose the path with the maximum power */
  1695. phydm_common_phy_info_3rd(rx_pwr_db, phy_sts->channel_pri_lsb,
  1696. (boolean)phy_sts->beamformed, is_mu,
  1697. bw, phy_info->rx_mimo_signal_quality[0],
  1698. rxsc, phy_info);
  1699. phydm_parsing_cfo(dm, pktinfo, phy_sts->cfo_tail, pktinfo->rate_ss);
  1700. #if (defined(CONFIG_PHYDM_ANTENNA_DIVERSITY))
  1701. dm->dm_fat_table.antsel_rx_keep_0 = phy_sts->antidx_a;
  1702. dm->dm_fat_table.antsel_rx_keep_1 = phy_sts->antidx_b;
  1703. dm->dm_fat_table.antsel_rx_keep_2 = phy_sts->antidx_c;
  1704. dm->dm_fat_table.antsel_rx_keep_3 = phy_sts->antidx_d;
  1705. #endif
  1706. }
  1707. void phydm_get_physts_jarguar3_2_3(struct dm_struct *dm, u8 *phy_status_inf,
  1708. struct phydm_perpkt_info_struct *pktinfo,
  1709. struct phydm_phyinfo_struct *phy_info)
  1710. {
  1711. /* type 2 & 3 is used for ofdm packet */
  1712. struct phy_status_rpt_jaguar3_type2_type3 *phy_sts = NULL;
  1713. s8 rx_pwr_db_max = -120;
  1714. s8 rx_path_pwr_db;
  1715. u8 i, rxsc, bw = CHANNEL_WIDTH_20, rx_count = 0;
  1716. phy_sts = (struct phy_status_rpt_jaguar3_type2_type3 *)phy_status_inf;
  1717. /* Update per-path information */
  1718. for (i = RF_PATH_A; i < PHYDM_MAX_RF_PATH; i++) {
  1719. if (dm->rx_ant_status & BIT(i)) {
  1720. rx_count++; /* @check the number of the ant */
  1721. if (rx_count > dm->num_rf_path)
  1722. break;
  1723. /* Update per-path information
  1724. * (RSSI_dB RSSI_percentage EVM SNR CFO sq)
  1725. */
  1726. /* @EVM report is reported by stream, not path */
  1727. rx_path_pwr_db = phy_sts->pwdb[i] - 110; /*@dB*/
  1728. if (pktinfo->is_to_self)
  1729. dm->ofdm_agc_idx[i] = phy_sts->pwdb[i];
  1730. phydm_per_path_info_3rd(i, rx_path_pwr_db, 0,
  1731. 0, 0, phy_info);
  1732. /* search maximum pwdb */
  1733. if (rx_path_pwr_db > rx_pwr_db_max)
  1734. rx_pwr_db_max = rx_path_pwr_db;
  1735. }
  1736. }
  1737. /* @mapping RX counter from 1~4 to 0~3 */
  1738. if (rx_count > 0)
  1739. phy_info->rx_count = rx_count - 1;
  1740. /* @count BF packet */
  1741. dm->phy_dbg_info.num_qry_bf_pkt = dm->phy_dbg_info.num_qry_bf_pkt +
  1742. phy_sts->beamformed;
  1743. /*STBC or LDPC pkt*/
  1744. dm->phy_dbg_info.is_ldpc_pkt = phy_sts->ldpc;
  1745. dm->phy_dbg_info.is_stbc_pkt = phy_sts->stbc;
  1746. /* @Check sub-channel */
  1747. if (pktinfo->data_rate > ODM_RATE11M &&
  1748. pktinfo->data_rate < ODM_RATEMCS0)
  1749. rxsc = phy_sts->l_rxsc; /*@Legacy*/
  1750. else
  1751. rxsc = phy_sts->ht_rxsc; /* @HT and VHT */
  1752. /* @Check RX bandwidth */
  1753. if (dm->support_ic_type & ODM_IC_JGR3_SERIES) {
  1754. if (rxsc >= 1 && rxsc <= 8)
  1755. bw = CHANNEL_WIDTH_20;
  1756. else if ((rxsc >= 9) && (rxsc <= 12))
  1757. bw = CHANNEL_WIDTH_40;
  1758. else if (rxsc >= 13)
  1759. bw = CHANNEL_WIDTH_80;
  1760. }
  1761. /* Update packet information */
  1762. /* RX power choose the path with the maximum power */
  1763. phydm_common_phy_info_3rd(rx_pwr_db_max, phy_sts->channel_lsb,
  1764. (boolean)phy_sts->beamformed,
  1765. false, bw, 0, rxsc, phy_info);
  1766. }
  1767. void phydm_get_physts_jarguar3_4(struct dm_struct *dm, u8 *phy_status_inf,
  1768. struct phydm_perpkt_info_struct *pktinfo,
  1769. struct phydm_phyinfo_struct *phy_info)
  1770. {
  1771. /* type 4 is used for ofdm packet */
  1772. struct phy_status_rpt_jaguar3_type4 *phy_sts = NULL;
  1773. s8 rx_pwr_db_max = -120;
  1774. s8 rx_path_pwr_db;
  1775. u8 i, rxsc, bw = CHANNEL_WIDTH_20, rx_cnt = 0;
  1776. phy_sts = (struct phy_status_rpt_jaguar3_type4 *)phy_status_inf;
  1777. /* Update per-path information */
  1778. for (i = RF_PATH_A; i < PHYDM_MAX_RF_PATH; i++) {
  1779. if (dm->rx_ant_status & BIT(i)) {
  1780. rx_cnt++; /* @check the number of the ant */
  1781. if (rx_cnt > dm->num_rf_path)
  1782. break;
  1783. /* Update per-path information
  1784. * (RSSI_dB RSSI_percentage EVM SNR CFO sq)
  1785. */
  1786. /* @EVM report is reported by stream, not path */
  1787. rx_path_pwr_db = phy_sts->pwdb[i] - 110; /*@dB*/
  1788. if (pktinfo->is_to_self)
  1789. dm->ofdm_agc_idx[i] = phy_sts->pwdb[i];
  1790. phydm_per_path_info_3rd(i, rx_path_pwr_db,
  1791. phy_sts->rxevm[rx_cnt - 1],
  1792. 0, phy_sts->rxsnr[i],
  1793. phy_info);
  1794. /* search maximum pwdb */
  1795. if (rx_path_pwr_db > rx_pwr_db_max)
  1796. rx_pwr_db_max = rx_path_pwr_db;
  1797. }
  1798. }
  1799. /* @mapping RX counter from 1~4 to 0~3 */
  1800. if (rx_cnt > 0)
  1801. phy_info->rx_count = rx_cnt - 1;
  1802. /* @count BF packet */
  1803. dm->phy_dbg_info.num_qry_bf_pkt = dm->phy_dbg_info.num_qry_bf_pkt +
  1804. phy_sts->beamformed;
  1805. /*STBC or LDPC pkt*/
  1806. dm->phy_dbg_info.is_ldpc_pkt = phy_sts->ldpc;
  1807. dm->phy_dbg_info.is_stbc_pkt = phy_sts->stbc;
  1808. /* @Check sub-channel */
  1809. if (pktinfo->data_rate > ODM_RATE11M &&
  1810. pktinfo->data_rate < ODM_RATEMCS0)
  1811. rxsc = phy_sts->l_rxsc; /*@Legacy*/
  1812. else
  1813. rxsc = phy_sts->ht_rxsc; /* @HT and VHT */
  1814. /* @Check RX bandwidth */
  1815. if (dm->support_ic_type & ODM_IC_JGR3_SERIES) {
  1816. if (rxsc >= 1 && rxsc <= 8)
  1817. bw = CHANNEL_WIDTH_20;
  1818. else if ((rxsc >= 9) && (rxsc <= 12))
  1819. bw = CHANNEL_WIDTH_40;
  1820. else if (rxsc >= 13)
  1821. bw = CHANNEL_WIDTH_80;
  1822. }
  1823. /* @Conditional number */
  1824. if (dm->support_ic_type & PHYSTS_3RD_TYPE_IC) {
  1825. dm->phy_dbg_info.condi_num = (u32)phy_sts->avg_cond_num_0;
  1826. }
  1827. /* Update packet information */
  1828. /* RX power choose the path with the maximum power */
  1829. phydm_common_phy_info_3rd(rx_pwr_db_max, phy_sts->channel_lsb,
  1830. (boolean)phy_sts->beamformed,
  1831. false, bw, 0, rxsc, phy_info);
  1832. }
  1833. void phydm_get_physts_jarguar3_5(struct dm_struct *dm, u8 *phy_status_inf,
  1834. struct phydm_perpkt_info_struct *pktinfo,
  1835. struct phydm_phyinfo_struct *phy_info)
  1836. {
  1837. /* type 5 is used for ofdm packet */
  1838. struct phy_status_rpt_jaguar3_type5 *phy_sts = NULL;
  1839. s8 rx_pwr_db_max = -120;
  1840. s8 rx_path_pwr_db;
  1841. u8 i, rxsc, bw = CHANNEL_WIDTH_20, rx_count = 0;
  1842. phy_sts = (struct phy_status_rpt_jaguar3_type5 *)phy_status_inf;
  1843. /* Update per-path information */
  1844. for (i = RF_PATH_A; i < PHYDM_MAX_RF_PATH; i++) {
  1845. if (dm->rx_ant_status & BIT(i)) {
  1846. rx_count++; /* @check the number of the ant */
  1847. if (rx_count > dm->num_rf_path)
  1848. break;
  1849. /* Update per-path information
  1850. * (RSSI_dB RSSI_percentage EVM SNR CFO sq)
  1851. */
  1852. /* @EVM report is reported by stream, not path */
  1853. rx_path_pwr_db = phy_sts->pwdb[i] - 110; /*@dB*/
  1854. if (pktinfo->is_to_self)
  1855. dm->ofdm_agc_idx[i] = phy_sts->pwdb[i];
  1856. phydm_per_path_info_3rd(i, rx_path_pwr_db,
  1857. 0, 0, 0, phy_info);
  1858. /* search maximum pwdb */
  1859. if (rx_path_pwr_db > rx_pwr_db_max)
  1860. rx_pwr_db_max = rx_path_pwr_db;
  1861. }
  1862. }
  1863. /* @mapping RX counter from 1~4 to 0~3 */
  1864. if (rx_count > 0)
  1865. phy_info->rx_count = rx_count - 1;
  1866. /* @count BF packet */
  1867. dm->phy_dbg_info.num_qry_bf_pkt = dm->phy_dbg_info.num_qry_bf_pkt +
  1868. phy_sts->beamformed;
  1869. /*STBC or LDPC pkt*/
  1870. dm->phy_dbg_info.is_ldpc_pkt = phy_sts->ldpc;
  1871. dm->phy_dbg_info.is_stbc_pkt = phy_sts->stbc;
  1872. /* @Check sub-channel */
  1873. if (pktinfo->data_rate > ODM_RATE11M &&
  1874. pktinfo->data_rate < ODM_RATEMCS0)
  1875. rxsc = phy_sts->l_rxsc; /*@Legacy*/
  1876. else
  1877. rxsc = phy_sts->ht_rxsc; /* @HT and VHT */
  1878. /* @Check RX bandwidth */
  1879. if (dm->support_ic_type & ODM_IC_JGR3_SERIES) {
  1880. if (rxsc >= 1 && rxsc <= 8)
  1881. bw = CHANNEL_WIDTH_20;
  1882. else if ((rxsc >= 9) && (rxsc <= 12))
  1883. bw = CHANNEL_WIDTH_40;
  1884. else if (rxsc >= 13)
  1885. bw = CHANNEL_WIDTH_80;
  1886. }
  1887. /* Update packet information */
  1888. /* RX power choose the path with the maximum power */
  1889. phydm_common_phy_info_3rd(rx_pwr_db_max, phy_sts->channel_lsb,
  1890. (boolean)phy_sts->beamformed,
  1891. false, bw, 0, rxsc, phy_info);
  1892. }
  1893. void phydm_process_dm_rssi_3rd_type(struct dm_struct *dm,
  1894. struct phydm_phyinfo_struct *phy_info,
  1895. struct phydm_perpkt_info_struct *pktinfo)
  1896. {
  1897. struct cmn_sta_info *sta = NULL;
  1898. struct rssi_info *rssi_t = NULL;
  1899. u8 rssi_tmp = 0;
  1900. u32 rssi_linear = 0;
  1901. s16 rssi_db = 0;
  1902. u8 i = 0;
  1903. /*@[Step4]*/
  1904. if (pktinfo->station_id >= ODM_ASSOCIATE_ENTRY_NUM)
  1905. return;
  1906. sta = dm->phydm_sta_info[pktinfo->station_id];
  1907. if (!is_sta_active(sta))
  1908. return;
  1909. if (!pktinfo->is_packet_match_bssid) /*@data frame only*/
  1910. return;
  1911. if (!(pktinfo->is_packet_to_self) && !(pktinfo->is_packet_beacon))
  1912. return;
  1913. if (pktinfo->is_packet_beacon) {
  1914. dm->phy_dbg_info.num_qry_beacon_pkt++;
  1915. dm->phy_dbg_info.beacon_phy_rate = pktinfo->data_rate;
  1916. }
  1917. rssi_t = &sta->rssi_stat;
  1918. if (pktinfo->is_cck_rate) {
  1919. rssi_db = phy_info->rx_mimo_signal_strength[0]; /*Path-A*/
  1920. if (rssi_t->rssi_acc == 0) {
  1921. rssi_t->rssi_acc = (s16)(rssi_db << RSSI_MA);
  1922. rssi_t->rssi = (s8)(rssi_db);
  1923. } else {
  1924. rssi_t->rssi_acc = MA_ACC(rssi_t->rssi_acc,
  1925. rssi_db, RSSI_MA);
  1926. rssi_t->rssi = (s8)GET_MA_VAL(rssi_t->rssi_acc,
  1927. RSSI_MA);
  1928. }
  1929. rssi_t->rssi_cck = (s8)rssi_db;
  1930. } else {
  1931. for (i = RF_PATH_A; i < PHYDM_MAX_RF_PATH; i++) {
  1932. rssi_tmp = phy_info->rx_mimo_signal_strength[i];
  1933. if (rssi_tmp != 0)
  1934. rssi_linear += phydm_db_2_linear(rssi_tmp);
  1935. }
  1936. switch (phy_info->rx_count + 1) {
  1937. case 2:
  1938. rssi_linear = DIVIDED_2(rssi_linear);
  1939. break;
  1940. case 3:
  1941. rssi_linear = DIVIDED_3(rssi_linear);
  1942. break;
  1943. case 4:
  1944. rssi_linear = DIVIDED_4(rssi_linear);
  1945. break;
  1946. }
  1947. rssi_db = (s16)odm_convert_to_db(rssi_linear);
  1948. if (rssi_t->rssi_acc == 0) {
  1949. rssi_t->rssi_acc = (s16)(rssi_db << RSSI_MA);
  1950. rssi_t->rssi = (s8)(rssi_db);
  1951. } else {
  1952. rssi_t->rssi_acc = MA_ACC(rssi_t->rssi_acc,
  1953. rssi_db, RSSI_MA);
  1954. rssi_t->rssi = (s8)GET_MA_VAL(rssi_t->rssi_acc,
  1955. RSSI_MA);
  1956. }
  1957. rssi_t->rssi_ofdm = (s8)rssi_db;
  1958. }
  1959. }
  1960. void phydm_rx_physts_3rd_type(void *dm_void, u8 *phy_sts,
  1961. struct phydm_perpkt_info_struct *pktinfo,
  1962. struct phydm_phyinfo_struct *phy_info)
  1963. {
  1964. struct dm_struct *dm = (struct dm_struct *)dm_void;
  1965. #ifdef PHYDM_PHYSTAUS_SMP_MODE
  1966. struct pkt_process_info *pkt_process = &dm->pkt_proc_struct;
  1967. #endif
  1968. u8 phy_status_type = (*phy_sts & 0xf);
  1969. #ifdef PHYDM_PHYSTAUS_SMP_MODE
  1970. if (pkt_process->phystatus_smp_mode_en && phy_status_type != 0) {
  1971. if (pkt_process->pre_ppdu_cnt == pktinfo->ppdu_cnt)
  1972. return;
  1973. pkt_process->pre_ppdu_cnt = pktinfo->ppdu_cnt;
  1974. }
  1975. #endif
  1976. /*@[Step 2]*/
  1977. phydm_reset_phy_info_3rd(dm, phy_info); /* @Memory reset */
  1978. /* Phy status parsing */
  1979. switch (phy_status_type) {
  1980. case 0: /*@CCK*/
  1981. phydm_get_physts_jarguar3_0(dm, phy_sts, pktinfo, phy_info);
  1982. break;
  1983. case 1:
  1984. phydm_get_physts_jarguar3_1(dm, phy_sts, pktinfo, phy_info);
  1985. break;
  1986. case 2:
  1987. case 3:
  1988. phydm_get_physts_jarguar3_2_3(dm, phy_sts, pktinfo, phy_info);
  1989. break;
  1990. case 4:
  1991. phydm_get_physts_jarguar3_4(dm, phy_sts, pktinfo, phy_info);
  1992. break;
  1993. case 5:
  1994. phydm_get_physts_jarguar3_5(dm, phy_sts, pktinfo, phy_info);
  1995. break;
  1996. default:
  1997. break;
  1998. }
  1999. /*@[Step 1]*/
  2000. #ifdef PHYDM_IC_JGR3_SERIES_SUPPORT
  2001. if (dm->support_ic_type & ODM_IC_JGR3_SERIES)
  2002. phydm_print_phystat_jaguar3(dm, phy_sts, pktinfo, phy_info);
  2003. #endif
  2004. }
  2005. #endif
  2006. #if (ODM_PHY_STATUS_NEW_TYPE_SUPPORT)
  2007. /* @For 8822B only!! need to move to FW finally */
  2008. /*@==============================================*/
  2009. boolean
  2010. phydm_query_is_mu_api(struct dm_struct *phydm, u8 ppdu_idx, u8 *p_data_rate,
  2011. u8 *p_gid)
  2012. {
  2013. u8 data_rate = 0, gid = 0;
  2014. boolean is_mu = false;
  2015. data_rate = phydm->phy_dbg_info.num_of_ppdu[ppdu_idx];
  2016. gid = phydm->phy_dbg_info.gid_num[ppdu_idx];
  2017. if (data_rate & BIT(7)) {
  2018. is_mu = true;
  2019. data_rate = data_rate & ~(BIT(7));
  2020. } else {
  2021. is_mu = false;
  2022. }
  2023. *p_data_rate = data_rate;
  2024. *p_gid = gid;
  2025. return is_mu;
  2026. }
  2027. void phydm_reset_phy_info(struct dm_struct *phydm,
  2028. struct phydm_phyinfo_struct *phy_info)
  2029. {
  2030. phy_info->rx_pwdb_all = 0;
  2031. phy_info->signal_quality = 0;
  2032. phy_info->band_width = 0;
  2033. phy_info->rx_count = 0;
  2034. odm_memory_set(phydm, phy_info->rx_mimo_signal_quality, 0, 4);
  2035. odm_memory_set(phydm, phy_info->rx_mimo_signal_strength, 0, 4);
  2036. odm_memory_set(phydm, phy_info->rx_snr, 0, 4);
  2037. phy_info->rx_power = -110;
  2038. phy_info->recv_signal_power = -110;
  2039. phy_info->bt_rx_rssi_percentage = 0;
  2040. phy_info->signal_strength = 0;
  2041. phy_info->channel = 0;
  2042. phy_info->is_mu_packet = 0;
  2043. phy_info->is_beamformed = 0;
  2044. phy_info->rxsc = 0;
  2045. odm_memory_set(phydm, phy_info->rx_pwr, -110, 4);
  2046. odm_memory_set(phydm, phy_info->cfo_short, 0, 8);
  2047. odm_memory_set(phydm, phy_info->cfo_tail, 0, 8);
  2048. odm_memory_set(phydm, phy_info->rx_mimo_evm_dbm, 0, 4);
  2049. }
  2050. void phydm_print_phy_sts_jgr2(struct dm_struct *dm, u8 *phy_status_inf,
  2051. struct phydm_perpkt_info_struct *pktinfo,
  2052. struct phydm_phyinfo_struct *phy_info)
  2053. {
  2054. struct phy_status_rpt_jaguar2_type0 *rpt0 = NULL;
  2055. struct phy_status_rpt_jaguar2_type1 *rpt = NULL;
  2056. struct phy_status_rpt_jaguar2_type2 *rpt2 = NULL;
  2057. struct odm_phy_dbg_info *dbg = &dm->phy_dbg_info;
  2058. u8 phy_status_page_num = (*phy_status_inf & 0xf);
  2059. u32 phy_status[PHY_STATUS_JRGUAR2_DW_LEN] = {0};
  2060. u8 i;
  2061. u32 size = PHY_STATUS_JRGUAR2_DW_LEN << 2;
  2062. rpt0 = (struct phy_status_rpt_jaguar2_type0 *)phy_status_inf;
  2063. rpt = (struct phy_status_rpt_jaguar2_type1 *)phy_status_inf;
  2064. rpt2 = (struct phy_status_rpt_jaguar2_type2 *)phy_status_inf;
  2065. odm_move_memory(dm, phy_status, phy_status_inf, size);
  2066. if (!(dm->debug_components & DBG_PHY_STATUS))
  2067. return;
  2068. if (dbg->show_phy_sts_all_pkt == 0) {
  2069. if (!pktinfo->is_packet_match_bssid)
  2070. return;
  2071. }
  2072. dbg->show_phy_sts_cnt++;
  2073. #if 0
  2074. dbg_print("cnt=%d, max=%d\n",
  2075. dbg->show_phy_sts_cnt, dbg->show_phy_sts_max_cnt);
  2076. #endif
  2077. if (dbg->show_phy_sts_max_cnt != SHOW_PHY_STATUS_UNLIMITED) {
  2078. if (dbg->show_phy_sts_cnt > dbg->show_phy_sts_max_cnt)
  2079. return;
  2080. }
  2081. pr_debug("Phy Status Rpt: OFDM_%d\n", phy_status_page_num);
  2082. pr_debug("StaID=%d, RxRate = 0x%x match_bssid=%d\n",
  2083. pktinfo->station_id, pktinfo->data_rate,
  2084. pktinfo->is_packet_match_bssid);
  2085. for (i = 0; i < PHY_STATUS_JRGUAR2_DW_LEN; i++)
  2086. pr_debug("Offset[%d:%d] = 0x%x\n",
  2087. ((4 * i) + 3), (4 * i), phy_status[i]);
  2088. if (phy_status_page_num == 0) {
  2089. pr_debug("[0] TRSW=%d, MP_gain_idx=%d, pwdb=%d\n",
  2090. rpt0->trsw, rpt0->gain, rpt0->pwdb);
  2091. pr_debug("[4] band=%d, CH=%d, agc_table = %d, rxsc = %d\n",
  2092. rpt0->band, rpt0->channel,
  2093. rpt0->agc_table, rpt0->rxsc);
  2094. pr_debug("[8] AntIdx[D:A]={%d, %d, %d, %d}, LSIG_len=%d\n",
  2095. rpt0->antidx_d, rpt0->antidx_c, rpt0->antidx_b,
  2096. rpt0->antidx_a, rpt0->length);
  2097. pr_debug("[12] lna_h=%d, bb_pwr=%d, lna_l=%d, vga=%d, sq=%d\n",
  2098. rpt0->lna_h, rpt0->bb_power, rpt0->lna_l,
  2099. rpt0->vga, rpt0->signal_quality);
  2100. } else if (phy_status_page_num == 1) {
  2101. pr_debug("[0] pwdb[D:A]={%d, %d, %d, %d}\n",
  2102. rpt->pwdb[3], rpt->pwdb[2],
  2103. rpt->pwdb[1], rpt->pwdb[0]);
  2104. pr_debug("[4] BF: %d, ldpc=%d, stbc=%d, g_bt=%d, antsw=%d, band=%d, CH=%d, rxsc[ht, l]={%d, %d}\n",
  2105. rpt->beamformed, rpt->ldpc, rpt->stbc, rpt->gnt_bt,
  2106. rpt->hw_antsw_occu, rpt->band, rpt->channel,
  2107. rpt->ht_rxsc, rpt->l_rxsc);
  2108. pr_debug("[8] AntIdx[D:A]={%d, %d, %d, %d}, LSIG_len=%d\n",
  2109. rpt->antidx_d, rpt->antidx_c, rpt->antidx_b,
  2110. rpt->antidx_a, rpt->lsig_length);
  2111. pr_debug("[12] rf_mode=%d, NBI=%d, Intf_pos=%d, GID=%d, PAID=%d\n",
  2112. rpt->rf_mode, rpt->nb_intf_flag,
  2113. (rpt->intf_pos + (rpt->intf_pos_msb << 8)), rpt->gid,
  2114. (rpt->paid + (rpt->paid_msb << 8)));
  2115. pr_debug("[16] EVM[D:A]={%d, %d, %d, %d}\n",
  2116. rpt->rxevm[3], rpt->rxevm[2],
  2117. rpt->rxevm[1], rpt->rxevm[0]);
  2118. pr_debug("[20] CFO[D:A]={%d, %d, %d, %d}\n",
  2119. rpt->cfo_tail[3], rpt->cfo_tail[2], rpt->cfo_tail[1],
  2120. rpt->cfo_tail[0]);
  2121. pr_debug("[24] SNR[D:A]={%d, %d, %d, %d}\n\n",
  2122. rpt->rxsnr[3], rpt->rxsnr[2], rpt->rxsnr[1],
  2123. rpt->rxsnr[0]);
  2124. } else if (phy_status_page_num == 2) {
  2125. pr_debug("[0] pwdb[D:A]={%d, %d, %d, %d}\n",
  2126. rpt2->pwdb[3], rpt2->pwdb[2], rpt2->pwdb[1],
  2127. rpt2->pwdb[0]);
  2128. pr_debug("[4] BF: %d, ldpc=%d, stbc=%d, g_bt=%d, antsw=%d, band=%d, CH=%d, rxsc[ht,l]={%d, %d}\n",
  2129. rpt2->beamformed, rpt2->ldpc, rpt2->stbc, rpt2->gnt_bt,
  2130. rpt2->hw_antsw_occu, rpt2->band, rpt2->channel,
  2131. rpt2->ht_rxsc, rpt2->l_rxsc);
  2132. pr_debug("[8] AgcTab[D:A]={%d, %d, %d, %d}, cnt_pw2cca=%d, shift_l_map=%d\n",
  2133. rpt2->agc_table_d, rpt2->agc_table_c,
  2134. rpt2->agc_table_b, rpt2->agc_table_a,
  2135. rpt2->cnt_pw2cca, rpt2->shift_l_map);
  2136. pr_debug("[12] (TRSW|Gain)[D:A]={%d %d, %d %d, %d %d, %d %d}, cnt_cca2agc_rdy=%d\n",
  2137. rpt2->trsw_d, rpt2->gain_d, rpt2->trsw_c, rpt2->gain_c,
  2138. rpt2->trsw_b, rpt2->gain_b, rpt2->trsw_a,
  2139. rpt2->gain_a, rpt2->cnt_cca2agc_rdy);
  2140. pr_debug("[16] AAGC step[D:A]={%d, %d, %d, %d} HT AAGC gain[D:A]={%d, %d, %d, %d}\n",
  2141. rpt2->aagc_step_d, rpt2->aagc_step_c,
  2142. rpt2->aagc_step_b, rpt2->aagc_step_a,
  2143. rpt2->ht_aagc_gain[3], rpt2->ht_aagc_gain[2],
  2144. rpt2->ht_aagc_gain[1], rpt2->ht_aagc_gain[0]);
  2145. pr_debug("[20] DAGC gain[D:A]={%d, %d, %d, %d}\n",
  2146. rpt2->dagc_gain[3],
  2147. rpt2->dagc_gain[2], rpt2->dagc_gain[1],
  2148. rpt2->dagc_gain[0]);
  2149. pr_debug("[24] syn_cnt: %d, Cnt=%d\n\n",
  2150. rpt2->syn_count, rpt2->counter);
  2151. }
  2152. }
  2153. void phydm_set_per_path_phy_info(u8 rx_path, s8 pwr, s8 rx_evm, s8 cfo_tail,
  2154. s8 rx_snr,
  2155. struct phydm_phyinfo_struct *phy_info)
  2156. {
  2157. u8 evm_dbm = 0;
  2158. u8 evm_percentage = 0;
  2159. /* SNR is S(8,1), EVM is S(8,1), CFO is S(8,7) */
  2160. if (rx_evm < 0) {
  2161. /* @Calculate EVM in dBm */
  2162. evm_dbm = ((u8)(0 - rx_evm) >> 1);
  2163. if (evm_dbm == 64)
  2164. evm_dbm = 0; /*@if 1SS rate, evm_dbm [2nd stream] =64*/
  2165. if (evm_dbm != 0) {
  2166. /* @Convert EVM to 0%~100% percentage */
  2167. if (evm_dbm >= 34)
  2168. evm_percentage = 100;
  2169. else
  2170. evm_percentage = (evm_dbm << 1) + (evm_dbm);
  2171. }
  2172. }
  2173. phy_info->rx_pwr[rx_path] = pwr;
  2174. /*@CFO(kHz) = CFO_tail * 312.5(kHz) / 2^7 ~= CFO tail * 5/2 (kHz)*/
  2175. phy_info->cfo_tail[rx_path] = (cfo_tail * 5) >> 1;
  2176. phy_info->rx_mimo_evm_dbm[rx_path] = evm_dbm;
  2177. phy_info->rx_mimo_signal_strength[rx_path] = phydm_pwr_2_percent(pwr);
  2178. phy_info->rx_mimo_signal_quality[rx_path] = evm_percentage;
  2179. phy_info->rx_snr[rx_path] = rx_snr >> 1;
  2180. #if 0
  2181. if (!pktinfo->is_packet_match_bssid)
  2182. return;
  2183. dbg_print("path (%d)--------\n", rx_path);
  2184. dbg_print("rx_pwr = %d, Signal strength = %d\n",
  2185. phy_info->rx_pwr[rx_path],
  2186. phy_info->rx_mimo_signal_strength[rx_path]);
  2187. dbg_print("evm_dbm = %d, Signal quality = %d\n",
  2188. phy_info->rx_mimo_evm_dbm[rx_path],
  2189. phy_info->rx_mimo_signal_quality[rx_path]);
  2190. dbg_print("CFO = %d, SNR = %d\n",
  2191. phy_info->cfo_tail[rx_path], phy_info->rx_snr[rx_path]);
  2192. #endif
  2193. }
  2194. void phydm_set_common_phy_info(s8 rx_power, u8 channel, boolean is_beamformed,
  2195. boolean is_mu_packet, u8 bandwidth,
  2196. u8 signal_quality, u8 rxsc,
  2197. struct phydm_phyinfo_struct *phy_info)
  2198. {
  2199. phy_info->rx_power = rx_power; /* RSSI in dB */
  2200. phy_info->recv_signal_power = rx_power; /* RSSI in dB */
  2201. phy_info->channel = channel; /* @channel number */
  2202. phy_info->is_beamformed = is_beamformed; /* @apply BF */
  2203. phy_info->is_mu_packet = is_mu_packet; /* @MU packet */
  2204. phy_info->rxsc = rxsc;
  2205. /* RSSI in percentage */
  2206. phy_info->rx_pwdb_all = phydm_pwr_2_percent(rx_power);
  2207. phy_info->signal_quality = signal_quality; /* signal quality */
  2208. phy_info->band_width = bandwidth; /* @bandwidth */
  2209. #if 0
  2210. if (!pktinfo->is_packet_match_bssid)
  2211. return;
  2212. dbg_print("rx_pwdb_all = %d, rx_power = %d, recv_signal_power = %d\n",
  2213. phy_info->rx_pwdb_all, phy_info->rx_power,
  2214. phy_info->recv_signal_power);
  2215. dbg_print("signal_quality = %d\n", phy_info->signal_quality);
  2216. dbg_print("is_beamformed = %d, is_mu_packet = %d, rx_count = %d\n",
  2217. phy_info->is_beamformed, phy_info->is_mu_packet,
  2218. phy_info->rx_count + 1);
  2219. dbg_print("channel = %d, rxsc = %d, band_width = %d\n", channel,
  2220. rxsc, bandwidth);
  2221. #endif
  2222. }
  2223. void phydm_get_phy_sts_type0(struct dm_struct *dm, u8 *phy_status_inf,
  2224. struct phydm_perpkt_info_struct *pktinfo,
  2225. struct phydm_phyinfo_struct *phy_info)
  2226. {
  2227. /* type 0 is used for cck packet */
  2228. struct phy_status_rpt_jaguar2_type0 *phy_sts = NULL;
  2229. u8 sq = 0;
  2230. s8 rx_pow = 0;
  2231. u8 lna_idx = 0, vga_idx = 0;
  2232. phy_sts = (struct phy_status_rpt_jaguar2_type0 *)phy_status_inf;
  2233. rx_pow = phy_sts->pwdb - 110;
  2234. if (dm->support_ic_type & ODM_RTL8723D) {
  2235. #if (RTL8723D_SUPPORT)
  2236. rx_pow = phy_sts->pwdb - 97;
  2237. #endif
  2238. }
  2239. #if (RTL8821C_SUPPORT)
  2240. else if (dm->support_ic_type & ODM_RTL8821C) {
  2241. if (phy_sts->pwdb >= -57)
  2242. rx_pow = phy_sts->pwdb - 100;
  2243. else
  2244. rx_pow = phy_sts->pwdb - 102;
  2245. }
  2246. #endif
  2247. if (pktinfo->is_to_self) {
  2248. dm->ofdm_agc_idx[0] = phy_sts->pwdb;
  2249. dm->ofdm_agc_idx[1] = 0;
  2250. dm->ofdm_agc_idx[2] = 0;
  2251. dm->ofdm_agc_idx[3] = 0;
  2252. }
  2253. /* @Calculate Signal Quality*/
  2254. if (phy_sts->signal_quality >= 64) {
  2255. sq = 0;
  2256. } else if (phy_sts->signal_quality <= 20) {
  2257. sq = 100;
  2258. } else {
  2259. /* @mapping to 2~99% */
  2260. sq = 64 - phy_sts->signal_quality;
  2261. sq = ((sq << 3) + sq) >> 2;
  2262. }
  2263. /* @Get RSSI for old CCK AGC */
  2264. if (!dm->cck_new_agc) {
  2265. vga_idx = phy_sts->vga;
  2266. if (dm->support_ic_type & ODM_RTL8197F) {
  2267. /*@3bit LNA*/
  2268. lna_idx = phy_sts->lna_l;
  2269. } else {
  2270. /*@4bit LNA*/
  2271. lna_idx = (phy_sts->lna_h << 3) | phy_sts->lna_l;
  2272. }
  2273. rx_pow = phydm_get_cck_rssi(dm, lna_idx, vga_idx);
  2274. }
  2275. /* @Confirm CCK RSSI */
  2276. #if (RTL8197F_SUPPORT)
  2277. if (dm->support_ic_type & ODM_RTL8197F) {
  2278. u8 bb_pwr_th_l = 5; /* round( 31*0.15 ) */
  2279. u8 bb_pwr_th_h = 27; /* round( 31*0.85 ) */
  2280. if (phy_sts->bb_power < bb_pwr_th_l ||
  2281. phy_sts->bb_power > bb_pwr_th_h)
  2282. rx_pow = 0; /* @Error RSSI for CCK ; set 100*/
  2283. }
  2284. #endif
  2285. /*@CCK no STBC and LDPC*/
  2286. dm->phy_dbg_info.is_ldpc_pkt = false;
  2287. dm->phy_dbg_info.is_stbc_pkt = false;
  2288. /* Update Common information */
  2289. phydm_set_common_phy_info(rx_pow, phy_sts->channel, false,
  2290. false, CHANNEL_WIDTH_20, sq,
  2291. phy_sts->rxsc, phy_info);
  2292. /* Update CCK pwdb */
  2293. phydm_set_per_path_phy_info(RF_PATH_A, rx_pow, 0, 0, 0, phy_info);
  2294. #ifdef CONFIG_PHYDM_ANTENNA_DIVERSITY
  2295. dm->dm_fat_table.antsel_rx_keep_0 = phy_sts->antidx_a;
  2296. dm->dm_fat_table.antsel_rx_keep_1 = phy_sts->antidx_b;
  2297. dm->dm_fat_table.antsel_rx_keep_2 = phy_sts->antidx_c;
  2298. dm->dm_fat_table.antsel_rx_keep_3 = phy_sts->antidx_d;
  2299. #endif
  2300. }
  2301. void phydm_get_phy_sts_type1(struct dm_struct *dm, u8 *phy_status_inf,
  2302. struct phydm_perpkt_info_struct *pktinfo,
  2303. struct phydm_phyinfo_struct *phy_info)
  2304. {
  2305. /* type 1 is used for ofdm packet */
  2306. struct phy_status_rpt_jaguar2_type1 *phy_sts = NULL;
  2307. struct odm_phy_dbg_info *dbg_i = &dm->phy_dbg_info;
  2308. s8 rx_pwr_db = -120;
  2309. s8 rx_pwr = 0;
  2310. u8 i, rxsc, bw = CHANNEL_WIDTH_20, rx_count = 0;
  2311. boolean is_mu;
  2312. phy_sts = (struct phy_status_rpt_jaguar2_type1 *)phy_status_inf;
  2313. /* Update per-path information */
  2314. for (i = RF_PATH_A; i < PHYDM_MAX_RF_PATH; i++) {
  2315. if (!(dm->rx_ant_status & BIT(i)))
  2316. continue;
  2317. rx_count++;
  2318. if (rx_count > dm->num_rf_path)
  2319. break;
  2320. /* Update per-path information
  2321. * (RSSI_dB RSSI_percentage EVM SNR CFO sq)
  2322. */
  2323. /* @EVM report is reported by stream, not path */
  2324. rx_pwr = phy_sts->pwdb[i] - 110; /* per-path pwdb(dB)*/
  2325. if (pktinfo->is_to_self)
  2326. dm->ofdm_agc_idx[i] = phy_sts->pwdb[i];
  2327. phydm_set_per_path_phy_info(i, rx_pwr,
  2328. phy_sts->rxevm[rx_count - 1],
  2329. phy_sts->cfo_tail[i],
  2330. phy_sts->rxsnr[i], phy_info);
  2331. /* search maximum pwdb */
  2332. if (rx_pwr > rx_pwr_db)
  2333. rx_pwr_db = rx_pwr;
  2334. }
  2335. /* @mapping RX counter from 1~4 to 0~3 */
  2336. if (rx_count > 0)
  2337. phy_info->rx_count = rx_count - 1;
  2338. /* @Check if MU packet or not */
  2339. if (phy_sts->gid != 0 && phy_sts->gid != 63) {
  2340. is_mu = true;
  2341. dbg_i->num_qry_mu_pkt++;
  2342. } else {
  2343. is_mu = false;
  2344. }
  2345. /* @count BF packet */
  2346. dbg_i->num_qry_bf_pkt = dbg_i->num_qry_bf_pkt + phy_sts->beamformed;
  2347. /*STBC or LDPC pkt*/
  2348. dbg_i->is_ldpc_pkt = phy_sts->ldpc;
  2349. dbg_i->is_stbc_pkt = phy_sts->stbc;
  2350. /* @Check sub-channel */
  2351. if (pktinfo->data_rate > ODM_RATE11M &&
  2352. pktinfo->data_rate < ODM_RATEMCS0)
  2353. rxsc = phy_sts->l_rxsc;
  2354. else
  2355. rxsc = phy_sts->ht_rxsc;
  2356. /* @Check RX bandwidth */
  2357. if (dm->support_ic_type & ODM_IC_11AC_SERIES) {
  2358. if (rxsc >= 1 && rxsc <= 8)
  2359. bw = CHANNEL_WIDTH_20;
  2360. else if ((rxsc >= 9) && (rxsc <= 12))
  2361. bw = CHANNEL_WIDTH_40;
  2362. else if (rxsc >= 13)
  2363. bw = CHANNEL_WIDTH_80;
  2364. else
  2365. bw = phy_sts->rf_mode;
  2366. } else if (dm->support_ic_type & ODM_IC_11N_SERIES) {
  2367. if (phy_sts->rf_mode == 0)
  2368. bw = CHANNEL_WIDTH_20;
  2369. else if ((rxsc == 1) || (rxsc == 2))
  2370. bw = CHANNEL_WIDTH_20;
  2371. else
  2372. bw = CHANNEL_WIDTH_40;
  2373. }
  2374. /* Update packet information */
  2375. phydm_set_common_phy_info(rx_pwr_db, phy_sts->channel,
  2376. (boolean)phy_sts->beamformed, is_mu, bw,
  2377. phy_info->rx_mimo_signal_quality[0],
  2378. rxsc, phy_info);
  2379. phydm_parsing_cfo(dm, pktinfo, phy_sts->cfo_tail, pktinfo->rate_ss);
  2380. #ifdef PHYDM_LNA_SAT_CHK_TYPE2
  2381. phydm_parsing_snr(dm, pktinfo, phy_sts->rxsnr);
  2382. #endif
  2383. #if (defined(CONFIG_PHYDM_ANTENNA_DIVERSITY))
  2384. dm->dm_fat_table.antsel_rx_keep_0 = phy_sts->antidx_a;
  2385. dm->dm_fat_table.antsel_rx_keep_1 = phy_sts->antidx_b;
  2386. dm->dm_fat_table.antsel_rx_keep_2 = phy_sts->antidx_c;
  2387. dm->dm_fat_table.antsel_rx_keep_3 = phy_sts->antidx_d;
  2388. #endif
  2389. }
  2390. void phydm_get_phy_sts_type2(struct dm_struct *dm, u8 *phy_status_inf,
  2391. struct phydm_perpkt_info_struct *pktinfo,
  2392. struct phydm_phyinfo_struct *phy_info)
  2393. {
  2394. struct phy_status_rpt_jaguar2_type2 *phy_sts = NULL;
  2395. s8 rx_pwr_db_max = -120;
  2396. s8 rx_pwr = 0;
  2397. u8 i, rxsc, bw = CHANNEL_WIDTH_20, rx_count = 0;
  2398. phy_sts = (struct phy_status_rpt_jaguar2_type2 *)phy_status_inf;
  2399. for (i = RF_PATH_A; i < PHYDM_MAX_RF_PATH; i++) {
  2400. if (!(dm->rx_ant_status & BIT(i)))
  2401. continue;
  2402. rx_count++;
  2403. if (rx_count > dm->num_rf_path)
  2404. break;
  2405. /* Update per-path information*/
  2406. /* RSSI_dB, RSSI_percentage, EVM, SNR, CFO, sq */
  2407. #if (RTL8197F_SUPPORT)
  2408. if ((dm->support_ic_type & ODM_RTL8197F) &&
  2409. phy_sts->pwdb[i] == 0x7f) { /*@97f workaround*/
  2410. if (i == RF_PATH_A) {
  2411. rx_pwr = (phy_sts->gain_a) << 1;
  2412. rx_pwr = rx_pwr - 110;
  2413. } else if (i == RF_PATH_B) {
  2414. rx_pwr = (phy_sts->gain_b) << 1;
  2415. rx_pwr = rx_pwr - 110;
  2416. } else {
  2417. rx_pwr = 0;
  2418. }
  2419. } else
  2420. #endif
  2421. rx_pwr = phy_sts->pwdb[i] - 110; /*@dBm*/
  2422. phydm_set_per_path_phy_info(i, rx_pwr, 0, 0, 0, phy_info);
  2423. if (rx_pwr > rx_pwr_db_max) /* search max pwdb */
  2424. rx_pwr_db_max = rx_pwr;
  2425. }
  2426. /* @mapping RX counter from 1~4 to 0~3 */
  2427. if (rx_count > 0)
  2428. phy_info->rx_count = rx_count - 1;
  2429. /* @Check RX sub-channel */
  2430. if (pktinfo->data_rate > ODM_RATE11M &&
  2431. pktinfo->data_rate < ODM_RATEMCS0)
  2432. rxsc = phy_sts->l_rxsc;
  2433. else
  2434. rxsc = phy_sts->ht_rxsc;
  2435. /*STBC or LDPC pkt*/
  2436. dm->phy_dbg_info.is_ldpc_pkt = phy_sts->ldpc;
  2437. dm->phy_dbg_info.is_stbc_pkt = phy_sts->stbc;
  2438. /* @Check RX bandwidth */
  2439. /* @BW information of sc=0 is useless,
  2440. *because there is no information of RF mode
  2441. */
  2442. if (dm->support_ic_type & ODM_IC_11AC_SERIES) {
  2443. if (rxsc >= 1 && rxsc <= 8)
  2444. bw = CHANNEL_WIDTH_20;
  2445. else if ((rxsc >= 9) && (rxsc <= 12))
  2446. bw = CHANNEL_WIDTH_40;
  2447. else if (rxsc >= 13)
  2448. bw = CHANNEL_WIDTH_80;
  2449. } else if (dm->support_ic_type & ODM_IC_11N_SERIES) {
  2450. if (rxsc == 3)
  2451. bw = CHANNEL_WIDTH_40;
  2452. else if ((rxsc == 1) || (rxsc == 2))
  2453. bw = CHANNEL_WIDTH_20;
  2454. }
  2455. /* Update packet information */
  2456. phydm_set_common_phy_info(rx_pwr_db_max, phy_sts->channel,
  2457. (boolean)phy_sts->beamformed,
  2458. false, bw, 0, rxsc, phy_info);
  2459. }
  2460. void phydm_process_rssi_for_dm_2nd_type(struct dm_struct *dm,
  2461. struct phydm_phyinfo_struct *phy_info,
  2462. struct phydm_perpkt_info_struct *pktinfo
  2463. )
  2464. {
  2465. struct cmn_sta_info *sta = NULL;
  2466. struct rssi_info *rssi_t = NULL;
  2467. u8 rssi_tmp = 0;
  2468. u32 rssi_linear = 0;
  2469. s16 rssi_db = 0;
  2470. u8 i = 0;
  2471. if (pktinfo->station_id >= ODM_ASSOCIATE_ENTRY_NUM)
  2472. return;
  2473. sta = dm->phydm_sta_info[pktinfo->station_id];
  2474. if (!is_sta_active(sta))
  2475. return;
  2476. if (!pktinfo->is_packet_match_bssid) /*@data frame only*/
  2477. return;
  2478. #if (defined(CONFIG_PHYDM_ANTENNA_DIVERSITY))
  2479. if (dm->support_ability & ODM_BB_ANT_DIV)
  2480. odm_process_rssi_for_ant_div(dm, phy_info, pktinfo);
  2481. #endif
  2482. #ifdef CONFIG_ADAPTIVE_SOML
  2483. phydm_rx_qam_for_soml(dm, pktinfo);
  2484. phydm_rx_rate_for_soml(dm, pktinfo);
  2485. #endif
  2486. if (!(pktinfo->is_packet_to_self) && !(pktinfo->is_packet_beacon))
  2487. return;
  2488. if (pktinfo->is_packet_beacon) {
  2489. dm->phy_dbg_info.num_qry_beacon_pkt++;
  2490. dm->phy_dbg_info.beacon_phy_rate = pktinfo->data_rate;
  2491. }
  2492. rssi_t = &sta->rssi_stat;
  2493. for (i = RF_PATH_A; i < PHYDM_MAX_RF_PATH; i++) {
  2494. rssi_tmp = phy_info->rx_mimo_signal_strength[i];
  2495. if (rssi_tmp != 0)
  2496. rssi_linear += phydm_db_2_linear(rssi_tmp);
  2497. }
  2498. switch (phy_info->rx_count + 1) {
  2499. case 2:
  2500. rssi_linear = DIVIDED_2(rssi_linear);
  2501. break;
  2502. case 3:
  2503. rssi_linear = DIVIDED_3(rssi_linear);
  2504. break;
  2505. case 4:
  2506. rssi_linear = DIVIDED_4(rssi_linear);
  2507. break;
  2508. }
  2509. rssi_db = (s16)odm_convert_to_db(rssi_linear);
  2510. if (rssi_t->rssi_acc == 0) {
  2511. rssi_t->rssi_acc = (s16)(rssi_db << RSSI_MA);
  2512. rssi_t->rssi = (s8)(rssi_db);
  2513. } else {
  2514. rssi_t->rssi_acc = MA_ACC(rssi_t->rssi_acc, rssi_db, RSSI_MA);
  2515. rssi_t->rssi = (s8)GET_MA_VAL(rssi_t->rssi_acc, RSSI_MA);
  2516. }
  2517. #if 0
  2518. PHYDM_DBG(dm, DBG_TMP, "RSSI[%d]{A,B,C,D}={%d, %d, %d, %d} AVG=%d\n",
  2519. pktinfo->station_id,
  2520. phy_info->rx_mimo_signal_strength[0],
  2521. phy_info->rx_mimo_signal_strength[1],
  2522. phy_info->rx_mimo_signal_strength[2],
  2523. phy_info->rx_mimo_signal_strength[3], rssi_db);
  2524. PHYDM_DBG(dm, DBG_TMP, "rssi_acc = %d, rssi=%d\n",
  2525. rssi_t->rssi_acc, rssi_t->rssi);
  2526. #endif
  2527. if (pktinfo->is_cck_rate)
  2528. rssi_t->rssi_cck = (s8)rssi_db;
  2529. else
  2530. rssi_t->rssi_ofdm = (s8)rssi_db;
  2531. }
  2532. void phydm_rx_physts_2nd_type(void *dm_void, u8 *phy_sts,
  2533. struct phydm_perpkt_info_struct *pktinfo,
  2534. struct phydm_phyinfo_struct *phy_info)
  2535. {
  2536. struct dm_struct *dm = (struct dm_struct *)dm_void;
  2537. #ifdef PHYDM_PHYSTAUS_SMP_MODE
  2538. struct pkt_process_info *pkt_process = &dm->pkt_proc_struct;
  2539. #endif
  2540. u8 page = (*phy_sts & 0xf);
  2541. #ifdef PHYDM_PHYSTAUS_SMP_MODE
  2542. if (pkt_process->phystatus_smp_mode_en && page != 0) {
  2543. if (pkt_process->pre_ppdu_cnt == pktinfo->ppdu_cnt)
  2544. return;
  2545. pkt_process->pre_ppdu_cnt = pktinfo->ppdu_cnt;
  2546. }
  2547. #endif
  2548. phydm_reset_phy_info(dm, phy_info); /* @Memory reset */
  2549. /* Phy status parsing */
  2550. switch (page) {
  2551. case 0: /*@CCK*/
  2552. phydm_get_phy_sts_type0(dm, phy_sts, pktinfo, phy_info);
  2553. break;
  2554. case 1:
  2555. phydm_get_phy_sts_type1(dm, phy_sts, pktinfo, phy_info);
  2556. break;
  2557. case 2:
  2558. phydm_get_phy_sts_type2(dm, phy_sts, pktinfo, phy_info);
  2559. break;
  2560. default:
  2561. break;
  2562. }
  2563. #if (RTL8822B_SUPPORT || RTL8821C_SUPPORT || RTL8195B_SUPPORT)
  2564. if (dm->support_ic_type & (ODM_RTL8822B | ODM_RTL8821C | ODM_RTL8195B))
  2565. phydm_print_phy_sts_jgr2(dm, phy_sts, pktinfo, phy_info);
  2566. #endif
  2567. }
  2568. /*@==============================================*/
  2569. #endif
  2570. void odm_phy_status_query(struct dm_struct *dm,
  2571. struct phydm_phyinfo_struct *phy_info,
  2572. u8 *phy_status_inf,
  2573. struct phydm_perpkt_info_struct *pktinfo)
  2574. {
  2575. u8 rate = pktinfo->data_rate;
  2576. pktinfo->is_cck_rate = (rate <= ODM_RATE11M) ? true : false;
  2577. pktinfo->rate_ss = phydm_rate_to_num_ss(dm, rate);
  2578. dm->rate_ss = pktinfo->rate_ss; /*@For AP EVM SW antenna diversity use*/
  2579. if (pktinfo->is_cck_rate)
  2580. dm->phy_dbg_info.num_qry_phy_status_cck++;
  2581. else
  2582. dm->phy_dbg_info.num_qry_phy_status_ofdm++;
  2583. /*Reset phy_info*/
  2584. odm_memory_set(dm, phy_info->rx_mimo_signal_strength, 0, 4);
  2585. odm_memory_set(dm, phy_info->rx_mimo_signal_quality, 0, 4);
  2586. if (dm->support_ic_type & PHYSTS_3RD_TYPE_IC) {
  2587. #ifdef PHYSTS_3RD_TYPE_SUPPORT
  2588. phydm_rx_physts_3rd_type(dm, phy_status_inf, pktinfo, phy_info);
  2589. phydm_process_dm_rssi_3rd_type(dm, phy_info, pktinfo);
  2590. #endif
  2591. } else if (dm->support_ic_type & PHYSTS_2ND_TYPE_IC) {
  2592. #if (ODM_PHY_STATUS_NEW_TYPE_SUPPORT == 1)
  2593. phydm_rx_physts_2nd_type(dm, phy_status_inf, pktinfo, phy_info);
  2594. phydm_process_rssi_for_dm_2nd_type(dm, phy_info, pktinfo);
  2595. #endif
  2596. } else if (dm->support_ic_type & ODM_IC_11AC_SERIES) {
  2597. #if ODM_IC_11AC_SERIES_SUPPORT
  2598. phydm_rx_physts_1st_type(dm, phy_info, phy_status_inf, pktinfo);
  2599. phydm_process_rssi_for_dm(dm, phy_info, pktinfo);
  2600. #endif
  2601. } else if (dm->support_ic_type & ODM_IC_11N_SERIES) {
  2602. #if ODM_IC_11N_SERIES_SUPPORT
  2603. phydm_phy_sts_n_parsing(dm, phy_info, phy_status_inf, pktinfo);
  2604. phydm_process_rssi_for_dm(dm, phy_info, pktinfo);
  2605. #endif
  2606. }
  2607. phy_info->signal_strength = phy_info->rx_pwdb_all;
  2608. #if (DM_ODM_SUPPORT_TYPE & ODM_WIN)
  2609. phydm_process_signal_strength(dm, phy_info, pktinfo);
  2610. #endif
  2611. if (pktinfo->is_packet_match_bssid) {
  2612. dm->curr_station_id = pktinfo->station_id;
  2613. dm->rx_rate = rate;
  2614. dm->rssi_a = phy_info->rx_mimo_signal_strength[RF_PATH_A];
  2615. dm->rssi_b = phy_info->rx_mimo_signal_strength[RF_PATH_B];
  2616. dm->rssi_c = phy_info->rx_mimo_signal_strength[RF_PATH_C];
  2617. dm->rssi_d = phy_info->rx_mimo_signal_strength[RF_PATH_D];
  2618. if (rate >= ODM_RATE6M && rate <= ODM_RATE54M)
  2619. dm->rxsc_l = (s8)phy_info->rxsc;
  2620. else if (phy_info->band_width == CHANNEL_WIDTH_20)
  2621. dm->rxsc_20 = (s8)phy_info->rxsc;
  2622. else if (phy_info->band_width == CHANNEL_WIDTH_40)
  2623. dm->rxsc_40 = (s8)phy_info->rxsc;
  2624. else if (phy_info->band_width == CHANNEL_WIDTH_80)
  2625. dm->rxsc_80 = (s8)phy_info->rxsc;
  2626. phydm_avg_phystatus_index(dm, phy_info, pktinfo);
  2627. phydm_rx_statistic_cal(dm, phy_info, phy_status_inf, pktinfo);
  2628. }
  2629. }
  2630. void phydm_rx_phy_status_init(void *dm_void)
  2631. {
  2632. struct dm_struct *dm = (struct dm_struct *)dm_void;
  2633. struct odm_phy_dbg_info *dbg = &dm->phy_dbg_info;
  2634. #ifdef PHYDM_PHYSTAUS_SMP_MODE
  2635. struct pkt_process_info *pkt_process = &dm->pkt_proc_struct;
  2636. if (dm->support_ic_type & ODM_RTL8822B) {
  2637. pkt_process->phystatus_smp_mode_en = 1;
  2638. pkt_process->pre_ppdu_cnt = 0xff;
  2639. /*phystatus sampling mode enable*/
  2640. odm_set_mac_reg(dm, R_0x60f, BIT(7), 1);
  2641. /*@First update timming*/
  2642. odm_set_bb_reg(dm, R_0x9e4, 0x3ff, 0x0);
  2643. /*Update Sampling time*/
  2644. odm_set_bb_reg(dm, R_0x9e4, 0xfc00, 0x0);
  2645. } else if (dm->support_ic_type & ODM_IC_JGR3_SERIES) {
  2646. /*@First update timming*/
  2647. odm_set_bb_reg(dm, R_0x8c0, 0x3ff0, 0x0);
  2648. /*Update Sampling time*/
  2649. odm_set_bb_reg(dm, R_0x8c0, 0xfc000, 0x0);
  2650. }
  2651. #endif
  2652. dbg->show_phy_sts_all_pkt = 0;
  2653. dbg->show_phy_sts_max_cnt = 1;
  2654. dbg->show_phy_sts_cnt = 0;
  2655. phydm_avg_phystatus_init(dm);
  2656. }