dm.c 97 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2009-2010 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. #include "../wifi.h"
  26. #include "../base.h"
  27. #include "../pci.h"
  28. #include "../core.h"
  29. #include "reg.h"
  30. #include "def.h"
  31. #include "phy.h"
  32. #include "dm.h"
  33. #include "fw.h"
  34. #include "trx.h"
  35. #include "../btcoexist/rtl_btc.h"
  36. static const u32 txscaling_tbl[TXSCALE_TABLE_SIZE] = {
  37. 0x081, /* 0, -12.0dB */
  38. 0x088, /* 1, -11.5dB */
  39. 0x090, /* 2, -11.0dB */
  40. 0x099, /* 3, -10.5dB */
  41. 0x0A2, /* 4, -10.0dB */
  42. 0x0AC, /* 5, -9.5dB */
  43. 0x0B6, /* 6, -9.0dB */
  44. 0x0C0, /* 7, -8.5dB */
  45. 0x0CC, /* 8, -8.0dB */
  46. 0x0D8, /* 9, -7.5dB */
  47. 0x0E5, /* 10, -7.0dB */
  48. 0x0F2, /* 11, -6.5dB */
  49. 0x101, /* 12, -6.0dB */
  50. 0x110, /* 13, -5.5dB */
  51. 0x120, /* 14, -5.0dB */
  52. 0x131, /* 15, -4.5dB */
  53. 0x143, /* 16, -4.0dB */
  54. 0x156, /* 17, -3.5dB */
  55. 0x16A, /* 18, -3.0dB */
  56. 0x180, /* 19, -2.5dB */
  57. 0x197, /* 20, -2.0dB */
  58. 0x1AF, /* 21, -1.5dB */
  59. 0x1C8, /* 22, -1.0dB */
  60. 0x1E3, /* 23, -0.5dB */
  61. 0x200, /* 24, +0 dB */
  62. 0x21E, /* 25, +0.5dB */
  63. 0x23E, /* 26, +1.0dB */
  64. 0x261, /* 27, +1.5dB */
  65. 0x285, /* 28, +2.0dB */
  66. 0x2AB, /* 29, +2.5dB */
  67. 0x2D3, /* 30, +3.0dB */
  68. 0x2FE, /* 31, +3.5dB */
  69. 0x32B, /* 32, +4.0dB */
  70. 0x35C, /* 33, +4.5dB */
  71. 0x38E, /* 34, +5.0dB */
  72. 0x3C4, /* 35, +5.5dB */
  73. 0x3FE /* 36, +6.0dB */
  74. };
  75. static const u32 rtl8821ae_txscaling_table[TXSCALE_TABLE_SIZE] = {
  76. 0x081, /* 0, -12.0dB */
  77. 0x088, /* 1, -11.5dB */
  78. 0x090, /* 2, -11.0dB */
  79. 0x099, /* 3, -10.5dB */
  80. 0x0A2, /* 4, -10.0dB */
  81. 0x0AC, /* 5, -9.5dB */
  82. 0x0B6, /* 6, -9.0dB */
  83. 0x0C0, /* 7, -8.5dB */
  84. 0x0CC, /* 8, -8.0dB */
  85. 0x0D8, /* 9, -7.5dB */
  86. 0x0E5, /* 10, -7.0dB */
  87. 0x0F2, /* 11, -6.5dB */
  88. 0x101, /* 12, -6.0dB */
  89. 0x110, /* 13, -5.5dB */
  90. 0x120, /* 14, -5.0dB */
  91. 0x131, /* 15, -4.5dB */
  92. 0x143, /* 16, -4.0dB */
  93. 0x156, /* 17, -3.5dB */
  94. 0x16A, /* 18, -3.0dB */
  95. 0x180, /* 19, -2.5dB */
  96. 0x197, /* 20, -2.0dB */
  97. 0x1AF, /* 21, -1.5dB */
  98. 0x1C8, /* 22, -1.0dB */
  99. 0x1E3, /* 23, -0.5dB */
  100. 0x200, /* 24, +0 dB */
  101. 0x21E, /* 25, +0.5dB */
  102. 0x23E, /* 26, +1.0dB */
  103. 0x261, /* 27, +1.5dB */
  104. 0x285, /* 28, +2.0dB */
  105. 0x2AB, /* 29, +2.5dB */
  106. 0x2D3, /* 30, +3.0dB */
  107. 0x2FE, /* 31, +3.5dB */
  108. 0x32B, /* 32, +4.0dB */
  109. 0x35C, /* 33, +4.5dB */
  110. 0x38E, /* 34, +5.0dB */
  111. 0x3C4, /* 35, +5.5dB */
  112. 0x3FE /* 36, +6.0dB */
  113. };
  114. static const u32 ofdmswing_table[] = {
  115. 0x0b40002d, /* 0, -15.0dB */
  116. 0x0c000030, /* 1, -14.5dB */
  117. 0x0cc00033, /* 2, -14.0dB */
  118. 0x0d800036, /* 3, -13.5dB */
  119. 0x0e400039, /* 4, -13.0dB */
  120. 0x0f00003c, /* 5, -12.5dB */
  121. 0x10000040, /* 6, -12.0dB */
  122. 0x11000044, /* 7, -11.5dB */
  123. 0x12000048, /* 8, -11.0dB */
  124. 0x1300004c, /* 9, -10.5dB */
  125. 0x14400051, /* 10, -10.0dB */
  126. 0x15800056, /* 11, -9.5dB */
  127. 0x16c0005b, /* 12, -9.0dB */
  128. 0x18000060, /* 13, -8.5dB */
  129. 0x19800066, /* 14, -8.0dB */
  130. 0x1b00006c, /* 15, -7.5dB */
  131. 0x1c800072, /* 16, -7.0dB */
  132. 0x1e400079, /* 17, -6.5dB */
  133. 0x20000080, /* 18, -6.0dB */
  134. 0x22000088, /* 19, -5.5dB */
  135. 0x24000090, /* 20, -5.0dB */
  136. 0x26000098, /* 21, -4.5dB */
  137. 0x288000a2, /* 22, -4.0dB */
  138. 0x2ac000ab, /* 23, -3.5dB */
  139. 0x2d4000b5, /* 24, -3.0dB */
  140. 0x300000c0, /* 25, -2.5dB */
  141. 0x32c000cb, /* 26, -2.0dB */
  142. 0x35c000d7, /* 27, -1.5dB */
  143. 0x390000e4, /* 28, -1.0dB */
  144. 0x3c8000f2, /* 29, -0.5dB */
  145. 0x40000100, /* 30, +0dB */
  146. 0x43c0010f, /* 31, +0.5dB */
  147. 0x47c0011f, /* 32, +1.0dB */
  148. 0x4c000130, /* 33, +1.5dB */
  149. 0x50800142, /* 34, +2.0dB */
  150. 0x55400155, /* 35, +2.5dB */
  151. 0x5a400169, /* 36, +3.0dB */
  152. 0x5fc0017f, /* 37, +3.5dB */
  153. 0x65400195, /* 38, +4.0dB */
  154. 0x6b8001ae, /* 39, +4.5dB */
  155. 0x71c001c7, /* 40, +5.0dB */
  156. 0x788001e2, /* 41, +5.5dB */
  157. 0x7f8001fe /* 42, +6.0dB */
  158. };
  159. static const u8 cckswing_table_ch1ch13[CCK_TABLE_SIZE][8] = {
  160. {0x09, 0x08, 0x07, 0x06, 0x04, 0x03, 0x01, 0x01}, /* 0, -16.0dB */
  161. {0x09, 0x09, 0x08, 0x06, 0x05, 0x03, 0x01, 0x01}, /* 1, -15.5dB */
  162. {0x0a, 0x09, 0x08, 0x07, 0x05, 0x03, 0x02, 0x01}, /* 2, -15.0dB */
  163. {0x0a, 0x0a, 0x09, 0x07, 0x05, 0x03, 0x02, 0x01}, /* 3, -14.5dB */
  164. {0x0b, 0x0a, 0x09, 0x08, 0x06, 0x04, 0x02, 0x01}, /* 4, -14.0dB */
  165. {0x0b, 0x0b, 0x0a, 0x08, 0x06, 0x04, 0x02, 0x01}, /* 5, -13.5dB */
  166. {0x0c, 0x0c, 0x0a, 0x09, 0x06, 0x04, 0x02, 0x01}, /* 6, -13.0dB */
  167. {0x0d, 0x0c, 0x0b, 0x09, 0x07, 0x04, 0x02, 0x01}, /* 7, -12.5dB */
  168. {0x0d, 0x0d, 0x0c, 0x0a, 0x07, 0x05, 0x02, 0x01}, /* 8, -12.0dB */
  169. {0x0e, 0x0e, 0x0c, 0x0a, 0x08, 0x05, 0x02, 0x01}, /* 9, -11.5dB */
  170. {0x0f, 0x0f, 0x0d, 0x0b, 0x08, 0x05, 0x03, 0x01}, /* 10, -11.0dB */
  171. {0x10, 0x10, 0x0e, 0x0b, 0x08, 0x05, 0x03, 0x01}, /* 11, -10.5dB */
  172. {0x11, 0x11, 0x0f, 0x0c, 0x09, 0x06, 0x03, 0x01}, /* 12, -10.0dB */
  173. {0x12, 0x12, 0x0f, 0x0c, 0x09, 0x06, 0x03, 0x01}, /* 13, -9.5dB */
  174. {0x13, 0x13, 0x10, 0x0d, 0x0a, 0x06, 0x03, 0x01}, /* 14, -9.0dB */
  175. {0x14, 0x14, 0x11, 0x0e, 0x0b, 0x07, 0x03, 0x02}, /* 15, -8.5dB */
  176. {0x16, 0x15, 0x12, 0x0f, 0x0b, 0x07, 0x04, 0x01}, /* 16, -8.0dB */
  177. {0x17, 0x16, 0x13, 0x10, 0x0c, 0x08, 0x04, 0x02}, /* 17, -7.5dB */
  178. {0x18, 0x17, 0x15, 0x11, 0x0c, 0x08, 0x04, 0x02}, /* 18, -7.0dB */
  179. {0x1a, 0x19, 0x16, 0x12, 0x0d, 0x09, 0x04, 0x02}, /* 19, -6.5dB */
  180. {0x1b, 0x1a, 0x17, 0x13, 0x0e, 0x09, 0x04, 0x02}, /* 20, -6.0dB */
  181. {0x1d, 0x1c, 0x18, 0x14, 0x0f, 0x0a, 0x05, 0x02}, /* 21, -5.5dB */
  182. {0x1f, 0x1e, 0x1a, 0x15, 0x10, 0x0a, 0x05, 0x02}, /* 22, -5.0dB */
  183. {0x20, 0x20, 0x1b, 0x16, 0x11, 0x08, 0x05, 0x02}, /* 23, -4.5dB */
  184. {0x22, 0x21, 0x1d, 0x18, 0x11, 0x0b, 0x06, 0x02}, /* 24, -4.0dB */
  185. {0x24, 0x23, 0x1f, 0x19, 0x13, 0x0c, 0x06, 0x03}, /* 25, -3.5dB */
  186. {0x26, 0x25, 0x21, 0x1b, 0x14, 0x0d, 0x06, 0x03}, /* 26, -3.0dB */
  187. {0x28, 0x28, 0x22, 0x1c, 0x15, 0x0d, 0x07, 0x03}, /* 27, -2.5dB */
  188. {0x2b, 0x2a, 0x25, 0x1e, 0x16, 0x0e, 0x07, 0x03}, /* 28, -2.0dB */
  189. {0x2d, 0x2d, 0x27, 0x1f, 0x18, 0x0f, 0x08, 0x03}, /* 29, -1.5dB */
  190. {0x30, 0x2f, 0x29, 0x21, 0x19, 0x10, 0x08, 0x03}, /* 30, -1.0dB */
  191. {0x33, 0x32, 0x2b, 0x23, 0x1a, 0x11, 0x08, 0x04}, /* 31, -0.5dB */
  192. {0x36, 0x35, 0x2e, 0x25, 0x1c, 0x12, 0x09, 0x04} /* 32, +0dB */
  193. };
  194. static const u8 cckswing_table_ch14[CCK_TABLE_SIZE][8] = {
  195. {0x09, 0x08, 0x07, 0x04, 0x00, 0x00, 0x00, 0x00}, /* 0, -16.0dB */
  196. {0x09, 0x09, 0x08, 0x05, 0x00, 0x00, 0x00, 0x00}, /* 1, -15.5dB */
  197. {0x0a, 0x09, 0x08, 0x05, 0x00, 0x00, 0x00, 0x00}, /* 2, -15.0dB */
  198. {0x0a, 0x0a, 0x09, 0x05, 0x00, 0x00, 0x00, 0x00}, /* 3, -14.5dB */
  199. {0x0b, 0x0a, 0x09, 0x05, 0x00, 0x00, 0x00, 0x00}, /* 4, -14.0dB */
  200. {0x0b, 0x0b, 0x0a, 0x06, 0x00, 0x00, 0x00, 0x00}, /* 5, -13.5dB */
  201. {0x0c, 0x0c, 0x0a, 0x06, 0x00, 0x00, 0x00, 0x00}, /* 6, -13.0dB */
  202. {0x0d, 0x0c, 0x0b, 0x06, 0x00, 0x00, 0x00, 0x00}, /* 7, -12.5dB */
  203. {0x0d, 0x0d, 0x0c, 0x07, 0x00, 0x00, 0x00, 0x00}, /* 8, -12.0dB */
  204. {0x0e, 0x0e, 0x0c, 0x07, 0x00, 0x00, 0x00, 0x00}, /* 9, -11.5dB */
  205. {0x0f, 0x0f, 0x0d, 0x08, 0x00, 0x00, 0x00, 0x00}, /* 10, -11.0dB */
  206. {0x10, 0x10, 0x0e, 0x08, 0x00, 0x00, 0x00, 0x00}, /* 11, -10.5dB */
  207. {0x11, 0x11, 0x0f, 0x09, 0x00, 0x00, 0x00, 0x00}, /* 12, -10.0dB */
  208. {0x12, 0x12, 0x0f, 0x09, 0x00, 0x00, 0x00, 0x00}, /* 13, -9.5dB */
  209. {0x13, 0x13, 0x10, 0x0a, 0x00, 0x00, 0x00, 0x00}, /* 14, -9.0dB */
  210. {0x14, 0x14, 0x11, 0x0a, 0x00, 0x00, 0x00, 0x00}, /* 15, -8.5dB */
  211. {0x16, 0x15, 0x12, 0x0b, 0x00, 0x00, 0x00, 0x00}, /* 16, -8.0dB */
  212. {0x17, 0x16, 0x13, 0x0b, 0x00, 0x00, 0x00, 0x00}, /* 17, -7.5dB */
  213. {0x18, 0x17, 0x15, 0x0c, 0x00, 0x00, 0x00, 0x00}, /* 18, -7.0dB */
  214. {0x1a, 0x19, 0x16, 0x0d, 0x00, 0x00, 0x00, 0x00}, /* 19, -6.5dB */
  215. {0x1b, 0x1a, 0x17, 0x0e, 0x00, 0x00, 0x00, 0x00}, /* 20, -6.0dB */
  216. {0x1d, 0x1c, 0x18, 0x0e, 0x00, 0x00, 0x00, 0x00}, /* 21, -5.5dB */
  217. {0x1f, 0x1e, 0x1a, 0x0f, 0x00, 0x00, 0x00, 0x00}, /* 22, -5.0dB */
  218. {0x20, 0x20, 0x1b, 0x10, 0x00, 0x00, 0x00, 0x00}, /* 23, -4.5dB */
  219. {0x22, 0x21, 0x1d, 0x11, 0x00, 0x00, 0x00, 0x00}, /* 24, -4.0dB */
  220. {0x24, 0x23, 0x1f, 0x12, 0x00, 0x00, 0x00, 0x00}, /* 25, -3.5dB */
  221. {0x26, 0x25, 0x21, 0x13, 0x00, 0x00, 0x00, 0x00}, /* 26, -3.0dB */
  222. {0x28, 0x28, 0x24, 0x14, 0x00, 0x00, 0x00, 0x00}, /* 27, -2.5dB */
  223. {0x2b, 0x2a, 0x25, 0x15, 0x00, 0x00, 0x00, 0x00}, /* 28, -2.0dB */
  224. {0x2d, 0x2d, 0x17, 0x17, 0x00, 0x00, 0x00, 0x00}, /* 29, -1.5dB */
  225. {0x30, 0x2f, 0x29, 0x18, 0x00, 0x00, 0x00, 0x00}, /* 30, -1.0dB */
  226. {0x33, 0x32, 0x2b, 0x19, 0x00, 0x00, 0x00, 0x00}, /* 31, -0.5dB */
  227. {0x36, 0x35, 0x2e, 0x1b, 0x00, 0x00, 0x00, 0x00} /* 32, +0dB */
  228. };
  229. static const u32 edca_setting_dl[PEER_MAX] = {
  230. 0xa44f, /* 0 UNKNOWN */
  231. 0x5ea44f, /* 1 REALTEK_90 */
  232. 0x5e4322, /* 2 REALTEK_92SE */
  233. 0x5ea42b, /* 3 BROAD */
  234. 0xa44f, /* 4 RAL */
  235. 0xa630, /* 5 ATH */
  236. 0x5ea630, /* 6 CISCO */
  237. 0x5ea42b, /* 7 MARVELL */
  238. };
  239. static const u32 edca_setting_ul[PEER_MAX] = {
  240. 0x5e4322, /* 0 UNKNOWN */
  241. 0xa44f, /* 1 REALTEK_90 */
  242. 0x5ea44f, /* 2 REALTEK_92SE */
  243. 0x5ea32b, /* 3 BROAD */
  244. 0x5ea422, /* 4 RAL */
  245. 0x5ea322, /* 5 ATH */
  246. 0x3ea430, /* 6 CISCO */
  247. 0x5ea44f, /* 7 MARV */
  248. };
  249. static u8 rtl8818e_delta_swing_table_idx_24gb_p[] = {
  250. 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 4, 4, 4,
  251. 4, 4, 4, 5, 5, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9};
  252. static u8 rtl8818e_delta_swing_table_idx_24gb_n[] = {
  253. 0, 0, 0, 2, 2, 3, 3, 4, 4, 4, 4, 5, 5, 6, 6,
  254. 7, 7, 7, 7, 8, 8, 9, 9, 10, 10, 10, 11, 11, 11, 11};
  255. static u8 rtl8812ae_delta_swing_table_idx_24gb_n[] = {
  256. 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 6,
  257. 6, 6, 7, 8, 9, 9, 9, 9, 10, 10, 10, 10, 11, 11};
  258. static u8 rtl8812ae_delta_swing_table_idx_24gb_p[] = {
  259. 0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 6,
  260. 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 9};
  261. static u8 rtl8812ae_delta_swing_table_idx_24ga_n[] = {
  262. 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 6,
  263. 6, 6, 7, 8, 8, 9, 9, 9, 10, 10, 10, 10, 11, 11};
  264. static u8 rtl8812ae_delta_swing_table_idx_24ga_p[] = {
  265. 0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 6,
  266. 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 9};
  267. static u8 rtl8812ae_delta_swing_table_idx_24gcckb_n[] = {
  268. 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 6,
  269. 6, 6, 7, 8, 9, 9, 9, 9, 10, 10, 10, 10, 11, 11};
  270. static u8 rtl8812ae_delta_swing_table_idx_24gcckb_p[] = {
  271. 0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 6,
  272. 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 9};
  273. static u8 rtl8812ae_delta_swing_table_idx_24gccka_n[] = {
  274. 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 6,
  275. 6, 6, 7, 8, 8, 9, 9, 9, 10, 10, 10, 10, 11, 11};
  276. static u8 rtl8812ae_delta_swing_table_idx_24gccka_p[] = {
  277. 0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 6,
  278. 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 9};
  279. static u8 rtl8812ae_delta_swing_table_idx_5gb_n[][DEL_SW_IDX_SZ] = {
  280. {0, 1, 1, 2, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 6, 7, 7,
  281. 7, 8, 8, 9, 9, 9, 10, 10, 11, 11, 12, 12, 13},
  282. {0, 1, 1, 2, 2, 2, 3, 3, 4, 4, 4, 5, 5, 6, 6, 7,
  283. 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 13, 13},
  284. {0, 1, 1, 2, 3, 3, 4, 4, 5, 6, 6, 7, 8, 9, 10, 11,
  285. 12, 12, 13, 14, 14, 14, 15, 16, 17, 17, 17, 18, 18, 18},
  286. };
  287. static u8 rtl8812ae_delta_swing_table_idx_5gb_p[][DEL_SW_IDX_SZ] = {
  288. {0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 6, 7, 7, 8,
  289. 8, 9, 9, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11},
  290. {0, 1, 1, 2, 2, 3, 3, 4, 4, 4, 5, 5, 6, 6, 7, 7, 8,
  291. 8, 9, 9, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11},
  292. {0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 7, 7, 8, 8, 9,
  293. 9, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11},
  294. };
  295. static u8 rtl8812ae_delta_swing_table_idx_5ga_n[][DEL_SW_IDX_SZ] = {
  296. {0, 1, 1, 2, 2, 3, 3, 4, 4, 4, 5, 5, 6, 6, 7, 7, 8,
  297. 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 13, 13, 13},
  298. {0, 1, 1, 2, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 8, 9,
  299. 9, 10, 10, 11, 11, 11, 12, 12, 12, 12, 12, 13, 13},
  300. {0, 1, 1, 2, 2, 3, 3, 4, 5, 6, 7, 8, 8, 9, 10, 11,
  301. 12, 13, 14, 14, 15, 15, 15, 16, 16, 16, 17, 17, 18, 18},
  302. };
  303. static u8 rtl8812ae_delta_swing_table_idx_5ga_p[][DEL_SW_IDX_SZ] = {
  304. {0, 1, 1, 2, 2, 3, 3, 4, 4, 4, 4, 5, 5, 6, 7, 7, 8,
  305. 8, 9, 9, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11},
  306. {0, 1, 1, 2, 2, 3, 3, 4, 4, 4, 5, 5, 6, 6, 7, 7, 8,
  307. 9, 9, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11},
  308. {0, 1, 1, 2, 3, 3, 4, 4, 5, 6, 6, 7, 7, 8, 9, 9,
  309. 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11},
  310. };
  311. static u8 rtl8821ae_delta_swing_table_idx_24gb_n[] = {
  312. 0, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6,
  313. 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10};
  314. static u8 rtl8821ae_delta_swing_table_idx_24gb_p[] = {
  315. 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8,
  316. 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12, 12, 12};
  317. static u8 rtl8821ae_delta_swing_table_idx_24ga_n[] = {
  318. 0, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6,
  319. 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10};
  320. static u8 rtl8821ae_delta_swing_table_idx_24ga_p[] = {
  321. 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8,
  322. 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12, 12, 12};
  323. static u8 rtl8821ae_delta_swing_table_idx_24gcckb_n[] = {
  324. 0, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6,
  325. 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10};
  326. static u8 rtl8821ae_delta_swing_table_idx_24gcckb_p[] = {
  327. 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8,
  328. 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12, 12, 12};
  329. static u8 rtl8821ae_delta_swing_table_idx_24gccka_n[] = {
  330. 0, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6,
  331. 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10};
  332. static u8 rtl8821ae_delta_swing_table_idx_24gccka_p[] = {
  333. 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8,
  334. 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12, 12, 12};
  335. static u8 rtl8821ae_delta_swing_table_idx_5gb_n[][DEL_SW_IDX_SZ] = {
  336. {0, 0, 1, 2, 3, 3, 4, 5, 6, 6, 7, 8, 9, 9, 10, 11,
  337. 12, 12, 13, 14, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16},
  338. {0, 0, 1, 2, 3, 3, 4, 5, 6, 6, 7, 8, 9, 9, 10, 11,
  339. 12, 12, 13, 14, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16},
  340. {0, 0, 1, 2, 3, 3, 4, 5, 6, 6, 7, 8, 9, 9, 10, 11,
  341. 12, 12, 13, 14, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16},
  342. };
  343. static u8 rtl8821ae_delta_swing_table_idx_5gb_p[][DEL_SW_IDX_SZ] = {
  344. {0, 0, 1, 2, 3, 3, 4, 5, 6, 6, 7, 8, 9, 9, 10, 11,
  345. 12, 12, 13, 14, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16},
  346. {0, 0, 1, 2, 3, 3, 4, 5, 6, 6, 7, 8, 9, 9, 10, 11,
  347. 12, 12, 13, 14, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16},
  348. {0, 0, 1, 2, 3, 3, 4, 5, 6, 6, 7, 8, 9, 9, 10, 11,
  349. 12, 12, 13, 14, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16},
  350. };
  351. static u8 rtl8821ae_delta_swing_table_idx_5ga_n[][DEL_SW_IDX_SZ] = {
  352. {0, 0, 1, 2, 3, 3, 4, 5, 6, 6, 7, 8, 9, 9, 10, 11,
  353. 12, 12, 13, 14, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16},
  354. {0, 0, 1, 2, 3, 3, 4, 5, 6, 6, 7, 8, 9, 9, 10, 11,
  355. 12, 12, 13, 14, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16},
  356. {0, 0, 1, 2, 3, 3, 4, 5, 6, 6, 7, 8, 9, 9, 10, 11,
  357. 12, 12, 13, 14, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16},
  358. };
  359. static u8 rtl8821ae_delta_swing_table_idx_5ga_p[][DEL_SW_IDX_SZ] = {
  360. {0, 0, 1, 2, 3, 3, 4, 5, 6, 6, 7, 8, 9, 9, 10, 11,
  361. 12, 12, 13, 14, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16},
  362. {0, 0, 1, 2, 3, 3, 4, 5, 6, 6, 7, 8, 9, 9, 10, 11,
  363. 12, 12, 13, 14, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16},
  364. {0, 0, 1, 2, 3, 3, 4, 5, 6, 6, 7, 8, 9, 9, 10, 11,
  365. 12, 12, 13, 14, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16},
  366. };
  367. void rtl8821ae_dm_txpower_track_adjust(struct ieee80211_hw *hw,
  368. u8 type, u8 *pdirection,
  369. u32 *poutwrite_val)
  370. {
  371. struct rtl_priv *rtlpriv = rtl_priv(hw);
  372. struct rtl_dm *rtldm = rtl_dm(rtl_priv(hw));
  373. u8 pwr_val = 0;
  374. if (type == 0) {
  375. if (rtlpriv->dm.swing_idx_ofdm[RF90_PATH_A] <=
  376. rtlpriv->dm.swing_idx_ofdm_base[RF90_PATH_A]) {
  377. *pdirection = 1;
  378. pwr_val = rtldm->swing_idx_ofdm_base[RF90_PATH_A] -
  379. rtldm->swing_idx_ofdm[RF90_PATH_A];
  380. } else {
  381. *pdirection = 2;
  382. pwr_val = rtldm->swing_idx_ofdm[RF90_PATH_A] -
  383. rtldm->swing_idx_ofdm_base[RF90_PATH_A];
  384. }
  385. } else if (type == 1) {
  386. if (rtldm->swing_idx_cck <= rtldm->swing_idx_cck_base) {
  387. *pdirection = 1;
  388. pwr_val = rtldm->swing_idx_cck_base -
  389. rtldm->swing_idx_cck;
  390. } else {
  391. *pdirection = 2;
  392. pwr_val = rtldm->swing_idx_cck -
  393. rtldm->swing_idx_cck_base;
  394. }
  395. }
  396. if (pwr_val >= TXPWRTRACK_MAX_IDX && (*pdirection == 1))
  397. pwr_val = TXPWRTRACK_MAX_IDX;
  398. *poutwrite_val = pwr_val | (pwr_val << 8)|
  399. (pwr_val << 16)|
  400. (pwr_val << 24);
  401. }
  402. void rtl8821ae_dm_clear_txpower_tracking_state(struct ieee80211_hw *hw)
  403. {
  404. struct rtl_priv *rtlpriv = rtl_priv(hw);
  405. struct rtl_dm *rtldm = rtl_dm(rtlpriv);
  406. struct rtl_efuse *rtlefuse = rtl_efuse(rtlpriv);
  407. u8 p = 0;
  408. rtldm->swing_idx_cck_base = rtldm->default_cck_index;
  409. rtldm->swing_idx_cck = rtldm->default_cck_index;
  410. rtldm->cck_index = 0;
  411. for (p = RF90_PATH_A; p <= RF90_PATH_B; ++p) {
  412. rtldm->swing_idx_ofdm_base[p] = rtldm->default_ofdm_index;
  413. rtldm->swing_idx_ofdm[p] = rtldm->default_ofdm_index;
  414. rtldm->ofdm_index[p] = rtldm->default_ofdm_index;
  415. rtldm->power_index_offset[p] = 0;
  416. rtldm->delta_power_index[p] = 0;
  417. rtldm->delta_power_index_last[p] = 0;
  418. /*Initial Mix mode power tracking*/
  419. rtldm->absolute_ofdm_swing_idx[p] = 0;
  420. rtldm->remnant_ofdm_swing_idx[p] = 0;
  421. }
  422. /*Initial at Modify Tx Scaling Mode*/
  423. rtldm->modify_txagc_flag_path_a = false;
  424. /*Initial at Modify Tx Scaling Mode*/
  425. rtldm->modify_txagc_flag_path_b = false;
  426. rtldm->remnant_cck_idx = 0;
  427. rtldm->thermalvalue = rtlefuse->eeprom_thermalmeter;
  428. rtldm->thermalvalue_iqk = rtlefuse->eeprom_thermalmeter;
  429. rtldm->thermalvalue_lck = rtlefuse->eeprom_thermalmeter;
  430. }
  431. static u8 rtl8821ae_dm_get_swing_index(struct ieee80211_hw *hw)
  432. {
  433. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  434. u8 i = 0;
  435. u32 bb_swing;
  436. bb_swing = phy_get_tx_swing_8812A(hw, rtlhal->current_bandtype,
  437. RF90_PATH_A);
  438. for (i = 0; i < TXSCALE_TABLE_SIZE; ++i)
  439. if (bb_swing == rtl8821ae_txscaling_table[i])
  440. break;
  441. return i;
  442. }
  443. void rtl8821ae_dm_initialize_txpower_tracking_thermalmeter(
  444. struct ieee80211_hw *hw)
  445. {
  446. struct rtl_priv *rtlpriv = rtl_priv(hw);
  447. struct rtl_dm *rtldm = rtl_dm(rtlpriv);
  448. struct rtl_efuse *rtlefuse = rtl_efuse(rtlpriv);
  449. u8 default_swing_index = 0;
  450. u8 p = 0;
  451. rtlpriv->dm.txpower_track_control = true;
  452. rtldm->thermalvalue = rtlefuse->eeprom_thermalmeter;
  453. rtldm->thermalvalue_iqk = rtlefuse->eeprom_thermalmeter;
  454. rtldm->thermalvalue_lck = rtlefuse->eeprom_thermalmeter;
  455. default_swing_index = rtl8821ae_dm_get_swing_index(hw);
  456. rtldm->default_ofdm_index =
  457. (default_swing_index == TXSCALE_TABLE_SIZE) ?
  458. 24 : default_swing_index;
  459. rtldm->default_cck_index = 24;
  460. rtldm->swing_idx_cck_base = rtldm->default_cck_index;
  461. rtldm->cck_index = rtldm->default_cck_index;
  462. for (p = RF90_PATH_A; p < MAX_RF_PATH; ++p) {
  463. rtldm->swing_idx_ofdm_base[p] =
  464. rtldm->default_ofdm_index;
  465. rtldm->ofdm_index[p] = rtldm->default_ofdm_index;
  466. rtldm->delta_power_index[p] = 0;
  467. rtldm->power_index_offset[p] = 0;
  468. rtldm->delta_power_index_last[p] = 0;
  469. }
  470. }
  471. void rtl8821ae_dm_init_edca_turbo(struct ieee80211_hw *hw)
  472. {
  473. struct rtl_priv *rtlpriv = rtl_priv(hw);
  474. rtlpriv->dm.current_turbo_edca = false;
  475. rtlpriv->dm.is_any_nonbepkts = false;
  476. rtlpriv->dm.is_cur_rdlstate = false;
  477. }
  478. void rtl8821ae_dm_init_rate_adaptive_mask(struct ieee80211_hw *hw)
  479. {
  480. struct rtl_priv *rtlpriv = rtl_priv(hw);
  481. struct rate_adaptive *p_ra = &rtlpriv->ra;
  482. p_ra->ratr_state = DM_RATR_STA_INIT;
  483. p_ra->pre_ratr_state = DM_RATR_STA_INIT;
  484. rtlpriv->dm.dm_type = DM_TYPE_BYDRIVER;
  485. if (rtlpriv->dm.dm_type == DM_TYPE_BYDRIVER)
  486. rtlpriv->dm.useramask = true;
  487. else
  488. rtlpriv->dm.useramask = false;
  489. p_ra->high_rssi_thresh_for_ra = 50;
  490. p_ra->low_rssi_thresh_for_ra40m = 20;
  491. }
  492. static void rtl8821ae_dm_init_dynamic_atc_switch(struct ieee80211_hw *hw)
  493. {
  494. struct rtl_priv *rtlpriv = rtl_priv(hw);
  495. rtlpriv->dm.crystal_cap = rtlpriv->efuse.crystalcap;
  496. rtlpriv->dm.atc_status = rtl_get_bbreg(hw, ROFDM1_CFOTRACKING, BIT(11));
  497. rtlpriv->dm.cfo_threshold = CFO_THRESHOLD_XTAL;
  498. }
  499. static void rtl8821ae_dm_common_info_self_init(struct ieee80211_hw *hw)
  500. {
  501. struct rtl_priv *rtlpriv = rtl_priv(hw);
  502. struct rtl_phy *rtlphy = &rtlpriv->phy;
  503. u8 tmp;
  504. rtlphy->cck_high_power =
  505. (bool)rtl_get_bbreg(hw, ODM_REG_CCK_RPT_FORMAT_11AC,
  506. ODM_BIT_CCK_RPT_FORMAT_11AC);
  507. tmp = (u8)rtl_get_bbreg(hw, ODM_REG_BB_RX_PATH_11AC,
  508. ODM_BIT_BB_RX_PATH_11AC);
  509. if (tmp & BIT(0))
  510. rtlpriv->dm.rfpath_rxenable[0] = true;
  511. if (tmp & BIT(1))
  512. rtlpriv->dm.rfpath_rxenable[1] = true;
  513. }
  514. void rtl8821ae_dm_init(struct ieee80211_hw *hw)
  515. {
  516. struct rtl_priv *rtlpriv = rtl_priv(hw);
  517. struct rtl_phy *rtlphy = &rtlpriv->phy;
  518. u32 cur_igvalue = rtl_get_bbreg(hw, ROFDM0_XAAGCCORE1, 0x7f);
  519. spin_lock(&rtlpriv->locks.iqk_lock);
  520. rtlphy->lck_inprogress = false;
  521. spin_unlock(&rtlpriv->locks.iqk_lock);
  522. rtlpriv->dm.dm_type = DM_TYPE_BYDRIVER;
  523. rtl8821ae_dm_common_info_self_init(hw);
  524. rtl_dm_diginit(hw, cur_igvalue);
  525. rtl8821ae_dm_init_rate_adaptive_mask(hw);
  526. rtl8821ae_dm_init_edca_turbo(hw);
  527. rtl8821ae_dm_initialize_txpower_tracking_thermalmeter(hw);
  528. rtl8821ae_dm_init_dynamic_atc_switch(hw);
  529. }
  530. static void rtl8821ae_dm_find_minimum_rssi(struct ieee80211_hw *hw)
  531. {
  532. struct rtl_priv *rtlpriv = rtl_priv(hw);
  533. struct dig_t *rtl_dm_dig = &rtlpriv->dm_digtable;
  534. struct rtl_mac *mac = rtl_mac(rtlpriv);
  535. /* Determine the minimum RSSI */
  536. if ((mac->link_state < MAC80211_LINKED) &&
  537. (rtlpriv->dm.entry_min_undec_sm_pwdb == 0)) {
  538. rtl_dm_dig->min_undec_pwdb_for_dm = 0;
  539. RT_TRACE(rtlpriv, COMP_BB_POWERSAVING, DBG_LOUD,
  540. "Not connected to any\n");
  541. }
  542. if (mac->link_state >= MAC80211_LINKED) {
  543. if (mac->opmode == NL80211_IFTYPE_AP ||
  544. mac->opmode == NL80211_IFTYPE_ADHOC) {
  545. rtl_dm_dig->min_undec_pwdb_for_dm =
  546. rtlpriv->dm.entry_min_undec_sm_pwdb;
  547. RT_TRACE(rtlpriv, COMP_BB_POWERSAVING, DBG_LOUD,
  548. "AP Client PWDB = 0x%lx\n",
  549. rtlpriv->dm.entry_min_undec_sm_pwdb);
  550. } else {
  551. rtl_dm_dig->min_undec_pwdb_for_dm =
  552. rtlpriv->dm.undec_sm_pwdb;
  553. RT_TRACE(rtlpriv, COMP_BB_POWERSAVING, DBG_LOUD,
  554. "STA Default Port PWDB = 0x%x\n",
  555. rtl_dm_dig->min_undec_pwdb_for_dm);
  556. }
  557. } else {
  558. rtl_dm_dig->min_undec_pwdb_for_dm =
  559. rtlpriv->dm.entry_min_undec_sm_pwdb;
  560. RT_TRACE(rtlpriv, COMP_BB_POWERSAVING, DBG_LOUD,
  561. "AP Ext Port or disconnet PWDB = 0x%x\n",
  562. rtl_dm_dig->min_undec_pwdb_for_dm);
  563. }
  564. RT_TRACE(rtlpriv, COMP_DIG, DBG_LOUD,
  565. "MinUndecoratedPWDBForDM =%d\n",
  566. rtl_dm_dig->min_undec_pwdb_for_dm);
  567. }
  568. static void rtl8812ae_dm_rssi_dump_to_register(struct ieee80211_hw *hw)
  569. {
  570. struct rtl_priv *rtlpriv = rtl_priv(hw);
  571. rtl_write_byte(rtlpriv, RA_RSSI_DUMP,
  572. rtlpriv->stats.rx_rssi_percentage[0]);
  573. rtl_write_byte(rtlpriv, RB_RSSI_DUMP,
  574. rtlpriv->stats.rx_rssi_percentage[1]);
  575. /* Rx EVM*/
  576. rtl_write_byte(rtlpriv, RS1_RX_EVM_DUMP,
  577. rtlpriv->stats.rx_evm_dbm[0]);
  578. rtl_write_byte(rtlpriv, RS2_RX_EVM_DUMP,
  579. rtlpriv->stats.rx_evm_dbm[1]);
  580. /*Rx SNR*/
  581. rtl_write_byte(rtlpriv, RA_RX_SNR_DUMP,
  582. (u8)(rtlpriv->stats.rx_snr_db[0]));
  583. rtl_write_byte(rtlpriv, RB_RX_SNR_DUMP,
  584. (u8)(rtlpriv->stats.rx_snr_db[1]));
  585. /*Rx Cfo_Short*/
  586. rtl_write_word(rtlpriv, RA_CFO_SHORT_DUMP,
  587. rtlpriv->stats.rx_cfo_short[0]);
  588. rtl_write_word(rtlpriv, RB_CFO_SHORT_DUMP,
  589. rtlpriv->stats.rx_cfo_short[1]);
  590. /*Rx Cfo_Tail*/
  591. rtl_write_word(rtlpriv, RA_CFO_LONG_DUMP,
  592. rtlpriv->stats.rx_cfo_tail[0]);
  593. rtl_write_word(rtlpriv, RB_CFO_LONG_DUMP,
  594. rtlpriv->stats.rx_cfo_tail[1]);
  595. }
  596. static void rtl8821ae_dm_check_rssi_monitor(struct ieee80211_hw *hw)
  597. {
  598. struct rtl_priv *rtlpriv = rtl_priv(hw);
  599. struct dig_t *dm_digtable = &rtlpriv->dm_digtable;
  600. struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
  601. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  602. struct rtl_sta_info *drv_priv;
  603. u8 h2c_parameter[4] = { 0 };
  604. long tmp_entry_max_pwdb = 0, tmp_entry_min_pwdb = 0xff;
  605. u8 stbc_tx = 0;
  606. u64 cur_txokcnt = 0, cur_rxokcnt = 0;
  607. static u64 last_txokcnt = 0, last_rxokcnt;
  608. cur_txokcnt = rtlpriv->stats.txbytesunicast - last_txokcnt;
  609. cur_rxokcnt = rtlpriv->stats.rxbytesunicast - last_rxokcnt;
  610. last_txokcnt = rtlpriv->stats.txbytesunicast;
  611. last_rxokcnt = rtlpriv->stats.rxbytesunicast;
  612. if (cur_rxokcnt > (last_txokcnt * 6))
  613. h2c_parameter[3] = 0x01;
  614. else
  615. h2c_parameter[3] = 0x00;
  616. /* AP & ADHOC & MESH */
  617. if (mac->opmode == NL80211_IFTYPE_AP ||
  618. mac->opmode == NL80211_IFTYPE_ADHOC ||
  619. mac->opmode == NL80211_IFTYPE_MESH_POINT) {
  620. spin_lock_bh(&rtlpriv->locks.entry_list_lock);
  621. list_for_each_entry(drv_priv, &rtlpriv->entry_list, list) {
  622. if (drv_priv->rssi_stat.undec_sm_pwdb <
  623. tmp_entry_min_pwdb)
  624. tmp_entry_min_pwdb =
  625. drv_priv->rssi_stat.undec_sm_pwdb;
  626. if (drv_priv->rssi_stat.undec_sm_pwdb >
  627. tmp_entry_max_pwdb)
  628. tmp_entry_max_pwdb =
  629. drv_priv->rssi_stat.undec_sm_pwdb;
  630. }
  631. spin_unlock_bh(&rtlpriv->locks.entry_list_lock);
  632. /* If associated entry is found */
  633. if (tmp_entry_max_pwdb != 0) {
  634. rtlpriv->dm.entry_max_undec_sm_pwdb =
  635. tmp_entry_max_pwdb;
  636. RTPRINT(rtlpriv, FDM, DM_PWDB,
  637. "EntryMaxPWDB = 0x%lx(%ld)\n",
  638. tmp_entry_max_pwdb, tmp_entry_max_pwdb);
  639. } else {
  640. rtlpriv->dm.entry_max_undec_sm_pwdb = 0;
  641. }
  642. /* If associated entry is found */
  643. if (tmp_entry_min_pwdb != 0xff) {
  644. rtlpriv->dm.entry_min_undec_sm_pwdb =
  645. tmp_entry_min_pwdb;
  646. RTPRINT(rtlpriv, FDM, DM_PWDB,
  647. "EntryMinPWDB = 0x%lx(%ld)\n",
  648. tmp_entry_min_pwdb, tmp_entry_min_pwdb);
  649. } else {
  650. rtlpriv->dm.entry_min_undec_sm_pwdb = 0;
  651. }
  652. }
  653. /* Indicate Rx signal strength to FW. */
  654. if (rtlpriv->dm.useramask) {
  655. if (rtlhal->hw_type == HARDWARE_TYPE_RTL8812AE) {
  656. if (mac->mode == WIRELESS_MODE_AC_24G ||
  657. mac->mode == WIRELESS_MODE_AC_5G ||
  658. mac->mode == WIRELESS_MODE_AC_ONLY)
  659. stbc_tx = (mac->vht_cur_stbc &
  660. STBC_VHT_ENABLE_TX) ? 1 : 0;
  661. else
  662. stbc_tx = (mac->ht_cur_stbc &
  663. STBC_HT_ENABLE_TX) ? 1 : 0;
  664. h2c_parameter[3] |= stbc_tx << 1;
  665. }
  666. h2c_parameter[2] =
  667. (u8)(rtlpriv->dm.undec_sm_pwdb & 0xFF);
  668. h2c_parameter[1] = 0x20;
  669. h2c_parameter[0] = 0;
  670. if (rtlhal->hw_type == HARDWARE_TYPE_RTL8812AE)
  671. rtl8821ae_fill_h2c_cmd(hw, H2C_RSSI_21AE_REPORT, 4,
  672. h2c_parameter);
  673. else
  674. rtl8821ae_fill_h2c_cmd(hw, H2C_RSSI_21AE_REPORT, 3,
  675. h2c_parameter);
  676. } else {
  677. rtl_write_byte(rtlpriv, 0x4fe, rtlpriv->dm.undec_sm_pwdb);
  678. }
  679. if (rtlhal->hw_type == HARDWARE_TYPE_RTL8812AE)
  680. rtl8812ae_dm_rssi_dump_to_register(hw);
  681. rtl8821ae_dm_find_minimum_rssi(hw);
  682. dm_digtable->rssi_val_min = rtlpriv->dm_digtable.min_undec_pwdb_for_dm;
  683. }
  684. void rtl8821ae_dm_write_cck_cca_thres(struct ieee80211_hw *hw, u8 current_cca)
  685. {
  686. struct rtl_priv *rtlpriv = rtl_priv(hw);
  687. struct dig_t *dm_digtable = &rtlpriv->dm_digtable;
  688. if (dm_digtable->cur_cck_cca_thres != current_cca)
  689. rtl_write_byte(rtlpriv, DM_REG_CCK_CCA_11AC, current_cca);
  690. dm_digtable->pre_cck_cca_thres = dm_digtable->cur_cck_cca_thres;
  691. dm_digtable->cur_cck_cca_thres = current_cca;
  692. }
  693. void rtl8821ae_dm_write_dig(struct ieee80211_hw *hw, u8 current_igi)
  694. {
  695. struct rtl_priv *rtlpriv = rtl_priv(hw);
  696. struct dig_t *dm_digtable = &rtlpriv->dm_digtable;
  697. if (dm_digtable->stop_dig)
  698. return;
  699. if (dm_digtable->cur_igvalue != current_igi) {
  700. rtl_set_bbreg(hw, DM_REG_IGI_A_11AC,
  701. DM_BIT_IGI_11AC, current_igi);
  702. if (rtlpriv->phy.rf_type != RF_1T1R)
  703. rtl_set_bbreg(hw, DM_REG_IGI_B_11AC,
  704. DM_BIT_IGI_11AC, current_igi);
  705. }
  706. dm_digtable->cur_igvalue = current_igi;
  707. }
  708. static void rtl8821ae_dm_dig(struct ieee80211_hw *hw)
  709. {
  710. struct rtl_priv *rtlpriv = rtl_priv(hw);
  711. struct dig_t *dm_digtable = &rtlpriv->dm_digtable;
  712. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  713. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  714. u8 dig_min_0;
  715. u8 dig_max_of_min;
  716. bool first_connect, first_disconnect;
  717. u8 dm_dig_max, dm_dig_min, offset;
  718. u8 current_igi = dm_digtable->cur_igvalue;
  719. RT_TRACE(rtlpriv, COMP_DIG, DBG_LOUD, "\n");
  720. if (mac->act_scanning) {
  721. RT_TRACE(rtlpriv, COMP_DIG, DBG_LOUD,
  722. "Return: In Scan Progress\n");
  723. return;
  724. }
  725. /*add by Neil Chen to avoid PSD is processing*/
  726. dig_min_0 = dm_digtable->dig_min_0;
  727. first_connect = (mac->link_state >= MAC80211_LINKED) &&
  728. (!dm_digtable->media_connect_0);
  729. first_disconnect = (mac->link_state < MAC80211_LINKED) &&
  730. (dm_digtable->media_connect_0);
  731. /*1 Boundary Decision*/
  732. dm_dig_max = 0x5A;
  733. if (rtlhal->hw_type != HARDWARE_TYPE_RTL8821AE)
  734. dm_dig_min = DM_DIG_MIN;
  735. else
  736. dm_dig_min = 0x1C;
  737. dig_max_of_min = DM_DIG_MAX_AP;
  738. if (mac->link_state >= MAC80211_LINKED) {
  739. if (rtlhal->hw_type != HARDWARE_TYPE_RTL8821AE)
  740. offset = 20;
  741. else
  742. offset = 10;
  743. if ((dm_digtable->rssi_val_min + offset) > dm_dig_max)
  744. dm_digtable->rx_gain_max = dm_dig_max;
  745. else if ((dm_digtable->rssi_val_min + offset) < dm_dig_min)
  746. dm_digtable->rx_gain_max = dm_dig_min;
  747. else
  748. dm_digtable->rx_gain_max =
  749. dm_digtable->rssi_val_min + offset;
  750. RT_TRACE(rtlpriv, COMP_DIG, DBG_LOUD,
  751. "dm_digtable->rssi_val_min=0x%x,dm_digtable->rx_gain_max = 0x%x",
  752. dm_digtable->rssi_val_min,
  753. dm_digtable->rx_gain_max);
  754. if (rtlpriv->dm.one_entry_only) {
  755. offset = 0;
  756. if (dm_digtable->rssi_val_min - offset < dm_dig_min)
  757. dig_min_0 = dm_dig_min;
  758. else if (dm_digtable->rssi_val_min -
  759. offset > dig_max_of_min)
  760. dig_min_0 = dig_max_of_min;
  761. else
  762. dig_min_0 =
  763. dm_digtable->rssi_val_min - offset;
  764. RT_TRACE(rtlpriv, COMP_DIG, DBG_LOUD,
  765. "bOneEntryOnly=TRUE, dig_min_0=0x%x\n",
  766. dig_min_0);
  767. } else {
  768. dig_min_0 = dm_dig_min;
  769. }
  770. } else {
  771. dm_digtable->rx_gain_max = dm_dig_max;
  772. dig_min_0 = dm_dig_min;
  773. RT_TRACE(rtlpriv, COMP_DIG, DBG_LOUD,
  774. "No Link\n");
  775. }
  776. if (rtlpriv->falsealm_cnt.cnt_all > 10000) {
  777. RT_TRACE(rtlpriv, COMP_DIG, DBG_LOUD,
  778. "Abnormally false alarm case.\n");
  779. if (dm_digtable->large_fa_hit != 3)
  780. dm_digtable->large_fa_hit++;
  781. if (dm_digtable->forbidden_igi < current_igi) {
  782. dm_digtable->forbidden_igi = current_igi;
  783. dm_digtable->large_fa_hit = 1;
  784. }
  785. if (dm_digtable->large_fa_hit >= 3) {
  786. if ((dm_digtable->forbidden_igi + 1) >
  787. dm_digtable->rx_gain_max)
  788. dm_digtable->rx_gain_min =
  789. dm_digtable->rx_gain_max;
  790. else
  791. dm_digtable->rx_gain_min =
  792. (dm_digtable->forbidden_igi + 1);
  793. dm_digtable->recover_cnt = 3600;
  794. }
  795. } else {
  796. /*Recovery mechanism for IGI lower bound*/
  797. if (dm_digtable->recover_cnt != 0) {
  798. dm_digtable->recover_cnt--;
  799. } else {
  800. if (dm_digtable->large_fa_hit < 3) {
  801. if ((dm_digtable->forbidden_igi - 1) <
  802. dig_min_0) {
  803. dm_digtable->forbidden_igi =
  804. dig_min_0;
  805. dm_digtable->rx_gain_min =
  806. dig_min_0;
  807. RT_TRACE(rtlpriv, COMP_DIG, DBG_LOUD,
  808. "Normal Case: At Lower Bound\n");
  809. } else {
  810. dm_digtable->forbidden_igi--;
  811. dm_digtable->rx_gain_min =
  812. (dm_digtable->forbidden_igi + 1);
  813. RT_TRACE(rtlpriv, COMP_DIG, DBG_LOUD,
  814. "Normal Case: Approach Lower Bound\n");
  815. }
  816. } else {
  817. dm_digtable->large_fa_hit = 0;
  818. }
  819. }
  820. }
  821. RT_TRACE(rtlpriv, COMP_DIG, DBG_LOUD,
  822. "pDM_DigTable->LargeFAHit=%d\n",
  823. dm_digtable->large_fa_hit);
  824. if (rtlpriv->dm.dbginfo.num_qry_beacon_pkt < 10)
  825. dm_digtable->rx_gain_min = dm_dig_min;
  826. if (dm_digtable->rx_gain_min > dm_digtable->rx_gain_max)
  827. dm_digtable->rx_gain_min = dm_digtable->rx_gain_max;
  828. /*Adjust initial gain by false alarm*/
  829. if (mac->link_state >= MAC80211_LINKED) {
  830. RT_TRACE(rtlpriv, COMP_DIG, DBG_LOUD,
  831. "DIG AfterLink\n");
  832. if (first_connect) {
  833. if (dm_digtable->rssi_val_min <= dig_max_of_min)
  834. current_igi = dm_digtable->rssi_val_min;
  835. else
  836. current_igi = dig_max_of_min;
  837. RT_TRACE(rtlpriv, COMP_DIG, DBG_LOUD,
  838. "First Connect\n");
  839. } else {
  840. if (rtlpriv->falsealm_cnt.cnt_all > DM_DIG_FA_TH2)
  841. current_igi = current_igi + 4;
  842. else if (rtlpriv->falsealm_cnt.cnt_all > DM_DIG_FA_TH1)
  843. current_igi = current_igi + 2;
  844. else if (rtlpriv->falsealm_cnt.cnt_all < DM_DIG_FA_TH0)
  845. current_igi = current_igi - 2;
  846. if ((rtlpriv->dm.dbginfo.num_qry_beacon_pkt < 10) &&
  847. (rtlpriv->falsealm_cnt.cnt_all < DM_DIG_FA_TH1)) {
  848. current_igi = dm_digtable->rx_gain_min;
  849. RT_TRACE(rtlpriv, COMP_DIG, DBG_LOUD,
  850. "Beacon is less than 10 and FA is less than 768, IGI GOES TO 0x1E!!!!!!!!!!!!\n");
  851. }
  852. }
  853. } else {
  854. RT_TRACE(rtlpriv, COMP_DIG, DBG_LOUD,
  855. "DIG BeforeLink\n");
  856. if (first_disconnect) {
  857. current_igi = dm_digtable->rx_gain_min;
  858. RT_TRACE(rtlpriv, COMP_DIG, DBG_LOUD,
  859. "First DisConnect\n");
  860. } else {
  861. /* 2012.03.30 LukeLee: enable DIG before
  862. * link but with very high thresholds
  863. */
  864. if (rtlpriv->falsealm_cnt.cnt_all > 2000)
  865. current_igi = current_igi + 4;
  866. else if (rtlpriv->falsealm_cnt.cnt_all > 600)
  867. current_igi = current_igi + 2;
  868. else if (rtlpriv->falsealm_cnt.cnt_all < 300)
  869. current_igi = current_igi - 2;
  870. if (current_igi >= 0x3e)
  871. current_igi = 0x3e;
  872. RT_TRACE(rtlpriv, COMP_DIG, DBG_LOUD, "England DIG\n");
  873. }
  874. }
  875. RT_TRACE(rtlpriv, COMP_DIG, DBG_LOUD,
  876. "DIG End Adjust IGI\n");
  877. /* Check initial gain by upper/lower bound*/
  878. if (current_igi > dm_digtable->rx_gain_max)
  879. current_igi = dm_digtable->rx_gain_max;
  880. if (current_igi < dm_digtable->rx_gain_min)
  881. current_igi = dm_digtable->rx_gain_min;
  882. RT_TRACE(rtlpriv, COMP_DIG, DBG_LOUD,
  883. "rx_gain_max=0x%x, rx_gain_min=0x%x\n",
  884. dm_digtable->rx_gain_max, dm_digtable->rx_gain_min);
  885. RT_TRACE(rtlpriv, COMP_DIG, DBG_LOUD,
  886. "TotalFA=%d\n", rtlpriv->falsealm_cnt.cnt_all);
  887. RT_TRACE(rtlpriv, COMP_DIG, DBG_LOUD,
  888. "CurIGValue=0x%x\n", current_igi);
  889. rtl8821ae_dm_write_dig(hw, current_igi);
  890. dm_digtable->media_connect_0 =
  891. ((mac->link_state >= MAC80211_LINKED) ? true : false);
  892. dm_digtable->dig_min_0 = dig_min_0;
  893. }
  894. static void rtl8821ae_dm_common_info_self_update(struct ieee80211_hw *hw)
  895. {
  896. struct rtl_priv *rtlpriv = rtl_priv(hw);
  897. u8 cnt = 0;
  898. struct rtl_sta_info *drv_priv;
  899. rtlpriv->dm.tx_rate = 0xff;
  900. rtlpriv->dm.one_entry_only = false;
  901. if (rtlpriv->mac80211.opmode == NL80211_IFTYPE_STATION &&
  902. rtlpriv->mac80211.link_state >= MAC80211_LINKED) {
  903. rtlpriv->dm.one_entry_only = true;
  904. return;
  905. }
  906. if (rtlpriv->mac80211.opmode == NL80211_IFTYPE_AP ||
  907. rtlpriv->mac80211.opmode == NL80211_IFTYPE_ADHOC ||
  908. rtlpriv->mac80211.opmode == NL80211_IFTYPE_MESH_POINT) {
  909. spin_lock_bh(&rtlpriv->locks.entry_list_lock);
  910. list_for_each_entry(drv_priv, &rtlpriv->entry_list, list)
  911. cnt++;
  912. spin_unlock_bh(&rtlpriv->locks.entry_list_lock);
  913. if (cnt == 1)
  914. rtlpriv->dm.one_entry_only = true;
  915. }
  916. }
  917. static void rtl8821ae_dm_false_alarm_counter_statistics(struct ieee80211_hw *hw)
  918. {
  919. struct rtl_priv *rtlpriv = rtl_priv(hw);
  920. struct false_alarm_statistics *falsealm_cnt = &rtlpriv->falsealm_cnt;
  921. u32 cck_enable = 0;
  922. /*read OFDM FA counter*/
  923. falsealm_cnt->cnt_ofdm_fail =
  924. rtl_get_bbreg(hw, ODM_REG_OFDM_FA_11AC, BMASKLWORD);
  925. falsealm_cnt->cnt_cck_fail =
  926. rtl_get_bbreg(hw, ODM_REG_CCK_FA_11AC, BMASKLWORD);
  927. cck_enable = rtl_get_bbreg(hw, ODM_REG_BB_RX_PATH_11AC, BIT(28));
  928. if (cck_enable) /*if(pDM_Odm->pBandType == ODM_BAND_2_4G)*/
  929. falsealm_cnt->cnt_all = falsealm_cnt->cnt_ofdm_fail +
  930. falsealm_cnt->cnt_cck_fail;
  931. else
  932. falsealm_cnt->cnt_all = falsealm_cnt->cnt_ofdm_fail;
  933. /*reset OFDM FA coutner*/
  934. rtl_set_bbreg(hw, ODM_REG_OFDM_FA_RST_11AC, BIT(17), 1);
  935. rtl_set_bbreg(hw, ODM_REG_OFDM_FA_RST_11AC, BIT(17), 0);
  936. /* reset CCK FA counter*/
  937. rtl_set_bbreg(hw, ODM_REG_CCK_FA_RST_11AC, BIT(15), 0);
  938. rtl_set_bbreg(hw, ODM_REG_CCK_FA_RST_11AC, BIT(15), 1);
  939. RT_TRACE(rtlpriv, COMP_DIG, DBG_LOUD, "Cnt_Cck_fail=%d\n",
  940. falsealm_cnt->cnt_cck_fail);
  941. RT_TRACE(rtlpriv, COMP_DIG, DBG_LOUD, "cnt_ofdm_fail=%d\n",
  942. falsealm_cnt->cnt_ofdm_fail);
  943. RT_TRACE(rtlpriv, COMP_DIG, DBG_LOUD, "Total False Alarm=%d\n",
  944. falsealm_cnt->cnt_all);
  945. }
  946. static void rtl8812ae_dm_check_txpower_tracking_thermalmeter(
  947. struct ieee80211_hw *hw)
  948. {
  949. struct rtl_priv *rtlpriv = rtl_priv(hw);
  950. if (!rtlpriv->dm.tm_trigger) {
  951. rtl_set_rfreg(hw, RF90_PATH_A, RF_T_METER_88E,
  952. BIT(17) | BIT(16), 0x03);
  953. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  954. "Trigger 8812 Thermal Meter!!\n");
  955. rtlpriv->dm.tm_trigger = 1;
  956. return;
  957. }
  958. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  959. "Schedule TxPowerTracking direct call!!\n");
  960. rtl8812ae_dm_txpower_tracking_callback_thermalmeter(hw);
  961. }
  962. static void rtl8821ae_dm_iq_calibrate(struct ieee80211_hw *hw)
  963. {
  964. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  965. struct rtl_dm *rtldm = rtl_dm(rtl_priv(hw));
  966. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  967. if (mac->link_state >= MAC80211_LINKED) {
  968. if (rtldm->linked_interval < 3)
  969. rtldm->linked_interval++;
  970. if (rtldm->linked_interval == 2) {
  971. if (rtlhal->hw_type == HARDWARE_TYPE_RTL8812AE)
  972. rtl8812ae_phy_iq_calibrate(hw, false);
  973. else
  974. rtl8821ae_phy_iq_calibrate(hw, false);
  975. }
  976. } else {
  977. rtldm->linked_interval = 0;
  978. }
  979. }
  980. static void rtl8812ae_get_delta_swing_table(struct ieee80211_hw *hw,
  981. u8 **up_a, u8 **down_a,
  982. u8 **up_b, u8 **down_b)
  983. {
  984. struct rtl_priv *rtlpriv = rtl_priv(hw);
  985. struct rtl_phy *rtlphy = &rtlpriv->phy;
  986. struct rtl_dm *rtldm = rtl_dm(rtl_priv(hw));
  987. u8 channel = rtlphy->current_channel;
  988. u8 rate = rtldm->tx_rate;
  989. if (1 <= channel && channel <= 14) {
  990. if (RTL8821AE_RX_HAL_IS_CCK_RATE(rate)) {
  991. *up_a = rtl8812ae_delta_swing_table_idx_24gccka_p;
  992. *down_a = rtl8812ae_delta_swing_table_idx_24gccka_n;
  993. *up_b = rtl8812ae_delta_swing_table_idx_24gcckb_p;
  994. *down_b = rtl8812ae_delta_swing_table_idx_24gcckb_n;
  995. } else {
  996. *up_a = rtl8812ae_delta_swing_table_idx_24ga_p;
  997. *down_a = rtl8812ae_delta_swing_table_idx_24ga_n;
  998. *up_b = rtl8812ae_delta_swing_table_idx_24gb_p;
  999. *down_b = rtl8812ae_delta_swing_table_idx_24gb_n;
  1000. }
  1001. } else if (36 <= channel && channel <= 64) {
  1002. *up_a = rtl8812ae_delta_swing_table_idx_5ga_p[0];
  1003. *down_a = rtl8812ae_delta_swing_table_idx_5ga_n[0];
  1004. *up_b = rtl8812ae_delta_swing_table_idx_5gb_p[0];
  1005. *down_b = rtl8812ae_delta_swing_table_idx_5gb_n[0];
  1006. } else if (100 <= channel && channel <= 140) {
  1007. *up_a = rtl8812ae_delta_swing_table_idx_5ga_p[1];
  1008. *down_a = rtl8812ae_delta_swing_table_idx_5ga_n[1];
  1009. *up_b = rtl8812ae_delta_swing_table_idx_5gb_p[1];
  1010. *down_b = rtl8812ae_delta_swing_table_idx_5gb_n[1];
  1011. } else if (149 <= channel && channel <= 173) {
  1012. *up_a = rtl8812ae_delta_swing_table_idx_5ga_p[2];
  1013. *down_a = rtl8812ae_delta_swing_table_idx_5ga_n[2];
  1014. *up_b = rtl8812ae_delta_swing_table_idx_5gb_p[2];
  1015. *down_b = rtl8812ae_delta_swing_table_idx_5gb_n[2];
  1016. } else {
  1017. *up_a = (u8 *)rtl8818e_delta_swing_table_idx_24gb_p;
  1018. *down_a = (u8 *)rtl8818e_delta_swing_table_idx_24gb_n;
  1019. *up_b = (u8 *)rtl8818e_delta_swing_table_idx_24gb_p;
  1020. *down_b = (u8 *)rtl8818e_delta_swing_table_idx_24gb_n;
  1021. }
  1022. }
  1023. void rtl8821ae_dm_update_init_rate(struct ieee80211_hw *hw, u8 rate)
  1024. {
  1025. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1026. struct rtl_dm *rtldm = rtl_dm(rtl_priv(hw));
  1027. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1028. u8 p = 0;
  1029. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  1030. "Get C2H Command! Rate=0x%x\n", rate);
  1031. rtldm->tx_rate = rate;
  1032. if (rtlhal->hw_type == HARDWARE_TYPE_RTL8821AE) {
  1033. rtl8821ae_dm_txpwr_track_set_pwr(hw, MIX_MODE, RF90_PATH_A, 0);
  1034. } else {
  1035. for (p = RF90_PATH_A; p < MAX_PATH_NUM_8812A; p++)
  1036. rtl8812ae_dm_txpwr_track_set_pwr(hw, MIX_MODE, p, 0);
  1037. }
  1038. }
  1039. u8 rtl8821ae_hw_rate_to_mrate(struct ieee80211_hw *hw, u8 rate)
  1040. {
  1041. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1042. u8 ret_rate = MGN_1M;
  1043. switch (rate) {
  1044. case DESC_RATE1M:
  1045. ret_rate = MGN_1M;
  1046. break;
  1047. case DESC_RATE2M:
  1048. ret_rate = MGN_2M;
  1049. break;
  1050. case DESC_RATE5_5M:
  1051. ret_rate = MGN_5_5M;
  1052. break;
  1053. case DESC_RATE11M:
  1054. ret_rate = MGN_11M;
  1055. break;
  1056. case DESC_RATE6M:
  1057. ret_rate = MGN_6M;
  1058. break;
  1059. case DESC_RATE9M:
  1060. ret_rate = MGN_9M;
  1061. break;
  1062. case DESC_RATE12M:
  1063. ret_rate = MGN_12M;
  1064. break;
  1065. case DESC_RATE18M:
  1066. ret_rate = MGN_18M;
  1067. break;
  1068. case DESC_RATE24M:
  1069. ret_rate = MGN_24M;
  1070. break;
  1071. case DESC_RATE36M:
  1072. ret_rate = MGN_36M;
  1073. break;
  1074. case DESC_RATE48M:
  1075. ret_rate = MGN_48M;
  1076. break;
  1077. case DESC_RATE54M:
  1078. ret_rate = MGN_54M;
  1079. break;
  1080. case DESC_RATEMCS0:
  1081. ret_rate = MGN_MCS0;
  1082. break;
  1083. case DESC_RATEMCS1:
  1084. ret_rate = MGN_MCS1;
  1085. break;
  1086. case DESC_RATEMCS2:
  1087. ret_rate = MGN_MCS2;
  1088. break;
  1089. case DESC_RATEMCS3:
  1090. ret_rate = MGN_MCS3;
  1091. break;
  1092. case DESC_RATEMCS4:
  1093. ret_rate = MGN_MCS4;
  1094. break;
  1095. case DESC_RATEMCS5:
  1096. ret_rate = MGN_MCS5;
  1097. break;
  1098. case DESC_RATEMCS6:
  1099. ret_rate = MGN_MCS6;
  1100. break;
  1101. case DESC_RATEMCS7:
  1102. ret_rate = MGN_MCS7;
  1103. break;
  1104. case DESC_RATEMCS8:
  1105. ret_rate = MGN_MCS8;
  1106. break;
  1107. case DESC_RATEMCS9:
  1108. ret_rate = MGN_MCS9;
  1109. break;
  1110. case DESC_RATEMCS10:
  1111. ret_rate = MGN_MCS10;
  1112. break;
  1113. case DESC_RATEMCS11:
  1114. ret_rate = MGN_MCS11;
  1115. break;
  1116. case DESC_RATEMCS12:
  1117. ret_rate = MGN_MCS12;
  1118. break;
  1119. case DESC_RATEMCS13:
  1120. ret_rate = MGN_MCS13;
  1121. break;
  1122. case DESC_RATEMCS14:
  1123. ret_rate = MGN_MCS14;
  1124. break;
  1125. case DESC_RATEMCS15:
  1126. ret_rate = MGN_MCS15;
  1127. break;
  1128. case DESC_RATEVHT1SS_MCS0:
  1129. ret_rate = MGN_VHT1SS_MCS0;
  1130. break;
  1131. case DESC_RATEVHT1SS_MCS1:
  1132. ret_rate = MGN_VHT1SS_MCS1;
  1133. break;
  1134. case DESC_RATEVHT1SS_MCS2:
  1135. ret_rate = MGN_VHT1SS_MCS2;
  1136. break;
  1137. case DESC_RATEVHT1SS_MCS3:
  1138. ret_rate = MGN_VHT1SS_MCS3;
  1139. break;
  1140. case DESC_RATEVHT1SS_MCS4:
  1141. ret_rate = MGN_VHT1SS_MCS4;
  1142. break;
  1143. case DESC_RATEVHT1SS_MCS5:
  1144. ret_rate = MGN_VHT1SS_MCS5;
  1145. break;
  1146. case DESC_RATEVHT1SS_MCS6:
  1147. ret_rate = MGN_VHT1SS_MCS6;
  1148. break;
  1149. case DESC_RATEVHT1SS_MCS7:
  1150. ret_rate = MGN_VHT1SS_MCS7;
  1151. break;
  1152. case DESC_RATEVHT1SS_MCS8:
  1153. ret_rate = MGN_VHT1SS_MCS8;
  1154. break;
  1155. case DESC_RATEVHT1SS_MCS9:
  1156. ret_rate = MGN_VHT1SS_MCS9;
  1157. break;
  1158. case DESC_RATEVHT2SS_MCS0:
  1159. ret_rate = MGN_VHT2SS_MCS0;
  1160. break;
  1161. case DESC_RATEVHT2SS_MCS1:
  1162. ret_rate = MGN_VHT2SS_MCS1;
  1163. break;
  1164. case DESC_RATEVHT2SS_MCS2:
  1165. ret_rate = MGN_VHT2SS_MCS2;
  1166. break;
  1167. case DESC_RATEVHT2SS_MCS3:
  1168. ret_rate = MGN_VHT2SS_MCS3;
  1169. break;
  1170. case DESC_RATEVHT2SS_MCS4:
  1171. ret_rate = MGN_VHT2SS_MCS4;
  1172. break;
  1173. case DESC_RATEVHT2SS_MCS5:
  1174. ret_rate = MGN_VHT2SS_MCS5;
  1175. break;
  1176. case DESC_RATEVHT2SS_MCS6:
  1177. ret_rate = MGN_VHT2SS_MCS6;
  1178. break;
  1179. case DESC_RATEVHT2SS_MCS7:
  1180. ret_rate = MGN_VHT2SS_MCS7;
  1181. break;
  1182. case DESC_RATEVHT2SS_MCS8:
  1183. ret_rate = MGN_VHT2SS_MCS8;
  1184. break;
  1185. case DESC_RATEVHT2SS_MCS9:
  1186. ret_rate = MGN_VHT2SS_MCS9;
  1187. break;
  1188. default:
  1189. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  1190. "HwRateToMRate8812(): Non supported Rate [%x]!!!\n",
  1191. rate);
  1192. break;
  1193. }
  1194. return ret_rate;
  1195. }
  1196. /*-----------------------------------------------------------------------------
  1197. * Function: odm_TxPwrTrackSetPwr88E()
  1198. *
  1199. * Overview: 88E change all channel tx power accordign to flag.
  1200. * OFDM & CCK are all different.
  1201. *
  1202. * Input: NONE
  1203. *
  1204. * Output: NONE
  1205. *
  1206. * Return: NONE
  1207. *
  1208. * Revised History:
  1209. * When Who Remark
  1210. * 04/23/2012 MHC Create Version 0.
  1211. *
  1212. *---------------------------------------------------------------------------
  1213. */
  1214. void rtl8812ae_dm_txpwr_track_set_pwr(struct ieee80211_hw *hw,
  1215. enum pwr_track_control_method method,
  1216. u8 rf_path, u8 channel_mapped_index)
  1217. {
  1218. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1219. struct rtl_dm *rtldm = rtl_dm(rtl_priv(hw));
  1220. struct rtl_phy *rtlphy = &rtlpriv->phy;
  1221. u32 final_swing_idx[2];
  1222. u8 pwr_tracking_limit = 26; /*+1.0dB*/
  1223. u8 tx_rate = 0xFF;
  1224. char final_ofdm_swing_index = 0;
  1225. if (rtldm->tx_rate != 0xFF)
  1226. tx_rate =
  1227. rtl8821ae_hw_rate_to_mrate(hw, rtldm->tx_rate);
  1228. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  1229. "===>rtl8812ae_dm_txpwr_track_set_pwr\n");
  1230. /*20130429 Mimic Modify High Rate BBSwing Limit.*/
  1231. if (tx_rate != 0xFF) {
  1232. /*CCK*/
  1233. if ((tx_rate >= MGN_1M) && (tx_rate <= MGN_11M))
  1234. pwr_tracking_limit = 32; /*+4dB*/
  1235. /*OFDM*/
  1236. else if ((tx_rate >= MGN_6M) && (tx_rate <= MGN_48M))
  1237. pwr_tracking_limit = 30; /*+3dB*/
  1238. else if (tx_rate == MGN_54M)
  1239. pwr_tracking_limit = 28; /*+2dB*/
  1240. /*HT*/
  1241. /*QPSK/BPSK*/
  1242. else if ((tx_rate >= MGN_MCS0) && (tx_rate <= MGN_MCS2))
  1243. pwr_tracking_limit = 34; /*+5dB*/
  1244. /*16QAM*/
  1245. else if ((tx_rate >= MGN_MCS3) && (tx_rate <= MGN_MCS4))
  1246. pwr_tracking_limit = 30; /*+3dB*/
  1247. /*64QAM*/
  1248. else if ((tx_rate >= MGN_MCS5) && (tx_rate <= MGN_MCS7))
  1249. pwr_tracking_limit = 28; /*+2dB*/
  1250. /*QPSK/BPSK*/
  1251. else if ((tx_rate >= MGN_MCS8) && (tx_rate <= MGN_MCS10))
  1252. pwr_tracking_limit = 34; /*+5dB*/
  1253. /*16QAM*/
  1254. else if ((tx_rate >= MGN_MCS11) && (tx_rate <= MGN_MCS12))
  1255. pwr_tracking_limit = 30; /*+3dB*/
  1256. /*64QAM*/
  1257. else if ((tx_rate >= MGN_MCS13) && (tx_rate <= MGN_MCS15))
  1258. pwr_tracking_limit = 28; /*+2dB*/
  1259. /*2 VHT*/
  1260. /*QPSK/BPSK*/
  1261. else if ((tx_rate >= MGN_VHT1SS_MCS0) &&
  1262. (tx_rate <= MGN_VHT1SS_MCS2))
  1263. pwr_tracking_limit = 34; /*+5dB*/
  1264. /*16QAM*/
  1265. else if ((tx_rate >= MGN_VHT1SS_MCS3) &&
  1266. (tx_rate <= MGN_VHT1SS_MCS4))
  1267. pwr_tracking_limit = 30; /*+3dB*/
  1268. /*64QAM*/
  1269. else if ((tx_rate >= MGN_VHT1SS_MCS5) &&
  1270. (tx_rate <= MGN_VHT1SS_MCS6))
  1271. pwr_tracking_limit = 28; /*+2dB*/
  1272. else if (tx_rate == MGN_VHT1SS_MCS7) /*64QAM*/
  1273. pwr_tracking_limit = 26; /*+1dB*/
  1274. else if (tx_rate == MGN_VHT1SS_MCS8) /*256QAM*/
  1275. pwr_tracking_limit = 24; /*+0dB*/
  1276. else if (tx_rate == MGN_VHT1SS_MCS9) /*256QAM*/
  1277. pwr_tracking_limit = 22; /*-1dB*/
  1278. /*QPSK/BPSK*/
  1279. else if ((tx_rate >= MGN_VHT2SS_MCS0) &&
  1280. (tx_rate <= MGN_VHT2SS_MCS2))
  1281. pwr_tracking_limit = 34; /*+5dB*/
  1282. /*16QAM*/
  1283. else if ((tx_rate >= MGN_VHT2SS_MCS3) &&
  1284. (tx_rate <= MGN_VHT2SS_MCS4))
  1285. pwr_tracking_limit = 30; /*+3dB*/
  1286. /*64QAM*/
  1287. else if ((tx_rate >= MGN_VHT2SS_MCS5) &&
  1288. (tx_rate <= MGN_VHT2SS_MCS6))
  1289. pwr_tracking_limit = 28; /*+2dB*/
  1290. else if (tx_rate == MGN_VHT2SS_MCS7) /*64QAM*/
  1291. pwr_tracking_limit = 26; /*+1dB*/
  1292. else if (tx_rate == MGN_VHT2SS_MCS8) /*256QAM*/
  1293. pwr_tracking_limit = 24; /*+0dB*/
  1294. else if (tx_rate == MGN_VHT2SS_MCS9) /*256QAM*/
  1295. pwr_tracking_limit = 22; /*-1dB*/
  1296. else
  1297. pwr_tracking_limit = 24;
  1298. }
  1299. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  1300. "TxRate=0x%x, PwrTrackingLimit=%d\n",
  1301. tx_rate, pwr_tracking_limit);
  1302. if (method == BBSWING) {
  1303. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  1304. "===>rtl8812ae_dm_txpwr_track_set_pwr\n");
  1305. if (rf_path == RF90_PATH_A) {
  1306. u32 tmp;
  1307. final_swing_idx[RF90_PATH_A] =
  1308. (rtldm->ofdm_index[RF90_PATH_A] >
  1309. pwr_tracking_limit) ?
  1310. pwr_tracking_limit :
  1311. rtldm->ofdm_index[RF90_PATH_A];
  1312. tmp = final_swing_idx[RF90_PATH_A];
  1313. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  1314. "pDM_Odm->RFCalibrateInfo.OFDM_index[ODM_RF_PATH_A]=%d,pDM_Odm->RealBbSwingIdx[ODM_RF_PATH_A]=%d\n",
  1315. rtldm->ofdm_index[RF90_PATH_A],
  1316. final_swing_idx[RF90_PATH_A]);
  1317. rtl_set_bbreg(hw, RA_TXSCALE, 0xFFE00000,
  1318. txscaling_tbl[tmp]);
  1319. } else {
  1320. u32 tmp;
  1321. final_swing_idx[RF90_PATH_B] =
  1322. rtldm->ofdm_index[RF90_PATH_B] >
  1323. pwr_tracking_limit ?
  1324. pwr_tracking_limit :
  1325. rtldm->ofdm_index[RF90_PATH_B];
  1326. tmp = final_swing_idx[RF90_PATH_B];
  1327. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  1328. "pDM_Odm->RFCalibrateInfo.OFDM_index[ODM_RF_PATH_B]=%d, pDM_Odm->RealBbSwingIdx[ODM_RF_PATH_B]=%d\n",
  1329. rtldm->ofdm_index[RF90_PATH_B],
  1330. final_swing_idx[RF90_PATH_B]);
  1331. rtl_set_bbreg(hw, RB_TXSCALE, 0xFFE00000,
  1332. txscaling_tbl[tmp]);
  1333. }
  1334. } else if (method == MIX_MODE) {
  1335. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  1336. "pDM_Odm->DefaultOfdmIndex=%d, pDM_Odm->Aboslute_OFDMSwingIdx[RFPath]=%d, RF_Path = %d\n",
  1337. rtldm->default_ofdm_index,
  1338. rtldm->absolute_ofdm_swing_idx[rf_path],
  1339. rf_path);
  1340. final_ofdm_swing_index = rtldm->default_ofdm_index +
  1341. rtldm->absolute_ofdm_swing_idx[rf_path];
  1342. if (rf_path == RF90_PATH_A) {
  1343. /*BBSwing higher then Limit*/
  1344. if (final_ofdm_swing_index > pwr_tracking_limit) {
  1345. rtldm->remnant_cck_idx =
  1346. final_ofdm_swing_index -
  1347. pwr_tracking_limit;
  1348. /* CCK Follow the same compensation value
  1349. * as Path A
  1350. */
  1351. rtldm->remnant_ofdm_swing_idx[rf_path] =
  1352. final_ofdm_swing_index -
  1353. pwr_tracking_limit;
  1354. rtl_set_bbreg(hw, RA_TXSCALE, 0xFFE00000,
  1355. txscaling_tbl[pwr_tracking_limit]);
  1356. rtldm->modify_txagc_flag_path_a = true;
  1357. /*Set TxAGC Page C{};*/
  1358. rtl8821ae_phy_set_txpower_level_by_path(hw,
  1359. rtlphy->current_channel,
  1360. RF90_PATH_A);
  1361. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  1362. "******Path_A Over BBSwing Limit ,PwrTrackingLimit = %d ,Remnant TxAGC Value = %d\n",
  1363. pwr_tracking_limit,
  1364. rtldm->remnant_ofdm_swing_idx[rf_path]);
  1365. } else if (final_ofdm_swing_index < 0) {
  1366. rtldm->remnant_cck_idx = final_ofdm_swing_index;
  1367. /* CCK Follow the same compensate value as Path A*/
  1368. rtldm->remnant_ofdm_swing_idx[rf_path] =
  1369. final_ofdm_swing_index;
  1370. rtl_set_bbreg(hw, RA_TXSCALE, 0xFFE00000,
  1371. txscaling_tbl[0]);
  1372. rtldm->modify_txagc_flag_path_a = true;
  1373. /*Set TxAGC Page C{};*/
  1374. rtl8821ae_phy_set_txpower_level_by_path(hw,
  1375. rtlphy->current_channel, RF90_PATH_A);
  1376. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  1377. "******Path_A Lower then BBSwing lower bound 0 , Remnant TxAGC Value = %d\n",
  1378. rtldm->remnant_ofdm_swing_idx[rf_path]);
  1379. } else {
  1380. rtl_set_bbreg(hw, RA_TXSCALE, 0xFFE00000,
  1381. txscaling_tbl[(u8)final_ofdm_swing_index]);
  1382. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  1383. "******Path_A Compensate with BBSwing, Final_OFDM_Swing_Index = %d\n",
  1384. final_ofdm_swing_index);
  1385. /*If TxAGC has changed, reset TxAGC again*/
  1386. if (rtldm->modify_txagc_flag_path_a) {
  1387. rtldm->remnant_cck_idx = 0;
  1388. rtldm->remnant_ofdm_swing_idx[rf_path] = 0;
  1389. /*Set TxAGC Page C{};*/
  1390. rtl8821ae_phy_set_txpower_level_by_path(hw,
  1391. rtlphy->current_channel, RF90_PATH_A);
  1392. rtldm->modify_txagc_flag_path_a = false;
  1393. RT_TRACE(rtlpriv, COMP_POWER_TRACKING,
  1394. DBG_LOUD,
  1395. "******Path_A pDM_Odm->Modify_TxAGC_Flag = FALSE\n");
  1396. }
  1397. }
  1398. }
  1399. /*BBSwing higher then Limit*/
  1400. if (rf_path == RF90_PATH_B) {
  1401. if (final_ofdm_swing_index > pwr_tracking_limit) {
  1402. rtldm->remnant_ofdm_swing_idx[rf_path] =
  1403. final_ofdm_swing_index -
  1404. pwr_tracking_limit;
  1405. rtl_set_bbreg(hw, RB_TXSCALE,
  1406. 0xFFE00000,
  1407. txscaling_tbl[pwr_tracking_limit]);
  1408. rtldm->modify_txagc_flag_path_b = true;
  1409. /*Set TxAGC Page E{};*/
  1410. rtl8821ae_phy_set_txpower_level_by_path(hw,
  1411. rtlphy->current_channel, RF90_PATH_B);
  1412. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  1413. "******Path_B Over BBSwing Limit , PwrTrackingLimit = %d , Remnant TxAGC Value = %d\n",
  1414. pwr_tracking_limit,
  1415. rtldm->remnant_ofdm_swing_idx[rf_path]);
  1416. } else if (final_ofdm_swing_index < 0) {
  1417. rtldm->remnant_ofdm_swing_idx[rf_path] =
  1418. final_ofdm_swing_index;
  1419. rtl_set_bbreg(hw, RB_TXSCALE, 0xFFE00000,
  1420. txscaling_tbl[0]);
  1421. rtldm->modify_txagc_flag_path_b = true;
  1422. /*Set TxAGC Page E{};*/
  1423. rtl8821ae_phy_set_txpower_level_by_path(hw,
  1424. rtlphy->current_channel, RF90_PATH_B);
  1425. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  1426. "******Path_B Lower then BBSwing lower bound 0 , Remnant TxAGC Value = %d\n",
  1427. rtldm->remnant_ofdm_swing_idx[rf_path]);
  1428. } else {
  1429. rtl_set_bbreg(hw, RB_TXSCALE, 0xFFE00000,
  1430. txscaling_tbl[(u8)final_ofdm_swing_index]);
  1431. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  1432. "******Path_B Compensate with BBSwing ,Final_OFDM_Swing_Index = %d\n",
  1433. final_ofdm_swing_index);
  1434. /*If TxAGC has changed, reset TxAGC again*/
  1435. if (rtldm->modify_txagc_flag_path_b) {
  1436. rtldm->remnant_ofdm_swing_idx[rf_path] = 0;
  1437. /*Set TxAGC Page E{};*/
  1438. rtl8821ae_phy_set_txpower_level_by_path(hw,
  1439. rtlphy->current_channel, RF90_PATH_B);
  1440. rtldm->modify_txagc_flag_path_b =
  1441. false;
  1442. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  1443. "******Path_B pDM_Odm->Modify_TxAGC_Flag = FALSE\n");
  1444. }
  1445. }
  1446. }
  1447. } else {
  1448. return;
  1449. }
  1450. }
  1451. void rtl8812ae_dm_txpower_tracking_callback_thermalmeter(
  1452. struct ieee80211_hw *hw)
  1453. {
  1454. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1455. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  1456. struct rtl_dm *rtldm = rtl_dm(rtl_priv(hw));
  1457. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1458. u8 thermal_value = 0, delta, delta_lck, delta_iqk, p = 0, i = 0;
  1459. u8 thermal_value_avg_count = 0;
  1460. u32 thermal_value_avg = 0;
  1461. /* OFDM BB Swing should be less than +3.0dB, */
  1462. u8 ofdm_min_index = 6;
  1463. /* GetRightChnlPlaceforIQK(pHalData->CurrentChannel)*/
  1464. u8 index_for_channel = 0;
  1465. /* 1. The following TWO tables decide
  1466. * the final index of OFDM/CCK swing table.
  1467. */
  1468. u8 *delta_swing_table_idx_tup_a;
  1469. u8 *delta_swing_table_idx_tdown_a;
  1470. u8 *delta_swing_table_idx_tup_b;
  1471. u8 *delta_swing_table_idx_tdown_b;
  1472. /*2. Initilization ( 7 steps in total )*/
  1473. rtl8812ae_get_delta_swing_table(hw,
  1474. (u8 **)&delta_swing_table_idx_tup_a,
  1475. (u8 **)&delta_swing_table_idx_tdown_a,
  1476. (u8 **)&delta_swing_table_idx_tup_b,
  1477. (u8 **)&delta_swing_table_idx_tdown_b);
  1478. rtldm->txpower_trackinginit = true;
  1479. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  1480. "pDM_Odm->BbSwingIdxCckBase: %d, pDM_Odm->BbSwingIdxOfdmBase[A]:%d, pDM_Odm->DefaultOfdmIndex: %d\n",
  1481. rtldm->swing_idx_cck_base,
  1482. rtldm->swing_idx_ofdm_base[RF90_PATH_A],
  1483. rtldm->default_ofdm_index);
  1484. thermal_value = (u8)rtl_get_rfreg(hw, RF90_PATH_A,
  1485. /*0x42: RF Reg[15:10] 88E*/
  1486. RF_T_METER_8812A, 0xfc00);
  1487. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  1488. "Thermal Meter = 0x%X, EFUSE Thermal Base = 0x%X\n",
  1489. thermal_value, rtlefuse->eeprom_thermalmeter);
  1490. if (!rtldm->txpower_track_control ||
  1491. rtlefuse->eeprom_thermalmeter == 0 ||
  1492. rtlefuse->eeprom_thermalmeter == 0xFF)
  1493. return;
  1494. /* 3. Initialize ThermalValues of RFCalibrateInfo*/
  1495. if (rtlhal->reloadtxpowerindex)
  1496. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  1497. "reload ofdm index for band switch\n");
  1498. /*4. Calculate average thermal meter*/
  1499. rtldm->thermalvalue_avg[rtldm->thermalvalue_avg_index] = thermal_value;
  1500. rtldm->thermalvalue_avg_index++;
  1501. if (rtldm->thermalvalue_avg_index == AVG_THERMAL_NUM_8812A)
  1502. /*Average times = c.AverageThermalNum*/
  1503. rtldm->thermalvalue_avg_index = 0;
  1504. for (i = 0; i < AVG_THERMAL_NUM_8812A; i++) {
  1505. if (rtldm->thermalvalue_avg[i]) {
  1506. thermal_value_avg += rtldm->thermalvalue_avg[i];
  1507. thermal_value_avg_count++;
  1508. }
  1509. }
  1510. /*Calculate Average ThermalValue after average enough times*/
  1511. if (thermal_value_avg_count) {
  1512. thermal_value = (u8)(thermal_value_avg /
  1513. thermal_value_avg_count);
  1514. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  1515. "AVG Thermal Meter = 0x%X, EFUSE Thermal Base = 0x%X\n",
  1516. thermal_value, rtlefuse->eeprom_thermalmeter);
  1517. }
  1518. /*5. Calculate delta, delta_LCK, delta_IQK.
  1519. *"delta" here is used to determine whether
  1520. *thermal value changes or not.
  1521. */
  1522. delta = (thermal_value > rtldm->thermalvalue) ?
  1523. (thermal_value - rtldm->thermalvalue) :
  1524. (rtldm->thermalvalue - thermal_value);
  1525. delta_lck = (thermal_value > rtldm->thermalvalue_lck) ?
  1526. (thermal_value - rtldm->thermalvalue_lck) :
  1527. (rtldm->thermalvalue_lck - thermal_value);
  1528. delta_iqk = (thermal_value > rtldm->thermalvalue_iqk) ?
  1529. (thermal_value - rtldm->thermalvalue_iqk) :
  1530. (rtldm->thermalvalue_iqk - thermal_value);
  1531. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  1532. "(delta, delta_LCK, delta_IQK) = (%d, %d, %d)\n",
  1533. delta, delta_lck, delta_iqk);
  1534. /* 6. If necessary, do LCK.
  1535. * Delta temperature is equal to or larger than 20 centigrade.
  1536. */
  1537. if (delta_lck >= IQK_THRESHOLD) {
  1538. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  1539. "delta_LCK(%d) >= Threshold_IQK(%d)\n",
  1540. delta_lck, IQK_THRESHOLD);
  1541. rtldm->thermalvalue_lck = thermal_value;
  1542. rtl8821ae_phy_lc_calibrate(hw);
  1543. }
  1544. /*7. If necessary, move the index of swing table to adjust Tx power.*/
  1545. if (delta > 0 && rtldm->txpower_track_control) {
  1546. /* "delta" here is used to record the
  1547. * absolute value of differrence.
  1548. */
  1549. delta = thermal_value > rtlefuse->eeprom_thermalmeter ?
  1550. (thermal_value - rtlefuse->eeprom_thermalmeter) :
  1551. (rtlefuse->eeprom_thermalmeter - thermal_value);
  1552. if (delta >= TXPWR_TRACK_TABLE_SIZE)
  1553. delta = TXPWR_TRACK_TABLE_SIZE - 1;
  1554. /*7.1 The Final Power Index = BaseIndex + PowerIndexOffset*/
  1555. if (thermal_value > rtlefuse->eeprom_thermalmeter) {
  1556. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  1557. "delta_swing_table_idx_tup_a[%d] = %d\n",
  1558. delta, delta_swing_table_idx_tup_a[delta]);
  1559. rtldm->delta_power_index_last[RF90_PATH_A] =
  1560. rtldm->delta_power_index[RF90_PATH_A];
  1561. rtldm->delta_power_index[RF90_PATH_A] =
  1562. delta_swing_table_idx_tup_a[delta];
  1563. rtldm->absolute_ofdm_swing_idx[RF90_PATH_A] =
  1564. delta_swing_table_idx_tup_a[delta];
  1565. /*Record delta swing for mix mode power tracking*/
  1566. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  1567. "******Temp is higher and pDM_Odm->Aboslute_OFDMSwingIdx[ODM_RF_PATH_A] = %d\n",
  1568. rtldm->absolute_ofdm_swing_idx[RF90_PATH_A]);
  1569. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  1570. "delta_swing_table_idx_tup_b[%d] = %d\n",
  1571. delta, delta_swing_table_idx_tup_b[delta]);
  1572. rtldm->delta_power_index_last[RF90_PATH_B] =
  1573. rtldm->delta_power_index[RF90_PATH_B];
  1574. rtldm->delta_power_index[RF90_PATH_B] =
  1575. delta_swing_table_idx_tup_b[delta];
  1576. rtldm->absolute_ofdm_swing_idx[RF90_PATH_B] =
  1577. delta_swing_table_idx_tup_b[delta];
  1578. /*Record delta swing for mix mode power tracking*/
  1579. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  1580. "******Temp is higher and pDM_Odm->Aboslute_OFDMSwingIdx[ODM_RF_PATH_B] = %d\n",
  1581. rtldm->absolute_ofdm_swing_idx[RF90_PATH_B]);
  1582. } else {
  1583. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  1584. "delta_swing_table_idx_tdown_a[%d] = %d\n",
  1585. delta, delta_swing_table_idx_tdown_a[delta]);
  1586. rtldm->delta_power_index_last[RF90_PATH_A] =
  1587. rtldm->delta_power_index[RF90_PATH_A];
  1588. rtldm->delta_power_index[RF90_PATH_A] =
  1589. -1 * delta_swing_table_idx_tdown_a[delta];
  1590. rtldm->absolute_ofdm_swing_idx[RF90_PATH_A] =
  1591. -1 * delta_swing_table_idx_tdown_a[delta];
  1592. /* Record delta swing for mix mode power tracking*/
  1593. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  1594. "******Temp is lower and pDM_Odm->Aboslute_OFDMSwingIdx[ODM_RF_PATH_A] = %d\n",
  1595. rtldm->absolute_ofdm_swing_idx[RF90_PATH_A]);
  1596. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  1597. "deltaSwingTableIdx_TDOWN_B[%d] = %d\n",
  1598. delta, delta_swing_table_idx_tdown_b[delta]);
  1599. rtldm->delta_power_index_last[RF90_PATH_B] =
  1600. rtldm->delta_power_index[RF90_PATH_B];
  1601. rtldm->delta_power_index[RF90_PATH_B] =
  1602. -1 * delta_swing_table_idx_tdown_b[delta];
  1603. rtldm->absolute_ofdm_swing_idx[RF90_PATH_B] =
  1604. -1 * delta_swing_table_idx_tdown_b[delta];
  1605. /*Record delta swing for mix mode power tracking*/
  1606. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  1607. "******Temp is lower and pDM_Odm->Aboslute_OFDMSwingIdx[ODM_RF_PATH_B] = %d\n",
  1608. rtldm->absolute_ofdm_swing_idx[RF90_PATH_B]);
  1609. }
  1610. for (p = RF90_PATH_A; p < MAX_PATH_NUM_8812A; p++) {
  1611. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  1612. "============================= [Path-%c]Calculating PowerIndexOffset =============================\n",
  1613. (p == RF90_PATH_A ? 'A' : 'B'));
  1614. if (rtldm->delta_power_index[p] ==
  1615. rtldm->delta_power_index_last[p])
  1616. /*If Thermal value changes but lookup
  1617. table value still the same*/
  1618. rtldm->power_index_offset[p] = 0;
  1619. else
  1620. rtldm->power_index_offset[p] =
  1621. rtldm->delta_power_index[p] -
  1622. rtldm->delta_power_index_last[p];
  1623. /* Power Index Diff between 2
  1624. * times Power Tracking
  1625. */
  1626. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  1627. "[Path-%c] PowerIndexOffset(%d) =DeltaPowerIndex(%d) -DeltaPowerIndexLast(%d)\n",
  1628. (p == RF90_PATH_A ? 'A' : 'B'),
  1629. rtldm->power_index_offset[p],
  1630. rtldm->delta_power_index[p] ,
  1631. rtldm->delta_power_index_last[p]);
  1632. rtldm->ofdm_index[p] =
  1633. rtldm->swing_idx_ofdm_base[p] +
  1634. rtldm->power_index_offset[p];
  1635. rtldm->cck_index =
  1636. rtldm->swing_idx_cck_base +
  1637. rtldm->power_index_offset[p];
  1638. rtldm->swing_idx_cck = rtldm->cck_index;
  1639. rtldm->swing_idx_ofdm[p] = rtldm->ofdm_index[p];
  1640. /****Print BB Swing Base and Index Offset */
  1641. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  1642. "The 'CCK' final index(%d) = BaseIndex(%d) + PowerIndexOffset(%d)\n",
  1643. rtldm->swing_idx_cck,
  1644. rtldm->swing_idx_cck_base,
  1645. rtldm->power_index_offset[p]);
  1646. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  1647. "The 'OFDM' final index(%d) = BaseIndex[%c](%d) + PowerIndexOffset(%d)\n",
  1648. rtldm->swing_idx_ofdm[p],
  1649. (p == RF90_PATH_A ? 'A' : 'B'),
  1650. rtldm->swing_idx_ofdm_base[p],
  1651. rtldm->power_index_offset[p]);
  1652. /*7.1 Handle boundary conditions of index.*/
  1653. if (rtldm->ofdm_index[p] > TXSCALE_TABLE_SIZE - 1)
  1654. rtldm->ofdm_index[p] = TXSCALE_TABLE_SIZE - 1;
  1655. else if (rtldm->ofdm_index[p] < ofdm_min_index)
  1656. rtldm->ofdm_index[p] = ofdm_min_index;
  1657. }
  1658. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  1659. "\n\n====================================================================================\n");
  1660. if (rtldm->cck_index > TXSCALE_TABLE_SIZE - 1)
  1661. rtldm->cck_index = TXSCALE_TABLE_SIZE - 1;
  1662. else if (rtldm->cck_index < 0)
  1663. rtldm->cck_index = 0;
  1664. } else {
  1665. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  1666. "The thermal meter is unchanged or TxPowerTracking OFF(%d): ThermalValue: %d , pDM_Odm->RFCalibrateInfo.ThermalValue: %d\n",
  1667. rtldm->txpower_track_control,
  1668. thermal_value,
  1669. rtldm->thermalvalue);
  1670. for (p = RF90_PATH_A; p < MAX_PATH_NUM_8812A; p++)
  1671. rtldm->power_index_offset[p] = 0;
  1672. }
  1673. /*Print Swing base & current*/
  1674. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  1675. "TxPowerTracking: [CCK] Swing Current Index: %d,Swing Base Index: %d\n",
  1676. rtldm->cck_index, rtldm->swing_idx_cck_base);
  1677. for (p = RF90_PATH_A; p < MAX_PATH_NUM_8812A; p++) {
  1678. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  1679. "TxPowerTracking: [OFDM] Swing Current Index: %d,Swing Base Index[%c]: %d\n",
  1680. rtldm->ofdm_index[p],
  1681. (p == RF90_PATH_A ? 'A' : 'B'),
  1682. rtldm->swing_idx_ofdm_base[p]);
  1683. }
  1684. if ((rtldm->power_index_offset[RF90_PATH_A] != 0 ||
  1685. rtldm->power_index_offset[RF90_PATH_B] != 0) &&
  1686. rtldm->txpower_track_control) {
  1687. /*7.2 Configure the Swing Table to adjust Tx Power.
  1688. *Always TRUE after Tx Power is adjusted by power tracking.
  1689. *
  1690. *2012/04/23 MH According to Luke's suggestion,
  1691. *we can not write BB digital
  1692. *to increase TX power. Otherwise, EVM will be bad.
  1693. *
  1694. *2012/04/25 MH Add for tx power tracking to set
  1695. *tx power in tx agc for 88E.
  1696. */
  1697. if (thermal_value > rtldm->thermalvalue) {
  1698. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  1699. "Temperature Increasing(A): delta_pi: %d , delta_t: %d, Now_t: %d,EFUSE_t: %d, Last_t: %d\n",
  1700. rtldm->power_index_offset[RF90_PATH_A],
  1701. delta, thermal_value,
  1702. rtlefuse->eeprom_thermalmeter,
  1703. rtldm->thermalvalue);
  1704. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  1705. "Temperature Increasing(B): delta_pi: %d ,delta_t: %d, Now_t: %d, EFUSE_t: %d, Last_t: %d\n",
  1706. rtldm->power_index_offset[RF90_PATH_B],
  1707. delta, thermal_value,
  1708. rtlefuse->eeprom_thermalmeter,
  1709. rtldm->thermalvalue);
  1710. } else if (thermal_value < rtldm->thermalvalue) { /*Low temperature*/
  1711. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  1712. "Temperature Decreasing(A): delta_pi: %d , delta_t: %d, Now_t: %d, EFUSE_t: %d, Last_t: %d\n",
  1713. rtldm->power_index_offset[RF90_PATH_A],
  1714. delta, thermal_value,
  1715. rtlefuse->eeprom_thermalmeter,
  1716. rtldm->thermalvalue);
  1717. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  1718. "Temperature Decreasing(B): delta_pi: %d , delta_t: %d, Now_t: %d, EFUSE_t: %d, Last_t: %d\n",
  1719. rtldm->power_index_offset[RF90_PATH_B],
  1720. delta, thermal_value,
  1721. rtlefuse->eeprom_thermalmeter,
  1722. rtldm->thermalvalue);
  1723. }
  1724. if (thermal_value > rtlefuse->eeprom_thermalmeter) {
  1725. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  1726. "Temperature(%d) higher than PG value(%d)\n",
  1727. thermal_value, rtlefuse->eeprom_thermalmeter);
  1728. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  1729. "**********Enter POWER Tracking MIX_MODE**********\n");
  1730. for (p = RF90_PATH_A; p < MAX_PATH_NUM_8812A; p++)
  1731. rtl8812ae_dm_txpwr_track_set_pwr(hw, MIX_MODE,
  1732. p, 0);
  1733. } else {
  1734. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  1735. "Temperature(%d) lower than PG value(%d)\n",
  1736. thermal_value, rtlefuse->eeprom_thermalmeter);
  1737. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  1738. "**********Enter POWER Tracking MIX_MODE**********\n");
  1739. for (p = RF90_PATH_A; p < MAX_PATH_NUM_8812A; p++)
  1740. rtl8812ae_dm_txpwr_track_set_pwr(hw, MIX_MODE,
  1741. p, index_for_channel);
  1742. }
  1743. /*Record last time Power Tracking result as base.*/
  1744. rtldm->swing_idx_cck_base = rtldm->swing_idx_cck;
  1745. for (p = RF90_PATH_A; p < MAX_PATH_NUM_8812A; p++)
  1746. rtldm->swing_idx_ofdm_base[p] =
  1747. rtldm->swing_idx_ofdm[p];
  1748. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  1749. "pDM_Odm->RFCalibrateInfo.ThermalValue =%d ThermalValue= %d\n",
  1750. rtldm->thermalvalue, thermal_value);
  1751. /*Record last Power Tracking Thermal Value*/
  1752. rtldm->thermalvalue = thermal_value;
  1753. }
  1754. /*Delta temperature is equal to or larger than
  1755. 20 centigrade (When threshold is 8).*/
  1756. if (delta_iqk >= IQK_THRESHOLD)
  1757. rtl8812ae_do_iqk(hw, delta_iqk, thermal_value, 8);
  1758. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  1759. "<===rtl8812ae_dm_txpower_tracking_callback_thermalmeter\n");
  1760. }
  1761. static void rtl8821ae_get_delta_swing_table(struct ieee80211_hw *hw, u8 **up_a,
  1762. u8 **down_a, u8 **up_b, u8 **down_b)
  1763. {
  1764. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1765. struct rtl_phy *rtlphy = &rtlpriv->phy;
  1766. struct rtl_dm *rtldm = rtl_dm(rtl_priv(hw));
  1767. u8 channel = rtlphy->current_channel;
  1768. u8 rate = rtldm->tx_rate;
  1769. if (1 <= channel && channel <= 14) {
  1770. if (RTL8821AE_RX_HAL_IS_CCK_RATE(rate)) {
  1771. *up_a = rtl8821ae_delta_swing_table_idx_24gccka_p;
  1772. *down_a = rtl8821ae_delta_swing_table_idx_24gccka_n;
  1773. *up_b = rtl8821ae_delta_swing_table_idx_24gcckb_p;
  1774. *down_b = rtl8821ae_delta_swing_table_idx_24gcckb_n;
  1775. } else {
  1776. *up_a = rtl8821ae_delta_swing_table_idx_24ga_p;
  1777. *down_a = rtl8821ae_delta_swing_table_idx_24ga_n;
  1778. *up_b = rtl8821ae_delta_swing_table_idx_24gb_p;
  1779. *down_b = rtl8821ae_delta_swing_table_idx_24gb_n;
  1780. }
  1781. } else if (36 <= channel && channel <= 64) {
  1782. *up_a = rtl8821ae_delta_swing_table_idx_5ga_p[0];
  1783. *down_a = rtl8821ae_delta_swing_table_idx_5ga_n[0];
  1784. *up_b = rtl8821ae_delta_swing_table_idx_5gb_p[0];
  1785. *down_b = rtl8821ae_delta_swing_table_idx_5gb_n[0];
  1786. } else if (100 <= channel && channel <= 140) {
  1787. *up_a = rtl8821ae_delta_swing_table_idx_5ga_p[1];
  1788. *down_a = rtl8821ae_delta_swing_table_idx_5ga_n[1];
  1789. *up_b = rtl8821ae_delta_swing_table_idx_5gb_p[1];
  1790. *down_b = rtl8821ae_delta_swing_table_idx_5gb_n[1];
  1791. } else if (149 <= channel && channel <= 173) {
  1792. *up_a = rtl8821ae_delta_swing_table_idx_5ga_p[2];
  1793. *down_a = rtl8821ae_delta_swing_table_idx_5ga_n[2];
  1794. *up_b = rtl8821ae_delta_swing_table_idx_5gb_p[2];
  1795. *down_b = rtl8821ae_delta_swing_table_idx_5gb_n[2];
  1796. } else {
  1797. *up_a = (u8 *)rtl8818e_delta_swing_table_idx_24gb_p;
  1798. *down_a = (u8 *)rtl8818e_delta_swing_table_idx_24gb_n;
  1799. *up_b = (u8 *)rtl8818e_delta_swing_table_idx_24gb_p;
  1800. *down_b = (u8 *)rtl8818e_delta_swing_table_idx_24gb_n;
  1801. }
  1802. return;
  1803. }
  1804. /*-----------------------------------------------------------------------------
  1805. * Function: odm_TxPwrTrackSetPwr88E()
  1806. *
  1807. * Overview: 88E change all channel tx power accordign to flag.
  1808. * OFDM & CCK are all different.
  1809. *
  1810. * Input: NONE
  1811. *
  1812. * Output: NONE
  1813. *
  1814. * Return: NONE
  1815. *
  1816. * Revised History:
  1817. * When Who Remark
  1818. * 04/23/2012 MHC Create Version 0.
  1819. *
  1820. *---------------------------------------------------------------------------
  1821. */
  1822. void rtl8821ae_dm_txpwr_track_set_pwr(struct ieee80211_hw *hw,
  1823. enum pwr_track_control_method method,
  1824. u8 rf_path, u8 channel_mapped_index)
  1825. {
  1826. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1827. struct rtl_dm *rtldm = rtl_dm(rtl_priv(hw));
  1828. struct rtl_phy *rtlphy = &rtlpriv->phy;
  1829. u32 final_swing_idx[1];
  1830. u8 pwr_tracking_limit = 26; /*+1.0dB*/
  1831. u8 tx_rate = 0xFF;
  1832. char final_ofdm_swing_index = 0;
  1833. if (rtldm->tx_rate != 0xFF)
  1834. tx_rate = rtl8821ae_hw_rate_to_mrate(hw, rtldm->tx_rate);
  1835. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD, "===>%s\n", __func__);
  1836. if (tx_rate != 0xFF) { /* Mimic Modify High Rate BBSwing Limit.*/
  1837. /*CCK*/
  1838. if ((tx_rate >= MGN_1M) && (tx_rate <= MGN_11M))
  1839. pwr_tracking_limit = 32; /*+4dB*/
  1840. /*OFDM*/
  1841. else if ((tx_rate >= MGN_6M) && (tx_rate <= MGN_48M))
  1842. pwr_tracking_limit = 30; /*+3dB*/
  1843. else if (tx_rate == MGN_54M)
  1844. pwr_tracking_limit = 28; /*+2dB*/
  1845. /*HT*/
  1846. /*QPSK/BPSK*/
  1847. else if ((tx_rate >= MGN_MCS0) && (tx_rate <= MGN_MCS2))
  1848. pwr_tracking_limit = 34; /*+5dB*/
  1849. /*16QAM*/
  1850. else if ((tx_rate >= MGN_MCS3) && (tx_rate <= MGN_MCS4))
  1851. pwr_tracking_limit = 30; /*+3dB*/
  1852. /*64QAM*/
  1853. else if ((tx_rate >= MGN_MCS5) && (tx_rate <= MGN_MCS7))
  1854. pwr_tracking_limit = 28; /*+2dB*/
  1855. /*2 VHT*/
  1856. /*QPSK/BPSK*/
  1857. else if ((tx_rate >= MGN_VHT1SS_MCS0) &&
  1858. (tx_rate <= MGN_VHT1SS_MCS2))
  1859. pwr_tracking_limit = 34; /*+5dB*/
  1860. /*16QAM*/
  1861. else if ((tx_rate >= MGN_VHT1SS_MCS3) &&
  1862. (tx_rate <= MGN_VHT1SS_MCS4))
  1863. pwr_tracking_limit = 30; /*+3dB*/
  1864. /*64QAM*/
  1865. else if ((tx_rate >= MGN_VHT1SS_MCS5) &&
  1866. (tx_rate <= MGN_VHT1SS_MCS6))
  1867. pwr_tracking_limit = 28; /*+2dB*/
  1868. else if (tx_rate == MGN_VHT1SS_MCS7) /*64QAM*/
  1869. pwr_tracking_limit = 26; /*+1dB*/
  1870. else if (tx_rate == MGN_VHT1SS_MCS8) /*256QAM*/
  1871. pwr_tracking_limit = 24; /*+0dB*/
  1872. else if (tx_rate == MGN_VHT1SS_MCS9) /*256QAM*/
  1873. pwr_tracking_limit = 22; /*-1dB*/
  1874. else
  1875. pwr_tracking_limit = 24;
  1876. }
  1877. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  1878. "TxRate=0x%x, PwrTrackingLimit=%d\n",
  1879. tx_rate, pwr_tracking_limit);
  1880. if (method == BBSWING) {
  1881. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  1882. "===>%s\n", __func__);
  1883. if (rf_path == RF90_PATH_A) {
  1884. final_swing_idx[RF90_PATH_A] =
  1885. (rtldm->ofdm_index[RF90_PATH_A] >
  1886. pwr_tracking_limit) ?
  1887. pwr_tracking_limit :
  1888. rtldm->ofdm_index[RF90_PATH_A];
  1889. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  1890. "pDM_Odm->RFCalibrateInfo.OFDM_index[ODM_RF_PATH_A]=%d,pDM_Odm->RealBbSwingIdx[ODM_RF_PATH_A]=%d\n",
  1891. rtldm->ofdm_index[RF90_PATH_A],
  1892. final_swing_idx[RF90_PATH_A]);
  1893. rtl_set_bbreg(hw, RA_TXSCALE, 0xFFE00000,
  1894. txscaling_tbl[final_swing_idx[RF90_PATH_A]]);
  1895. }
  1896. } else if (method == MIX_MODE) {
  1897. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  1898. "pDM_Odm->DefaultOfdmIndex=%d,pDM_Odm->Aboslute_OFDMSwingIdx[RFPath]=%d, RF_Path = %d\n",
  1899. rtldm->default_ofdm_index,
  1900. rtldm->absolute_ofdm_swing_idx[rf_path],
  1901. rf_path);
  1902. final_ofdm_swing_index =
  1903. rtldm->default_ofdm_index +
  1904. rtldm->absolute_ofdm_swing_idx[rf_path];
  1905. /*BBSwing higher then Limit*/
  1906. if (rf_path == RF90_PATH_A) {
  1907. if (final_ofdm_swing_index > pwr_tracking_limit) {
  1908. rtldm->remnant_cck_idx =
  1909. final_ofdm_swing_index -
  1910. pwr_tracking_limit;
  1911. /* CCK Follow the same compensate value as Path A*/
  1912. rtldm->remnant_ofdm_swing_idx[rf_path] =
  1913. final_ofdm_swing_index -
  1914. pwr_tracking_limit;
  1915. rtl_set_bbreg(hw, RA_TXSCALE,
  1916. 0xFFE00000,
  1917. txscaling_tbl[pwr_tracking_limit]);
  1918. rtldm->modify_txagc_flag_path_a = true;
  1919. /*Set TxAGC Page C{};*/
  1920. rtl8821ae_phy_set_txpower_level_by_path(hw,
  1921. rtlphy->current_channel,
  1922. RF90_PATH_A);
  1923. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  1924. " ******Path_A Over BBSwing Limit , PwrTrackingLimit = %d , Remnant TxAGC Value = %d\n",
  1925. pwr_tracking_limit,
  1926. rtldm->remnant_ofdm_swing_idx[rf_path]);
  1927. } else if (final_ofdm_swing_index < 0) {
  1928. rtldm->remnant_cck_idx = final_ofdm_swing_index;
  1929. /* CCK Follow the same compensate value as Path A*/
  1930. rtldm->remnant_ofdm_swing_idx[rf_path] =
  1931. final_ofdm_swing_index;
  1932. rtl_set_bbreg(hw, RA_TXSCALE, 0xFFE00000,
  1933. txscaling_tbl[0]);
  1934. rtldm->modify_txagc_flag_path_a = true;
  1935. /*Set TxAGC Page C{};*/
  1936. rtl8821ae_phy_set_txpower_level_by_path(hw,
  1937. rtlphy->current_channel, RF90_PATH_A);
  1938. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  1939. "******Path_A Lower then BBSwing lower bound 0 , Remnant TxAGC Value = %d\n",
  1940. rtldm->remnant_ofdm_swing_idx[rf_path]);
  1941. } else {
  1942. rtl_set_bbreg(hw, RA_TXSCALE, 0xFFE00000,
  1943. txscaling_tbl[(u8)final_ofdm_swing_index]);
  1944. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  1945. "******Path_A Compensate with BBSwing ,Final_OFDM_Swing_Index = %d\n",
  1946. final_ofdm_swing_index);
  1947. /*If TxAGC has changed, reset TxAGC again*/
  1948. if (rtldm->modify_txagc_flag_path_a) {
  1949. rtldm->remnant_cck_idx = 0;
  1950. rtldm->remnant_ofdm_swing_idx[rf_path] = 0;
  1951. /*Set TxAGC Page C{};*/
  1952. rtl8821ae_phy_set_txpower_level_by_path(hw,
  1953. rtlphy->current_channel, RF90_PATH_A);
  1954. rtldm->modify_txagc_flag_path_a = false;
  1955. RT_TRACE(rtlpriv, COMP_POWER_TRACKING,
  1956. DBG_LOUD,
  1957. "******Path_A pDM_Odm->Modify_TxAGC_Flag= FALSE\n");
  1958. }
  1959. }
  1960. }
  1961. } else {
  1962. return;
  1963. }
  1964. }
  1965. void rtl8821ae_dm_txpower_tracking_callback_thermalmeter(
  1966. struct ieee80211_hw *hw)
  1967. {
  1968. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1969. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  1970. struct rtl_dm *rtldm = rtl_dm(rtl_priv(hw));
  1971. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1972. struct rtl_phy *rtlphy = &rtlpriv->phy;
  1973. u8 thermal_value = 0, delta, delta_lck, delta_iqk, p = 0, i = 0;
  1974. u8 thermal_value_avg_count = 0;
  1975. u32 thermal_value_avg = 0;
  1976. u8 ofdm_min_index = 6; /*OFDM BB Swing should be less than +3.0dB */
  1977. /* GetRightChnlPlaceforIQK(pHalData->CurrentChannel)*/
  1978. u8 index_for_channel = 0;
  1979. /* 1. The following TWO tables decide the final
  1980. * index of OFDM/CCK swing table.
  1981. */
  1982. u8 *delta_swing_table_idx_tup_a;
  1983. u8 *delta_swing_table_idx_tdown_a;
  1984. u8 *delta_swing_table_idx_tup_b;
  1985. u8 *delta_swing_table_idx_tdown_b;
  1986. /*2. Initilization ( 7 steps in total )*/
  1987. rtl8821ae_get_delta_swing_table(hw, (u8 **)&delta_swing_table_idx_tup_a,
  1988. (u8 **)&delta_swing_table_idx_tdown_a,
  1989. (u8 **)&delta_swing_table_idx_tup_b,
  1990. (u8 **)&delta_swing_table_idx_tdown_b);
  1991. rtldm->txpower_trackinginit = true;
  1992. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  1993. "===>%s,\n pDM_Odm->BbSwingIdxCckBase: %d,pDM_Odm->BbSwingIdxOfdmBase[A]:%d, pDM_Odm->DefaultOfdmIndex: %d\n",
  1994. __func__,
  1995. rtldm->swing_idx_cck_base,
  1996. rtldm->swing_idx_ofdm_base[RF90_PATH_A],
  1997. rtldm->default_ofdm_index);
  1998. /*0x42: RF Reg[15:10] 88E*/
  1999. thermal_value = (u8)rtl_get_rfreg(hw,
  2000. RF90_PATH_A, RF_T_METER_8812A, 0xfc00);
  2001. if (!rtldm->txpower_track_control ||
  2002. rtlefuse->eeprom_thermalmeter == 0 ||
  2003. rtlefuse->eeprom_thermalmeter == 0xFF)
  2004. return;
  2005. /* 3. Initialize ThermalValues of RFCalibrateInfo*/
  2006. if (rtlhal->reloadtxpowerindex) {
  2007. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  2008. "reload ofdm index for band switch\n");
  2009. }
  2010. /*4. Calculate average thermal meter*/
  2011. rtldm->thermalvalue_avg[rtldm->thermalvalue_avg_index] = thermal_value;
  2012. rtldm->thermalvalue_avg_index++;
  2013. if (rtldm->thermalvalue_avg_index == AVG_THERMAL_NUM_8812A)
  2014. /*Average times = c.AverageThermalNum*/
  2015. rtldm->thermalvalue_avg_index = 0;
  2016. for (i = 0; i < AVG_THERMAL_NUM_8812A; i++) {
  2017. if (rtldm->thermalvalue_avg[i]) {
  2018. thermal_value_avg += rtldm->thermalvalue_avg[i];
  2019. thermal_value_avg_count++;
  2020. }
  2021. }
  2022. /*Calculate Average ThermalValue after average enough times*/
  2023. if (thermal_value_avg_count) {
  2024. thermal_value = (u8)(thermal_value_avg /
  2025. thermal_value_avg_count);
  2026. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  2027. "AVG Thermal Meter = 0x%X, EFUSE Thermal Base = 0x%X\n",
  2028. thermal_value, rtlefuse->eeprom_thermalmeter);
  2029. }
  2030. /*5. Calculate delta, delta_LCK, delta_IQK.
  2031. *"delta" here is used to determine whether
  2032. * thermal value changes or not.
  2033. */
  2034. delta = (thermal_value > rtldm->thermalvalue) ?
  2035. (thermal_value - rtldm->thermalvalue) :
  2036. (rtldm->thermalvalue - thermal_value);
  2037. delta_lck = (thermal_value > rtldm->thermalvalue_lck) ?
  2038. (thermal_value - rtldm->thermalvalue_lck) :
  2039. (rtldm->thermalvalue_lck - thermal_value);
  2040. delta_iqk = (thermal_value > rtldm->thermalvalue_iqk) ?
  2041. (thermal_value - rtldm->thermalvalue_iqk) :
  2042. (rtldm->thermalvalue_iqk - thermal_value);
  2043. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  2044. "(delta, delta_LCK, delta_IQK) = (%d, %d, %d)\n",
  2045. delta, delta_lck, delta_iqk);
  2046. /* 6. If necessary, do LCK. */
  2047. /*Delta temperature is equal to or larger than 20 centigrade.*/
  2048. if (delta_lck >= IQK_THRESHOLD) {
  2049. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  2050. "delta_LCK(%d) >= Threshold_IQK(%d)\n",
  2051. delta_lck, IQK_THRESHOLD);
  2052. rtldm->thermalvalue_lck = thermal_value;
  2053. rtl8821ae_phy_lc_calibrate(hw);
  2054. }
  2055. /*7. If necessary, move the index of swing table to adjust Tx power.*/
  2056. if (delta > 0 && rtldm->txpower_track_control) {
  2057. /*"delta" here is used to record the
  2058. * absolute value of differrence.
  2059. */
  2060. delta = thermal_value > rtlefuse->eeprom_thermalmeter ?
  2061. (thermal_value - rtlefuse->eeprom_thermalmeter) :
  2062. (rtlefuse->eeprom_thermalmeter - thermal_value);
  2063. if (delta >= TXSCALE_TABLE_SIZE)
  2064. delta = TXSCALE_TABLE_SIZE - 1;
  2065. /*7.1 The Final Power Index = BaseIndex + PowerIndexOffset*/
  2066. if (thermal_value > rtlefuse->eeprom_thermalmeter) {
  2067. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  2068. "delta_swing_table_idx_tup_a[%d] = %d\n",
  2069. delta, delta_swing_table_idx_tup_a[delta]);
  2070. rtldm->delta_power_index_last[RF90_PATH_A] =
  2071. rtldm->delta_power_index[RF90_PATH_A];
  2072. rtldm->delta_power_index[RF90_PATH_A] =
  2073. delta_swing_table_idx_tup_a[delta];
  2074. rtldm->absolute_ofdm_swing_idx[RF90_PATH_A] =
  2075. delta_swing_table_idx_tup_a[delta];
  2076. /*Record delta swing for mix mode power tracking*/
  2077. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  2078. "******Temp is higher and pDM_Odm->Aboslute_OFDMSwingIdx[ODM_RF_PATH_A] = %d\n",
  2079. rtldm->absolute_ofdm_swing_idx[RF90_PATH_A]);
  2080. } else {
  2081. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  2082. "delta_swing_table_idx_tdown_a[%d] = %d\n",
  2083. delta, delta_swing_table_idx_tdown_a[delta]);
  2084. rtldm->delta_power_index_last[RF90_PATH_A] =
  2085. rtldm->delta_power_index[RF90_PATH_A];
  2086. rtldm->delta_power_index[RF90_PATH_A] =
  2087. -1 * delta_swing_table_idx_tdown_a[delta];
  2088. rtldm->absolute_ofdm_swing_idx[RF90_PATH_A] =
  2089. -1 * delta_swing_table_idx_tdown_a[delta];
  2090. /* Record delta swing for mix mode power tracking*/
  2091. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  2092. "******Temp is lower and pDM_Odm->Aboslute_OFDMSwingIdx[ODM_RF_PATH_A] = %d\n",
  2093. rtldm->absolute_ofdm_swing_idx[RF90_PATH_A]);
  2094. }
  2095. for (p = RF90_PATH_A; p < MAX_PATH_NUM_8821A; p++) {
  2096. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  2097. "\n\n================================ [Path-%c]Calculating PowerIndexOffset ================================\n",
  2098. (p == RF90_PATH_A ? 'A' : 'B'));
  2099. /*If Thermal value changes but lookup table value
  2100. * still the same
  2101. */
  2102. if (rtldm->delta_power_index[p] ==
  2103. rtldm->delta_power_index_last[p])
  2104. rtldm->power_index_offset[p] = 0;
  2105. else
  2106. rtldm->power_index_offset[p] =
  2107. rtldm->delta_power_index[p] -
  2108. rtldm->delta_power_index_last[p];
  2109. /*Power Index Diff between 2 times Power Tracking*/
  2110. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  2111. "[Path-%c] PowerIndexOffset(%d) = DeltaPowerIndex(%d) - DeltaPowerIndexLast(%d)\n",
  2112. (p == RF90_PATH_A ? 'A' : 'B'),
  2113. rtldm->power_index_offset[p],
  2114. rtldm->delta_power_index[p] ,
  2115. rtldm->delta_power_index_last[p]);
  2116. rtldm->ofdm_index[p] =
  2117. rtldm->swing_idx_ofdm_base[p] +
  2118. rtldm->power_index_offset[p];
  2119. rtldm->cck_index =
  2120. rtldm->swing_idx_cck_base +
  2121. rtldm->power_index_offset[p];
  2122. rtldm->swing_idx_cck = rtldm->cck_index;
  2123. rtldm->swing_idx_ofdm[p] = rtldm->ofdm_index[p];
  2124. /*********Print BB Swing Base and Index Offset********/
  2125. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  2126. "The 'CCK' final index(%d) = BaseIndex(%d) + PowerIndexOffset(%d)\n",
  2127. rtldm->swing_idx_cck,
  2128. rtldm->swing_idx_cck_base,
  2129. rtldm->power_index_offset[p]);
  2130. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  2131. "The 'OFDM' final index(%d) = BaseIndex[%c](%d) + PowerIndexOffset(%d)\n",
  2132. rtldm->swing_idx_ofdm[p],
  2133. (p == RF90_PATH_A ? 'A' : 'B'),
  2134. rtldm->swing_idx_ofdm_base[p],
  2135. rtldm->power_index_offset[p]);
  2136. /*7.1 Handle boundary conditions of index.*/
  2137. if (rtldm->ofdm_index[p] > TXSCALE_TABLE_SIZE - 1)
  2138. rtldm->ofdm_index[p] = TXSCALE_TABLE_SIZE - 1;
  2139. else if (rtldm->ofdm_index[p] < ofdm_min_index)
  2140. rtldm->ofdm_index[p] = ofdm_min_index;
  2141. }
  2142. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  2143. "\n\n========================================================================================================\n");
  2144. if (rtldm->cck_index > TXSCALE_TABLE_SIZE - 1)
  2145. rtldm->cck_index = TXSCALE_TABLE_SIZE - 1;
  2146. else if (rtldm->cck_index < 0)
  2147. rtldm->cck_index = 0;
  2148. } else {
  2149. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  2150. "The thermal meter is unchanged or TxPowerTracking OFF(%d):ThermalValue: %d , pDM_Odm->RFCalibrateInfo.ThermalValue: %d\n",
  2151. rtldm->txpower_track_control,
  2152. thermal_value,
  2153. rtldm->thermalvalue);
  2154. for (p = RF90_PATH_A; p < MAX_PATH_NUM_8821A; p++)
  2155. rtldm->power_index_offset[p] = 0;
  2156. }
  2157. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  2158. "TxPowerTracking: [CCK] Swing Current Index: %d, Swing Base Index: %d\n",
  2159. /*Print Swing base & current*/
  2160. rtldm->cck_index, rtldm->swing_idx_cck_base);
  2161. for (p = RF90_PATH_A; p < MAX_PATH_NUM_8821A; p++) {
  2162. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  2163. "TxPowerTracking: [OFDM] Swing Current Index: %d, Swing Base Index[%c]: %d\n",
  2164. rtldm->ofdm_index[p],
  2165. (p == RF90_PATH_A ? 'A' : 'B'),
  2166. rtldm->swing_idx_ofdm_base[p]);
  2167. }
  2168. if ((rtldm->power_index_offset[RF90_PATH_A] != 0 ||
  2169. rtldm->power_index_offset[RF90_PATH_B] != 0) &&
  2170. rtldm->txpower_track_control) {
  2171. /*7.2 Configure the Swing Table to adjust Tx Power.*/
  2172. /*Always TRUE after Tx Power is adjusted by power tracking.*/
  2173. /*
  2174. * 2012/04/23 MH According to Luke's suggestion,
  2175. * we can not write BB digital
  2176. * to increase TX power. Otherwise, EVM will be bad.
  2177. *
  2178. * 2012/04/25 MH Add for tx power tracking to
  2179. * set tx power in tx agc for 88E.
  2180. */
  2181. if (thermal_value > rtldm->thermalvalue) {
  2182. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  2183. "Temperature Increasing(A): delta_pi: %d , delta_t: %d,Now_t: %d, EFUSE_t: %d, Last_t: %d\n",
  2184. rtldm->power_index_offset[RF90_PATH_A],
  2185. delta, thermal_value,
  2186. rtlefuse->eeprom_thermalmeter,
  2187. rtldm->thermalvalue);
  2188. } else if (thermal_value < rtldm->thermalvalue) { /*Low temperature*/
  2189. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  2190. "Temperature Decreasing(A): delta_pi: %d , delta_t: %d, Now_t: %d, EFUSE_t: %d, Last_t: %d\n",
  2191. rtldm->power_index_offset[RF90_PATH_A],
  2192. delta, thermal_value,
  2193. rtlefuse->eeprom_thermalmeter,
  2194. rtldm->thermalvalue);
  2195. }
  2196. if (thermal_value > rtlefuse->eeprom_thermalmeter) {
  2197. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  2198. "Temperature(%d) higher than PG value(%d)\n",
  2199. thermal_value, rtlefuse->eeprom_thermalmeter);
  2200. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  2201. "****Enter POWER Tracking MIX_MODE****\n");
  2202. for (p = RF90_PATH_A; p < MAX_PATH_NUM_8821A; p++)
  2203. rtl8821ae_dm_txpwr_track_set_pwr(hw,
  2204. MIX_MODE, p, index_for_channel);
  2205. } else {
  2206. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  2207. "Temperature(%d) lower than PG value(%d)\n",
  2208. thermal_value, rtlefuse->eeprom_thermalmeter);
  2209. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  2210. "*****Enter POWER Tracking MIX_MODE*****\n");
  2211. for (p = RF90_PATH_A; p < MAX_PATH_NUM_8821A; p++)
  2212. rtl8812ae_dm_txpwr_track_set_pwr(hw,
  2213. MIX_MODE, p, index_for_channel);
  2214. }
  2215. /*Record last time Power Tracking result as base.*/
  2216. rtldm->swing_idx_cck_base = rtldm->swing_idx_cck;
  2217. for (p = RF90_PATH_A; p < MAX_PATH_NUM_8821A; p++)
  2218. rtldm->swing_idx_ofdm_base[p] = rtldm->swing_idx_ofdm[p];
  2219. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  2220. "pDM_Odm->RFCalibrateInfo.ThermalValue = %d ThermalValue= %d\n",
  2221. rtldm->thermalvalue, thermal_value);
  2222. /*Record last Power Tracking Thermal Value*/
  2223. rtldm->thermalvalue = thermal_value;
  2224. }
  2225. /* Delta temperature is equal to or larger than
  2226. * 20 centigrade (When threshold is 8).
  2227. */
  2228. if (delta_iqk >= IQK_THRESHOLD) {
  2229. if (!rtlphy->lck_inprogress) {
  2230. spin_lock(&rtlpriv->locks.iqk_lock);
  2231. rtlphy->lck_inprogress = true;
  2232. spin_unlock(&rtlpriv->locks.iqk_lock);
  2233. rtl8821ae_do_iqk(hw, delta_iqk, thermal_value, 8);
  2234. spin_lock(&rtlpriv->locks.iqk_lock);
  2235. rtlphy->lck_inprogress = false;
  2236. spin_unlock(&rtlpriv->locks.iqk_lock);
  2237. }
  2238. }
  2239. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD, "<===%s\n", __func__);
  2240. }
  2241. void rtl8821ae_dm_check_txpower_tracking_thermalmeter(struct ieee80211_hw *hw)
  2242. {
  2243. struct rtl_priv *rtlpriv = rtl_priv(hw);
  2244. if (!rtlpriv->dm.tm_trigger) {
  2245. rtl_set_rfreg(hw, RF90_PATH_A, RF_T_METER_88E, BIT(17)|BIT(16),
  2246. 0x03);
  2247. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  2248. "Trigger 8821ae Thermal Meter!!\n");
  2249. rtlpriv->dm.tm_trigger = 1;
  2250. return;
  2251. } else {
  2252. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  2253. "Schedule TxPowerTracking !!\n");
  2254. rtl8821ae_dm_txpower_tracking_callback_thermalmeter(hw);
  2255. rtlpriv->dm.tm_trigger = 0;
  2256. }
  2257. }
  2258. static void rtl8821ae_dm_refresh_rate_adaptive_mask(struct ieee80211_hw *hw)
  2259. {
  2260. struct rtl_priv *rtlpriv = rtl_priv(hw);
  2261. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  2262. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  2263. struct rate_adaptive *p_ra = &rtlpriv->ra;
  2264. u32 low_rssithresh_for_ra = p_ra->low2high_rssi_thresh_for_ra40m;
  2265. u32 high_rssithresh_for_ra = p_ra->high_rssi_thresh_for_ra;
  2266. u8 go_up_gap = 5;
  2267. struct ieee80211_sta *sta = NULL;
  2268. if (is_hal_stop(rtlhal)) {
  2269. RT_TRACE(rtlpriv, COMP_RATE, DBG_LOUD,
  2270. "driver is going to unload\n");
  2271. return;
  2272. }
  2273. if (!rtlpriv->dm.useramask) {
  2274. RT_TRACE(rtlpriv, COMP_RATE, DBG_LOUD,
  2275. "driver does not control rate adaptive mask\n");
  2276. return;
  2277. }
  2278. if (mac->link_state == MAC80211_LINKED &&
  2279. mac->opmode == NL80211_IFTYPE_STATION) {
  2280. switch (p_ra->pre_ratr_state) {
  2281. case DM_RATR_STA_MIDDLE:
  2282. high_rssithresh_for_ra += go_up_gap;
  2283. break;
  2284. case DM_RATR_STA_LOW:
  2285. high_rssithresh_for_ra += go_up_gap;
  2286. low_rssithresh_for_ra += go_up_gap;
  2287. break;
  2288. default:
  2289. break;
  2290. }
  2291. if (rtlpriv->dm.undec_sm_pwdb >
  2292. (long)high_rssithresh_for_ra)
  2293. p_ra->ratr_state = DM_RATR_STA_HIGH;
  2294. else if (rtlpriv->dm.undec_sm_pwdb >
  2295. (long)low_rssithresh_for_ra)
  2296. p_ra->ratr_state = DM_RATR_STA_MIDDLE;
  2297. else
  2298. p_ra->ratr_state = DM_RATR_STA_LOW;
  2299. if (p_ra->pre_ratr_state != p_ra->ratr_state) {
  2300. RT_TRACE(rtlpriv, COMP_RATE, DBG_LOUD,
  2301. "RSSI = %ld\n",
  2302. rtlpriv->dm.undec_sm_pwdb);
  2303. RT_TRACE(rtlpriv, COMP_RATE, DBG_LOUD,
  2304. "RSSI_LEVEL = %d\n", p_ra->ratr_state);
  2305. RT_TRACE(rtlpriv, COMP_RATE, DBG_LOUD,
  2306. "PreState = %d, CurState = %d\n",
  2307. p_ra->pre_ratr_state, p_ra->ratr_state);
  2308. rcu_read_lock();
  2309. sta = rtl_find_sta(hw, mac->bssid);
  2310. if (sta)
  2311. rtlpriv->cfg->ops->update_rate_tbl(hw,
  2312. sta, p_ra->ratr_state);
  2313. rcu_read_unlock();
  2314. p_ra->pre_ratr_state = p_ra->ratr_state;
  2315. }
  2316. }
  2317. }
  2318. static void rtl8821ae_dm_refresh_basic_rate_mask(struct ieee80211_hw *hw)
  2319. {
  2320. struct rtl_priv *rtlpriv = rtl_priv(hw);
  2321. struct dig_t *dm_digtable = &rtlpriv->dm_digtable;
  2322. struct rtl_mac *mac = &rtlpriv->mac80211;
  2323. static u8 stage;
  2324. u8 cur_stage = 0;
  2325. u16 basic_rate = RRSR_1M | RRSR_2M | RRSR_5_5M | RRSR_11M | RRSR_6M;
  2326. if (mac->link_state < MAC80211_LINKED)
  2327. cur_stage = 0;
  2328. else if (dm_digtable->rssi_val_min < 25)
  2329. cur_stage = 1;
  2330. else if (dm_digtable->rssi_val_min > 30)
  2331. cur_stage = 3;
  2332. else
  2333. cur_stage = 2;
  2334. if (cur_stage != stage) {
  2335. if (cur_stage == 1) {
  2336. basic_rate &= (!(basic_rate ^ mac->basic_rates));
  2337. rtlpriv->cfg->ops->set_hw_reg(hw,
  2338. HW_VAR_BASIC_RATE, (u8 *)&basic_rate);
  2339. } else if (cur_stage == 3 && (stage == 1 || stage == 2)) {
  2340. rtlpriv->cfg->ops->set_hw_reg(hw,
  2341. HW_VAR_BASIC_RATE, (u8 *)&mac->basic_rates);
  2342. }
  2343. }
  2344. stage = cur_stage;
  2345. }
  2346. static void rtl8821ae_dm_edca_choose_traffic_idx(
  2347. struct ieee80211_hw *hw, u64 cur_tx_bytes,
  2348. u64 cur_rx_bytes, bool b_bias_on_rx,
  2349. bool *pb_is_cur_rdl_state)
  2350. {
  2351. struct rtl_priv *rtlpriv = rtl_priv(hw);
  2352. if (b_bias_on_rx) {
  2353. if (cur_tx_bytes > (cur_rx_bytes*4)) {
  2354. *pb_is_cur_rdl_state = false;
  2355. RT_TRACE(rtlpriv, COMP_TURBO, DBG_LOUD,
  2356. "Uplink Traffic\n ");
  2357. } else {
  2358. *pb_is_cur_rdl_state = true;
  2359. RT_TRACE(rtlpriv, COMP_TURBO, DBG_LOUD,
  2360. "Balance Traffic\n");
  2361. }
  2362. } else {
  2363. if (cur_rx_bytes > (cur_tx_bytes*4)) {
  2364. *pb_is_cur_rdl_state = true;
  2365. RT_TRACE(rtlpriv, COMP_TURBO, DBG_LOUD,
  2366. "Downlink Traffic\n");
  2367. } else {
  2368. *pb_is_cur_rdl_state = false;
  2369. RT_TRACE(rtlpriv, COMP_TURBO, DBG_LOUD,
  2370. "Balance Traffic\n");
  2371. }
  2372. }
  2373. return;
  2374. }
  2375. static void rtl8821ae_dm_check_edca_turbo(struct ieee80211_hw *hw)
  2376. {
  2377. struct rtl_priv *rtlpriv = rtl_priv(hw);
  2378. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  2379. struct rtl_dm *rtldm = rtl_dm(rtl_priv(hw));
  2380. /*Keep past Tx/Rx packet count for RT-to-RT EDCA turbo.*/
  2381. u64 cur_tx_ok_cnt = 0;
  2382. u64 cur_rx_ok_cnt = 0;
  2383. u32 edca_be_ul = 0x5ea42b;
  2384. u32 edca_be_dl = 0x5ea42b;
  2385. u32 edca_be = 0x5ea42b;
  2386. u8 iot_peer = 0;
  2387. bool *pb_is_cur_rdl_state = NULL;
  2388. bool b_last_is_cur_rdl_state = false;
  2389. bool b_bias_on_rx = false;
  2390. bool b_edca_turbo_on = false;
  2391. RT_TRACE(rtlpriv, COMP_TURBO, DBG_LOUD,
  2392. "rtl8821ae_dm_check_edca_turbo=====>");
  2393. RT_TRACE(rtlpriv, COMP_TURBO, DBG_LOUD,
  2394. "Orginial BE PARAM: 0x%x\n",
  2395. rtl_read_dword(rtlpriv, DM_REG_EDCA_BE_11N));
  2396. if (rtlpriv->dm.dbginfo.num_non_be_pkt > 0x100)
  2397. rtlpriv->dm.is_any_nonbepkts = true;
  2398. rtlpriv->dm.dbginfo.num_non_be_pkt = 0;
  2399. /*===============================
  2400. * list paramter for different platform
  2401. *===============================
  2402. */
  2403. b_last_is_cur_rdl_state = rtlpriv->dm.is_cur_rdlstate;
  2404. pb_is_cur_rdl_state = &rtlpriv->dm.is_cur_rdlstate;
  2405. cur_tx_ok_cnt = rtlpriv->stats.txbytesunicast - rtldm->last_tx_ok_cnt;
  2406. cur_rx_ok_cnt = rtlpriv->stats.rxbytesunicast - rtldm->last_rx_ok_cnt;
  2407. rtldm->last_tx_ok_cnt = rtlpriv->stats.txbytesunicast;
  2408. rtldm->last_rx_ok_cnt = rtlpriv->stats.rxbytesunicast;
  2409. iot_peer = rtlpriv->mac80211.vendor;
  2410. b_bias_on_rx = false;
  2411. b_edca_turbo_on = ((!rtlpriv->dm.is_any_nonbepkts) &&
  2412. (!rtlpriv->dm.disable_framebursting)) ?
  2413. true : false;
  2414. if (rtlpriv->rtlhal.hw_type != HARDWARE_TYPE_RTL8812AE) {
  2415. if ((iot_peer == PEER_CISCO) &&
  2416. (mac->mode == WIRELESS_MODE_N_24G)) {
  2417. edca_be_dl = edca_setting_dl[iot_peer];
  2418. edca_be_ul = edca_setting_ul[iot_peer];
  2419. }
  2420. }
  2421. RT_TRACE(rtlpriv, COMP_TURBO, DBG_LOUD,
  2422. "bIsAnyNonBEPkts : 0x%x bDisableFrameBursting : 0x%x\n",
  2423. rtlpriv->dm.is_any_nonbepkts,
  2424. rtlpriv->dm.disable_framebursting);
  2425. RT_TRACE(rtlpriv, COMP_TURBO, DBG_LOUD,
  2426. "bEdcaTurboOn : 0x%x bBiasOnRx : 0x%x\n",
  2427. b_edca_turbo_on, b_bias_on_rx);
  2428. if (b_edca_turbo_on) {
  2429. RT_TRACE(rtlpriv, COMP_TURBO, DBG_LOUD,
  2430. "curTxOkCnt : 0x%llx\n", cur_tx_ok_cnt);
  2431. RT_TRACE(rtlpriv, COMP_TURBO, DBG_LOUD,
  2432. "curRxOkCnt : 0x%llx\n", cur_rx_ok_cnt);
  2433. if (b_bias_on_rx)
  2434. rtl8821ae_dm_edca_choose_traffic_idx(hw, cur_tx_ok_cnt,
  2435. cur_rx_ok_cnt, true, pb_is_cur_rdl_state);
  2436. else
  2437. rtl8821ae_dm_edca_choose_traffic_idx(hw, cur_tx_ok_cnt,
  2438. cur_rx_ok_cnt, false, pb_is_cur_rdl_state);
  2439. edca_be = (*pb_is_cur_rdl_state) ? edca_be_dl : edca_be_ul;
  2440. rtl_write_dword(rtlpriv, DM_REG_EDCA_BE_11N, edca_be);
  2441. RT_TRACE(rtlpriv, COMP_TURBO, DBG_LOUD,
  2442. "EDCA Turbo on: EDCA_BE:0x%x\n", edca_be);
  2443. rtlpriv->dm.current_turbo_edca = true;
  2444. RT_TRACE(rtlpriv, COMP_TURBO, DBG_LOUD,
  2445. "EDCA_BE_DL : 0x%x EDCA_BE_UL : 0x%x EDCA_BE : 0x%x\n",
  2446. edca_be_dl, edca_be_ul, edca_be);
  2447. } else {
  2448. if (rtlpriv->dm.current_turbo_edca) {
  2449. u8 tmp = AC0_BE;
  2450. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_AC_PARAM,
  2451. (u8 *)(&tmp));
  2452. }
  2453. rtlpriv->dm.current_turbo_edca = false;
  2454. }
  2455. rtlpriv->dm.is_any_nonbepkts = false;
  2456. rtldm->last_tx_ok_cnt = rtlpriv->stats.txbytesunicast;
  2457. rtldm->last_rx_ok_cnt = rtlpriv->stats.rxbytesunicast;
  2458. }
  2459. static void rtl8821ae_dm_cck_packet_detection_thresh(struct ieee80211_hw *hw)
  2460. {
  2461. struct rtl_priv *rtlpriv = rtl_priv(hw);
  2462. struct dig_t *dm_digtable = &rtlpriv->dm_digtable;
  2463. u8 cur_cck_cca_thresh;
  2464. if (rtlpriv->mac80211.link_state >= MAC80211_LINKED) {
  2465. if (dm_digtable->rssi_val_min > 25) {
  2466. cur_cck_cca_thresh = 0xcd;
  2467. } else if ((dm_digtable->rssi_val_min <= 25) &&
  2468. (dm_digtable->rssi_val_min > 10)) {
  2469. cur_cck_cca_thresh = 0x83;
  2470. } else {
  2471. if (rtlpriv->falsealm_cnt.cnt_cck_fail > 1000)
  2472. cur_cck_cca_thresh = 0x83;
  2473. else
  2474. cur_cck_cca_thresh = 0x40;
  2475. }
  2476. } else {
  2477. if (rtlpriv->falsealm_cnt.cnt_cck_fail > 1000)
  2478. cur_cck_cca_thresh = 0x83;
  2479. else
  2480. cur_cck_cca_thresh = 0x40;
  2481. }
  2482. if (dm_digtable->cur_cck_cca_thres != cur_cck_cca_thresh)
  2483. rtl_write_byte(rtlpriv, ODM_REG_CCK_CCA_11AC,
  2484. cur_cck_cca_thresh);
  2485. dm_digtable->pre_cck_cca_thres = dm_digtable->cur_cck_cca_thres;
  2486. dm_digtable->cur_cck_cca_thres = cur_cck_cca_thresh;
  2487. RT_TRACE(rtlpriv, COMP_DIG, DBG_TRACE,
  2488. "CCK cca thresh hold =%x\n", dm_digtable->cur_cck_cca_thres);
  2489. }
  2490. static void rtl8821ae_dm_dynamic_atc_switch(struct ieee80211_hw *hw)
  2491. {
  2492. struct rtl_priv *rtlpriv = rtl_priv(hw);
  2493. struct rtl_dm *rtldm = rtl_dm(rtl_priv(hw));
  2494. u8 crystal_cap;
  2495. u32 packet_count;
  2496. int cfo_khz_a, cfo_khz_b, cfo_ave = 0, adjust_xtal = 0;
  2497. int cfo_ave_diff;
  2498. if (rtlpriv->mac80211.link_state < MAC80211_LINKED) {
  2499. /*1.Enable ATC*/
  2500. if (rtldm->atc_status == ATC_STATUS_OFF) {
  2501. rtl_set_bbreg(hw, RFC_AREA, BIT(14), ATC_STATUS_ON);
  2502. rtldm->atc_status = ATC_STATUS_ON;
  2503. }
  2504. RT_TRACE(rtlpriv, COMP_DIG, DBG_LOUD, "No link!!\n");
  2505. RT_TRACE(rtlpriv, COMP_DIG, DBG_LOUD,
  2506. "atc_status = %d\n", rtldm->atc_status);
  2507. if (rtldm->crystal_cap != rtlpriv->efuse.crystalcap) {
  2508. rtldm->crystal_cap = rtlpriv->efuse.crystalcap;
  2509. crystal_cap = rtldm->crystal_cap & 0x3f;
  2510. crystal_cap = crystal_cap & 0x3f;
  2511. if (rtlpriv->rtlhal.hw_type == HARDWARE_TYPE_RTL8812AE)
  2512. rtl_set_bbreg(hw, REG_MAC_PHY_CTRL,
  2513. 0x7ff80000, (crystal_cap |
  2514. (crystal_cap << 6)));
  2515. else
  2516. rtl_set_bbreg(hw, REG_MAC_PHY_CTRL,
  2517. 0xfff000, (crystal_cap |
  2518. (crystal_cap << 6)));
  2519. }
  2520. RT_TRACE(rtlpriv, COMP_DIG, DBG_LOUD, "crystal_cap = 0x%x\n",
  2521. rtldm->crystal_cap);
  2522. } else{
  2523. /*1. Calculate CFO for path-A & path-B*/
  2524. cfo_khz_a = (int)(rtldm->cfo_tail[0] * 3125) / 1280;
  2525. cfo_khz_b = (int)(rtldm->cfo_tail[1] * 3125) / 1280;
  2526. packet_count = rtldm->packet_count;
  2527. /*2.No new packet*/
  2528. if (packet_count == rtldm->packet_count_pre) {
  2529. RT_TRACE(rtlpriv, COMP_DIG, DBG_LOUD,
  2530. "packet counter doesn't change\n");
  2531. return;
  2532. }
  2533. rtldm->packet_count_pre = packet_count;
  2534. RT_TRACE(rtlpriv, COMP_DIG, DBG_LOUD,
  2535. "packet counter = %d\n",
  2536. rtldm->packet_count);
  2537. /*3.Average CFO*/
  2538. if (rtlpriv->phy.rf_type == RF_1T1R)
  2539. cfo_ave = cfo_khz_a;
  2540. else
  2541. cfo_ave = (cfo_khz_a + cfo_khz_b) >> 1;
  2542. RT_TRACE(rtlpriv, COMP_DIG, DBG_LOUD,
  2543. "cfo_khz_a = %dkHz, cfo_khz_b = %dkHz, cfo_ave = %dkHz\n",
  2544. cfo_khz_a, cfo_khz_b, cfo_ave);
  2545. /*4.Avoid abnormal large CFO*/
  2546. cfo_ave_diff = (rtldm->cfo_ave_pre >= cfo_ave) ?
  2547. (rtldm->cfo_ave_pre - cfo_ave) :
  2548. (cfo_ave - rtldm->cfo_ave_pre);
  2549. if (cfo_ave_diff > 20 && rtldm->large_cfo_hit == 0) {
  2550. RT_TRACE(rtlpriv, COMP_DIG, DBG_LOUD,
  2551. "first large CFO hit\n");
  2552. rtldm->large_cfo_hit = 1;
  2553. return;
  2554. } else
  2555. rtldm->large_cfo_hit = 0;
  2556. rtldm->cfo_ave_pre = cfo_ave;
  2557. /*CFO tracking by adjusting Xtal cap.*/
  2558. /*1.Dynamic Xtal threshold*/
  2559. if (cfo_ave >= -rtldm->cfo_threshold &&
  2560. cfo_ave <= rtldm->cfo_threshold &&
  2561. rtldm->is_freeze == 0) {
  2562. if (rtldm->cfo_threshold == CFO_THRESHOLD_XTAL) {
  2563. rtldm->cfo_threshold = CFO_THRESHOLD_XTAL + 10;
  2564. rtldm->is_freeze = 1;
  2565. } else {
  2566. rtldm->cfo_threshold = CFO_THRESHOLD_XTAL;
  2567. }
  2568. }
  2569. RT_TRACE(rtlpriv, COMP_DIG, DBG_LOUD,
  2570. "Dynamic threshold = %d\n",
  2571. rtldm->cfo_threshold);
  2572. /* 2.Calculate Xtal offset*/
  2573. if (cfo_ave > rtldm->cfo_threshold && rtldm->crystal_cap < 0x3f)
  2574. adjust_xtal = ((cfo_ave - CFO_THRESHOLD_XTAL) >> 2) + 1;
  2575. else if ((cfo_ave < -rtlpriv->dm.cfo_threshold) &&
  2576. rtlpriv->dm.crystal_cap > 0)
  2577. adjust_xtal = ((cfo_ave + CFO_THRESHOLD_XTAL) >> 2) - 1;
  2578. RT_TRACE(rtlpriv, COMP_DIG, DBG_LOUD,
  2579. "Crystal cap = 0x%x, Crystal cap offset = %d\n",
  2580. rtldm->crystal_cap, adjust_xtal);
  2581. /*3.Adjudt Crystal Cap.*/
  2582. if (adjust_xtal != 0) {
  2583. rtldm->is_freeze = 0;
  2584. rtldm->crystal_cap += adjust_xtal;
  2585. if (rtldm->crystal_cap > 0x3f)
  2586. rtldm->crystal_cap = 0x3f;
  2587. else if (rtldm->crystal_cap < 0)
  2588. rtldm->crystal_cap = 0;
  2589. crystal_cap = rtldm->crystal_cap & 0x3f;
  2590. crystal_cap = crystal_cap & 0x3f;
  2591. if (rtlpriv->rtlhal.hw_type == HARDWARE_TYPE_RTL8812AE)
  2592. rtl_set_bbreg(hw, REG_MAC_PHY_CTRL,
  2593. 0x7ff80000, (crystal_cap |
  2594. (crystal_cap << 6)));
  2595. else
  2596. rtl_set_bbreg(hw, REG_MAC_PHY_CTRL,
  2597. 0xfff000, (crystal_cap |
  2598. (crystal_cap << 6)));
  2599. RT_TRACE(rtlpriv, COMP_DIG, DBG_LOUD,
  2600. "New crystal cap = 0x%x\n",
  2601. rtldm->crystal_cap);
  2602. }
  2603. }
  2604. }
  2605. void rtl8821ae_dm_watchdog(struct ieee80211_hw *hw)
  2606. {
  2607. struct rtl_priv *rtlpriv = rtl_priv(hw);
  2608. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  2609. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  2610. bool fw_current_inpsmode = false;
  2611. bool fw_ps_awake = true;
  2612. rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_FW_PSMODE_STATUS,
  2613. (u8 *)(&fw_current_inpsmode));
  2614. rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_FWLPS_RF_ON,
  2615. (u8 *)(&fw_ps_awake));
  2616. if (ppsc->p2p_ps_info.p2p_ps_mode)
  2617. fw_ps_awake = false;
  2618. if ((ppsc->rfpwr_state == ERFON) &&
  2619. ((!fw_current_inpsmode) && fw_ps_awake) &&
  2620. (!ppsc->rfchange_inprogress)) {
  2621. rtl8821ae_dm_common_info_self_update(hw);
  2622. rtl8821ae_dm_false_alarm_counter_statistics(hw);
  2623. rtl8821ae_dm_check_rssi_monitor(hw);
  2624. rtl8821ae_dm_dig(hw);
  2625. rtl8821ae_dm_cck_packet_detection_thresh(hw);
  2626. rtl8821ae_dm_refresh_rate_adaptive_mask(hw);
  2627. rtl8821ae_dm_refresh_basic_rate_mask(hw);
  2628. rtl8821ae_dm_check_edca_turbo(hw);
  2629. rtl8821ae_dm_dynamic_atc_switch(hw);
  2630. if (rtlhal->hw_type == HARDWARE_TYPE_RTL8812AE)
  2631. rtl8812ae_dm_check_txpower_tracking_thermalmeter(hw);
  2632. else
  2633. rtl8821ae_dm_check_txpower_tracking_thermalmeter(hw);
  2634. rtl8821ae_dm_iq_calibrate(hw);
  2635. }
  2636. rtlpriv->dm.dbginfo.num_qry_beacon_pkt = 0;
  2637. RT_TRACE(rtlpriv, COMP_DIG, DBG_DMESG, "\n");
  2638. }
  2639. void rtl8821ae_dm_set_tx_ant_by_tx_info(struct ieee80211_hw *hw,
  2640. u8 *pdesc, u32 mac_id)
  2641. {
  2642. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  2643. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  2644. struct rtl_dm *rtldm = rtl_dm(rtl_priv(hw));
  2645. struct fast_ant_training *pfat_table = &rtldm->fat_table;
  2646. if (rtlhal->hw_type != HARDWARE_TYPE_RTL8812AE)
  2647. return;
  2648. if (rtlefuse->antenna_div_type == CG_TRX_HW_ANTDIV)
  2649. SET_TX_DESC_TX_ANT(pdesc, pfat_table->antsel_a[mac_id]);
  2650. }