rtl8812a_phycfg.c 160 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of version 2 of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  17. *
  18. *
  19. ******************************************************************************/
  20. #define _RTL8812A_PHYCFG_C_
  21. //#include <drv_types.h>
  22. #include <rtl8812a_hal.h>
  23. const char *const GLBwSrc[]={
  24. "CHANNEL_WIDTH_20",
  25. "CHANNEL_WIDTH_40",
  26. "CHANNEL_WIDTH_80",
  27. "CHANNEL_WIDTH_160",
  28. "CHANNEL_WIDTH_80_80"
  29. };
  30. #define ENABLE_POWER_BY_RATE 1
  31. #define POWERINDEX_ARRAY_SIZE 48 //= cckRatesSize + ofdmRatesSize + htRates1TSize + htRates2TSize + vhtRates1TSize + vhtRates1TSize;
  32. /*---------------------Define local function prototype-----------------------*/
  33. /*----------------------------Function Body----------------------------------*/
  34. //
  35. // 1. BB register R/W API
  36. //
  37. u32
  38. PHY_QueryBBReg8812(
  39. IN PADAPTER Adapter,
  40. IN u32 RegAddr,
  41. IN u32 BitMask
  42. )
  43. {
  44. u32 ReturnValue = 0, OriginalValue, BitShift;
  45. #if (DISABLE_BB_RF == 1)
  46. return 0;
  47. #endif
  48. //DBG_871X("--->PHY_QueryBBReg8812(): RegAddr(%#x), BitMask(%#x)\n", RegAddr, BitMask);
  49. OriginalValue = rtw_read32(Adapter, RegAddr);
  50. BitShift = PHY_CalculateBitShift(BitMask);
  51. ReturnValue = (OriginalValue & BitMask) >> BitShift;
  52. //DBG_871X("BBR MASK=0x%x Addr[0x%x]=0x%x\n", BitMask, RegAddr, OriginalValue);
  53. return (ReturnValue);
  54. }
  55. VOID
  56. PHY_SetBBReg8812(
  57. IN PADAPTER Adapter,
  58. IN u4Byte RegAddr,
  59. IN u4Byte BitMask,
  60. IN u4Byte Data
  61. )
  62. {
  63. u4Byte OriginalValue, BitShift;
  64. #if (DISABLE_BB_RF == 1)
  65. return;
  66. #endif
  67. if(BitMask!= bMaskDWord)
  68. {//if not "double word" write
  69. OriginalValue = rtw_read32(Adapter, RegAddr);
  70. BitShift = PHY_CalculateBitShift(BitMask);
  71. Data = ((OriginalValue) & (~BitMask)) |( ((Data << BitShift)) & BitMask);
  72. }
  73. rtw_write32(Adapter, RegAddr, Data);
  74. //DBG_871X("BBW MASK=0x%x Addr[0x%x]=0x%x\n", BitMask, RegAddr, Data);
  75. }
  76. //
  77. // 2. RF register R/W API
  78. //
  79. static u32
  80. phy_RFSerialRead(
  81. IN PADAPTER Adapter,
  82. IN u8 eRFPath,
  83. IN u32 Offset
  84. )
  85. {
  86. u32 retValue = 0;
  87. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  88. BB_REGISTER_DEFINITION_T *pPhyReg = &pHalData->PHYRegDef[eRFPath];
  89. BOOLEAN bIsPIMode = _FALSE;
  90. // 2009/06/17 MH We can not execute IO for power save or other accident mode.
  91. //if(RT_CANNOT_IO(Adapter))
  92. //{
  93. // RT_DISP(FPHY, PHY_RFR, ("phy_RFSerialRead return all one\n"));
  94. // return 0xFFFFFFFF;
  95. //}
  96. // <20120809, Kordan> CCA OFF(when entering), asked by James to avoid reading the wrong value.
  97. // <20120828, Kordan> Toggling CCA would affect RF 0x0, skip it!
  98. if (Offset != 0x0 && ! (IS_VENDOR_8812A_C_CUT(Adapter) || IS_HARDWARE_TYPE_8821(Adapter)))
  99. PHY_SetBBReg(Adapter, rCCAonSec_Jaguar, 0x8, 1);
  100. Offset &= 0xff;
  101. if (eRFPath == RF_PATH_A)
  102. bIsPIMode = (BOOLEAN)PHY_QueryBBReg(Adapter, 0xC00, 0x4);
  103. else if (eRFPath == RF_PATH_B)
  104. bIsPIMode = (BOOLEAN)PHY_QueryBBReg(Adapter, 0xE00, 0x4);
  105. if(IS_VENDOR_8812A_TEST_CHIP(Adapter))
  106. PHY_SetBBReg(Adapter, pPhyReg->rfHSSIPara2, bMaskDWord, 0);
  107. PHY_SetBBReg(Adapter, pPhyReg->rfHSSIPara2, bHSSIRead_addr_Jaguar, Offset);
  108. if (IS_VENDOR_8812A_TEST_CHIP(Adapter) )
  109. PHY_SetBBReg(Adapter, pPhyReg->rfHSSIPara2, bMaskDWord, Offset|BIT8);
  110. if (IS_VENDOR_8812A_C_CUT(Adapter) || IS_HARDWARE_TYPE_8821(Adapter))
  111. rtw_udelay_os(20);
  112. if (bIsPIMode)
  113. {
  114. retValue = PHY_QueryBBReg(Adapter, pPhyReg->rfLSSIReadBackPi, rRead_data_Jaguar);
  115. //DBG_871X("[PI mode] RFR-%d Addr[0x%x]=0x%x\n", eRFPath, pPhyReg->rfLSSIReadBackPi, retValue);
  116. }
  117. else
  118. {
  119. retValue = PHY_QueryBBReg(Adapter, pPhyReg->rfLSSIReadBack, rRead_data_Jaguar);
  120. //DBG_871X("[SI mode] RFR-%d Addr[0x%x]=0x%x\n", eRFPath, pPhyReg->rfLSSIReadBack, retValue);
  121. }
  122. // <20120809, Kordan> CCA ON(when exiting), asked by James to avoid reading the wrong value.
  123. // <20120828, Kordan> Toggling CCA would affect RF 0x0, skip it!
  124. if (Offset != 0x0 && ! (IS_VENDOR_8812A_C_CUT(Adapter) || IS_HARDWARE_TYPE_8821(Adapter)))
  125. PHY_SetBBReg(Adapter, rCCAonSec_Jaguar, 0x8, 0);
  126. return retValue;
  127. }
  128. static VOID
  129. phy_RFSerialWrite(
  130. IN PADAPTER Adapter,
  131. IN u8 eRFPath,
  132. IN u32 Offset,
  133. IN u32 Data
  134. )
  135. {
  136. u32 DataAndAddr = 0;
  137. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  138. BB_REGISTER_DEFINITION_T *pPhyReg = &pHalData->PHYRegDef[eRFPath];
  139. // 2009/06/17 MH We can not execute IO for power save or other accident mode.
  140. //if(RT_CANNOT_IO(Adapter))
  141. //{
  142. // RTPRINT(FPHY, PHY_RFW, ("phy_RFSerialWrite stop\n"));
  143. // return;
  144. //}
  145. Offset &= 0xff;
  146. // Shadow Update
  147. //PHY_RFShadowWrite(Adapter, eRFPath, Offset, Data);
  148. // Put write addr in [27:20] and write data in [19:00]
  149. DataAndAddr = ((Offset<<20) | (Data&0x000fffff)) & 0x0fffffff;
  150. //3 <Note> This is a workaround for 8812A test chips.
  151. #ifdef CONFIG_USB_HCI
  152. // <20120427, Kordan> MAC first moves lower 16 bits and then upper 16 bits of a 32-bit data.
  153. // BaseBand doesn't know the two actions is actually only one action to access 32-bit data,
  154. // so that the lower 16 bits is overwritten by the upper 16 bits. (Asked by ynlin.)
  155. // (Unfortunately, the protection mechanism has not been implemented in 8812A yet.)
  156. // 2012/10/26 MH Revise V3236 Lanhsin check in, if we do not enable the function
  157. // for 8821, then it can not scan.
  158. if ((!pHalData->bSupportUSB3) && (IS_TEST_CHIP(pHalData->VersionID))) // USB 2.0 or older
  159. {
  160. //if (IS_VENDOR_8812A_TEST_CHIP(Adapter) || IS_HARDWARE_TYPE_8821(Adapter) is)
  161. {
  162. rtw_write32(Adapter, 0x1EC, DataAndAddr);
  163. if (eRFPath == RF_PATH_A)
  164. rtw_write32(Adapter, 0x1E8, 0x4000F000|0xC90);
  165. else
  166. rtw_write32(Adapter, 0x1E8, 0x4000F000|0xE90);
  167. }
  168. }
  169. else // USB 3.0
  170. #endif
  171. {
  172. // Write Operation
  173. // TODO: Dynamically determine whether using PI or SI to write RF registers.
  174. PHY_SetBBReg(Adapter, pPhyReg->rf3wireOffset, bMaskDWord, DataAndAddr);
  175. //DBG_871X("RFW-%d Addr[0x%x]=0x%x\n", eRFPath, pPhyReg->rf3wireOffset, DataAndAddr);
  176. }
  177. }
  178. u32
  179. PHY_QueryRFReg8812(
  180. IN PADAPTER Adapter,
  181. IN u8 eRFPath,
  182. IN u32 RegAddr,
  183. IN u32 BitMask
  184. )
  185. {
  186. u32 Original_Value, Readback_Value, BitShift;
  187. #if (DISABLE_BB_RF == 1)
  188. return 0;
  189. #endif
  190. Original_Value = phy_RFSerialRead(Adapter, eRFPath, RegAddr);
  191. BitShift = PHY_CalculateBitShift(BitMask);
  192. Readback_Value = (Original_Value & BitMask) >> BitShift;
  193. return (Readback_Value);
  194. }
  195. VOID
  196. PHY_SetRFReg8812(
  197. IN PADAPTER Adapter,
  198. IN u8 eRFPath,
  199. IN u32 RegAddr,
  200. IN u32 BitMask,
  201. IN u32 Data
  202. )
  203. {
  204. #if (DISABLE_BB_RF == 1)
  205. return;
  206. #endif
  207. if(BitMask == 0)
  208. return;
  209. // RF data is 20 bits only
  210. if (BitMask != bLSSIWrite_data_Jaguar) {
  211. u32 Original_Value, BitShift;
  212. Original_Value = phy_RFSerialRead(Adapter, eRFPath, RegAddr);
  213. BitShift = PHY_CalculateBitShift(BitMask);
  214. Data = ((Original_Value) & (~BitMask)) | (Data<< BitShift);
  215. }
  216. phy_RFSerialWrite(Adapter, eRFPath, RegAddr, Data);
  217. }
  218. //
  219. // 3. Initial MAC/BB/RF config by reading MAC/BB/RF txt.
  220. //
  221. s32 PHY_MACConfig8812(PADAPTER Adapter)
  222. {
  223. int rtStatus = _SUCCESS;
  224. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  225. s8 *pszMACRegFile;
  226. s8 sz8812MACRegFile[] = RTL8812_PHY_MACREG;
  227. pszMACRegFile = sz8812MACRegFile;
  228. //
  229. // Config MAC
  230. //
  231. #ifdef CONFIG_EMBEDDED_FWIMG
  232. if(HAL_STATUS_SUCCESS != ODM_ConfigMACWithHeaderFile(&pHalData->odmpriv))
  233. rtStatus = _FAIL;
  234. #else
  235. // Not make sure EEPROM, add later
  236. DBG_871X("Read MACREG.txt\n");
  237. rtStatus = phy_ConfigMACWithParaFile(Adapter, pszMACRegFile);
  238. #endif//CONFIG_EMBEDDED_FWIMG
  239. return rtStatus;
  240. }
  241. static VOID
  242. phy_InitBBRFRegisterDefinition(
  243. IN PADAPTER Adapter
  244. )
  245. {
  246. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  247. // RF Interface Sowrtware Control
  248. pHalData->PHYRegDef[RF_PATH_A].rfintfs = rFPGA0_XAB_RFInterfaceSW; // 16 LSBs if read 32-bit from 0x870
  249. pHalData->PHYRegDef[RF_PATH_B].rfintfs = rFPGA0_XAB_RFInterfaceSW; // 16 MSBs if read 32-bit from 0x870 (16-bit for 0x872)
  250. // RF Interface Output (and Enable)
  251. pHalData->PHYRegDef[RF_PATH_A].rfintfo = rFPGA0_XA_RFInterfaceOE; // 16 LSBs if read 32-bit from 0x860
  252. pHalData->PHYRegDef[RF_PATH_B].rfintfo = rFPGA0_XB_RFInterfaceOE; // 16 LSBs if read 32-bit from 0x864
  253. // RF Interface (Output and) Enable
  254. pHalData->PHYRegDef[RF_PATH_A].rfintfe = rFPGA0_XA_RFInterfaceOE; // 16 MSBs if read 32-bit from 0x860 (16-bit for 0x862)
  255. pHalData->PHYRegDef[RF_PATH_B].rfintfe = rFPGA0_XB_RFInterfaceOE; // 16 MSBs if read 32-bit from 0x864 (16-bit for 0x866)
  256. pHalData->PHYRegDef[RF_PATH_A].rf3wireOffset = rA_LSSIWrite_Jaguar; //LSSI Parameter
  257. pHalData->PHYRegDef[RF_PATH_B].rf3wireOffset = rB_LSSIWrite_Jaguar;
  258. pHalData->PHYRegDef[RF_PATH_A].rfHSSIPara2 = rHSSIRead_Jaguar; //wire control parameter2
  259. pHalData->PHYRegDef[RF_PATH_B].rfHSSIPara2 = rHSSIRead_Jaguar; //wire control parameter2
  260. // Tranceiver Readback LSSI/HSPI mode
  261. pHalData->PHYRegDef[RF_PATH_A].rfLSSIReadBack = rA_SIRead_Jaguar;
  262. pHalData->PHYRegDef[RF_PATH_B].rfLSSIReadBack = rB_SIRead_Jaguar;
  263. pHalData->PHYRegDef[RF_PATH_A].rfLSSIReadBackPi = rA_PIRead_Jaguar;
  264. pHalData->PHYRegDef[RF_PATH_B].rfLSSIReadBackPi = rB_PIRead_Jaguar;
  265. //pHalData->bPhyValueInitReady=_TRUE;
  266. }
  267. VOID
  268. PHY_BB8812_Config_1T(
  269. IN PADAPTER Adapter
  270. )
  271. {
  272. // BB OFDM RX Path_A
  273. PHY_SetBBReg(Adapter, rRxPath_Jaguar, bRxPath_Jaguar, 0x11);
  274. // BB OFDM TX Path_A
  275. PHY_SetBBReg(Adapter, rTxPath_Jaguar, bMaskLWord, 0x1111);
  276. // BB CCK R/Rx Path_A
  277. PHY_SetBBReg(Adapter, rCCK_RX_Jaguar, bCCK_RX_Jaguar, 0x0);
  278. // MCS support
  279. PHY_SetBBReg(Adapter, 0x8bc, 0xc0000060, 0x4);
  280. // RF Path_B HSSI OFF
  281. PHY_SetBBReg(Adapter, 0xe00, 0xf, 0x4);
  282. // RF Path_B Power Down
  283. PHY_SetBBReg(Adapter, 0xe90, bMaskDWord, 0);
  284. // ADDA Path_B OFF
  285. PHY_SetBBReg(Adapter, 0xe60, bMaskDWord, 0);
  286. PHY_SetBBReg(Adapter, 0xe64, bMaskDWord, 0);
  287. }
  288. static int
  289. phy_BB8812_Config_ParaFile(
  290. IN PADAPTER Adapter
  291. )
  292. {
  293. EEPROM_EFUSE_PRIV *pEEPROM = GET_EEPROM_EFUSE_PRIV(Adapter);
  294. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  295. int rtStatus = _SUCCESS;
  296. s8 sz8812BBRegFile[] = RTL8812_PHY_REG;
  297. s8 sz8812AGCTableFile[] = RTL8812_AGC_TAB;
  298. s8 sz8812BBRegPgFile[] = RTL8812_PHY_REG_PG;
  299. s8 sz8812BBRegMpFile[] = RTL8812_PHY_REG_MP;
  300. s8 sz8812BBRegLimitFile[] = RTL8812_TXPWR_LMT;
  301. s8 sz8821BBRegFile[] = RTL8821_PHY_REG;
  302. s8 sz8821AGCTableFile[] = RTL8821_AGC_TAB;
  303. s8 sz8821BBRegPgFile[] = RTL8821_PHY_REG_PG;
  304. s8 sz8821BBRegMpFile[] = RTL8821_PHY_REG_MP;
  305. s8 sz8821RFTxPwrLmtFile[] = RTL8821_TXPWR_LMT;
  306. s8 *pszBBRegFile = NULL, *pszAGCTableFile = NULL,
  307. *pszBBRegPgFile = NULL, *pszBBRegMpFile=NULL,
  308. *pszRFTxPwrLmtFile = NULL;
  309. //DBG_871X("==>phy_BB8812_Config_ParaFile\n");
  310. if(IS_HARDWARE_TYPE_8812(Adapter))
  311. {
  312. pszBBRegFile=sz8812BBRegFile ;
  313. pszAGCTableFile =sz8812AGCTableFile;
  314. pszBBRegPgFile = sz8812BBRegPgFile;
  315. pszBBRegMpFile = sz8812BBRegMpFile;
  316. pszRFTxPwrLmtFile = sz8812BBRegLimitFile;
  317. }
  318. else
  319. {
  320. pszBBRegFile=sz8821BBRegFile ;
  321. pszAGCTableFile =sz8821AGCTableFile;
  322. pszBBRegPgFile = sz8821BBRegPgFile;
  323. pszBBRegMpFile = sz8821BBRegMpFile;
  324. pszRFTxPwrLmtFile = sz8821RFTxPwrLmtFile;
  325. }
  326. DBG_871X("===> phy_BB8812_Config_ParaFile() EEPROMRegulatory %d\n", pHalData->EEPROMRegulatory );
  327. //DBG_871X(" ===> phy_BB8812_Config_ParaFile() phy_reg:%s\n",pszBBRegFile);
  328. //DBG_871X(" ===> phy_BB8812_Config_ParaFile() phy_reg_pg:%s\n",pszBBRegPgFile);
  329. //DBG_871X(" ===> phy_BB8812_Config_ParaFile() agc_table:%s\n",pszAGCTableFile);
  330. PHY_InitPowerLimitTable( &(pHalData->odmpriv) );
  331. if ( ( Adapter->registrypriv.RegEnableTxPowerLimit == 1 && pHalData->EEPROMRegulatory != 2 ) ||
  332. pHalData->EEPROMRegulatory == 1 )
  333. {
  334. #ifdef CONFIG_EMBEDDED_FWIMG
  335. if (HAL_STATUS_SUCCESS != ODM_ConfigRFWithHeaderFile(&pHalData->odmpriv, CONFIG_RF_TXPWR_LMT, 0))
  336. rtStatus = _FAIL;
  337. #else
  338. rtStatus = PHY_ConfigBBWithPowerLimitTableParaFile( Adapter, pszRFTxPwrLmtFile );
  339. #endif
  340. if(rtStatus != _SUCCESS){
  341. DBG_871X("phy_BB8812_Config_ParaFile():Write BB Reg Fail!!");
  342. goto phy_BB_Config_ParaFile_Fail;
  343. }
  344. }
  345. // Read PHY_REG.TXT BB INIT!!
  346. #ifdef CONFIG_EMBEDDED_FWIMG
  347. if (HAL_STATUS_SUCCESS != ODM_ConfigBBWithHeaderFile(&pHalData->odmpriv, CONFIG_BB_PHY_REG))
  348. rtStatus = _FAIL;
  349. #else
  350. // No matter what kind of CHIP we always read PHY_REG.txt. We must copy different
  351. // type of parameter files to phy_reg.txt at first.
  352. rtStatus = phy_ConfigBBWithParaFile(Adapter,pszBBRegFile);
  353. #endif
  354. if(rtStatus != _SUCCESS){
  355. DBG_871X("phy_BB8812_Config_ParaFile():Write BB Reg Fail!!");
  356. goto phy_BB_Config_ParaFile_Fail;
  357. }
  358. //f (MP_DRIVER == 1)
  359. #if 0
  360. // Read PHY_REG_MP.TXT BB INIT!!
  361. #ifdef CONFIG_EMBEDDED_FWIMG
  362. if (HAL_STATUS_SUCCESS != ODM_ConfigBBWithHeaderFile(&pHalData->odmpriv, CONFIG_BB_PHY_REG))
  363. rtStatus = _FAIL;
  364. #else
  365. // No matter what kind of CHIP we always read PHY_REG.txt. We must copy different
  366. // type of parameter files to phy_reg.txt at first.
  367. rtStatus = phy_ConfigBBWithMpParaFile(Adapter,pszBBRegMpFile);
  368. #endif
  369. if(rtStatus != _SUCCESS){
  370. DBG_871X("phy_BB8812_Config_ParaFile():Write BB Reg MP Fail!!");
  371. goto phy_BB_Config_ParaFile_Fail;
  372. }
  373. #endif // #if (MP_DRIVER == 1)
  374. // If EEPROM or EFUSE autoload OK, We must config by PHY_REG_PG.txt
  375. //1 TODO
  376. if (pEEPROM->bautoload_fail_flag == _FALSE)
  377. {
  378. pHalData->pwrGroupCnt = 0;
  379. #ifdef CONFIG_EMBEDDED_FWIMG
  380. if (HAL_STATUS_SUCCESS != ODM_ConfigBBWithHeaderFile(&pHalData->odmpriv, CONFIG_BB_PHY_REG_PG))
  381. rtStatus = _FAIL;
  382. #else
  383. rtStatus = phy_ConfigBBWithPgParaFile(Adapter, pszBBRegPgFile);
  384. #endif
  385. if(rtStatus != _SUCCESS){
  386. DBG_871X("phy_BB8812_Config_ParaFile():BB_PG Reg Fail!!");
  387. goto phy_BB_Config_ParaFile_Fail;
  388. }
  389. if ( ( Adapter->registrypriv.RegEnableTxPowerLimit == 1 && pHalData->EEPROMRegulatory != 2 ) ||
  390. pHalData->EEPROMRegulatory == 1 )
  391. PHY_ConvertPowerLimitToPowerIndex( Adapter );
  392. }
  393. // BB AGC table Initialization
  394. #ifdef CONFIG_EMBEDDED_FWIMG
  395. if (HAL_STATUS_SUCCESS != ODM_ConfigBBWithHeaderFile(&pHalData->odmpriv, CONFIG_BB_AGC_TAB))
  396. rtStatus = _FAIL;
  397. #else
  398. rtStatus = phy_ConfigBBWithParaFile(Adapter, pszAGCTableFile);
  399. #endif
  400. if(rtStatus != _SUCCESS){
  401. DBG_871X("phy_BB8812_Config_ParaFile():AGC Table Fail\n");
  402. goto phy_BB_Config_ParaFile_Fail;
  403. }
  404. phy_BB_Config_ParaFile_Fail:
  405. return rtStatus;
  406. }
  407. int
  408. PHY_BBConfig8812(
  409. IN PADAPTER Adapter
  410. )
  411. {
  412. int rtStatus = _SUCCESS;
  413. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  414. u8 TmpU1B=0;
  415. u8 CrystalCap;
  416. phy_InitBBRFRegisterDefinition(Adapter);
  417. //tangw check start 20120412
  418. // . APLL_EN,,APLL_320_GATEB,APLL_320BIAS, auto config by hw fsm after pfsm_go (0x4 bit 8) set
  419. TmpU1B = rtw_read8(Adapter, REG_SYS_FUNC_EN);
  420. if(IS_HARDWARE_TYPE_8812AU(Adapter) || IS_HARDWARE_TYPE_8821U(Adapter))
  421. TmpU1B |= FEN_USBA;
  422. else if(IS_HARDWARE_TYPE_8812E(Adapter) || IS_HARDWARE_TYPE_8821E(Adapter))
  423. TmpU1B |= FEN_PCIEA;
  424. rtw_write8(Adapter, REG_SYS_FUNC_EN, TmpU1B);
  425. rtw_write8(Adapter, REG_SYS_FUNC_EN, (TmpU1B|FEN_BB_GLB_RSTn|FEN_BBRSTB));//same with 8812
  426. //6. 0x1f[7:0] = 0x07 PathA RF Power On
  427. rtw_write8(Adapter, REG_RF_CTRL, 0x07);//RF_SDMRSTB,RF_RSTB,RF_EN same with 8723a
  428. //7. PathB RF Power On
  429. rtw_write8(Adapter, REG_OPT_CTRL_8812+2, 0x7);//RF_SDMRSTB,RF_RSTB,RF_EN same with 8723a
  430. //tangw check end 20120412
  431. //
  432. // Config BB and AGC
  433. //
  434. rtStatus = phy_BB8812_Config_ParaFile(Adapter);
  435. if(IS_HARDWARE_TYPE_8812(Adapter))
  436. {
  437. // write 0x2C[30:25] = 0x2C[24:19] = CrystalCap
  438. CrystalCap = pHalData->CrystalCap & 0x3F;
  439. PHY_SetBBReg(Adapter, REG_MAC_PHY_CTRL, 0x7FF80000, (CrystalCap | (CrystalCap << 6)));
  440. }
  441. else if ((IS_HARDWARE_TYPE_8723A(Adapter) && pHalData->EEPROMVersion >= 0x01) ||
  442. IS_HARDWARE_TYPE_8821(Adapter) || IS_HARDWARE_TYPE_8723B(Adapter) ||
  443. IS_HARDWARE_TYPE_8192E(Adapter))
  444. {
  445. // 0x2C[23:18] = 0x2C[17:12] = CrystalCap
  446. CrystalCap = pHalData->CrystalCap & 0x3F;
  447. PHY_SetBBReg(Adapter, REG_MAC_PHY_CTRL, 0xFFF000, (CrystalCap | (CrystalCap << 6)));
  448. }
  449. if(IS_HARDWARE_TYPE_JAGUAR(Adapter))
  450. {
  451. pHalData->Reg837 = rtw_read8(Adapter, 0x837);
  452. }
  453. return rtStatus;
  454. }
  455. int
  456. PHY_RFConfig8812(
  457. IN PADAPTER Adapter
  458. )
  459. {
  460. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  461. int rtStatus = _SUCCESS;
  462. if (Adapter->bSurpriseRemoved)
  463. return _FAIL;
  464. switch(pHalData->rf_chip)
  465. {
  466. case RF_PSEUDO_11N:
  467. DBG_871X("%s(): RF_PSEUDO_11N\n",__FUNCTION__);
  468. break;
  469. default:
  470. rtStatus = PHY_RF6052_Config_8812(Adapter);
  471. break;
  472. }
  473. return rtStatus;
  474. }
  475. BOOLEAN
  476. eqNByte(
  477. u8* str1,
  478. u8* str2,
  479. u32 num
  480. )
  481. {
  482. if(num==0)
  483. return _FALSE;
  484. while(num>0)
  485. {
  486. num--;
  487. if(str1[num]!=str2[num])
  488. return _FALSE;
  489. }
  490. return _TRUE;
  491. }
  492. BOOLEAN
  493. GetU1ByteIntegerFromStringInDecimal(
  494. IN s8* Str,
  495. IN OUT u8* pInt
  496. )
  497. {
  498. u16 i = 0;
  499. *pInt = 0;
  500. while ( Str[i] != '\0' )
  501. {
  502. if ( Str[i] >= '0' && Str[i] <= '9' )
  503. {
  504. *pInt *= 10;
  505. *pInt += ( Str[i] - '0' );
  506. }
  507. else
  508. {
  509. return _FALSE;
  510. }
  511. ++i;
  512. }
  513. return _TRUE;
  514. }
  515. static s8
  516. phy_GetChannelGroup(
  517. IN BAND_TYPE Band,
  518. IN u8 Channel
  519. )
  520. {
  521. s8 channelGroup = -1;
  522. if ( Channel <= 14 && Band == BAND_ON_2_4G )
  523. {
  524. if ( 1 <= Channel && Channel <= 2 ) channelGroup = 0;
  525. else if ( 3 <= Channel && Channel <= 5 ) channelGroup = 1;
  526. else if ( 6 <= Channel && Channel <= 8 ) channelGroup = 2;
  527. else if ( 9 <= Channel && Channel <= 11 ) channelGroup = 3;
  528. else if ( 12 <= Channel && Channel <= 14) channelGroup = 4;
  529. else
  530. {
  531. DBG_871X( "==> phy_GetChannelGroup() in 2.4 G, but Channel %d in Group not found \n", Channel );
  532. channelGroup = -1;
  533. }
  534. }
  535. else if( Band == BAND_ON_5G )
  536. {
  537. if ( 36 <= Channel && Channel <= 42 ) channelGroup = 0;
  538. else if ( 44 <= Channel && Channel <= 48 ) channelGroup = 1;
  539. else if ( 50 <= Channel && Channel <= 58 ) channelGroup = 2;
  540. else if ( 60 <= Channel && Channel <= 64 ) channelGroup = 3;
  541. else if ( 100 <= Channel && Channel <= 106 ) channelGroup = 4;
  542. else if ( 108 <= Channel && Channel <= 114 ) channelGroup = 5;
  543. else if ( 116 <= Channel && Channel <= 122 ) channelGroup = 6;
  544. else if ( 124 <= Channel && Channel <= 130 ) channelGroup = 7;
  545. else if ( 132 <= Channel && Channel <= 138 ) channelGroup = 8;
  546. else if ( 140 <= Channel && Channel <= 144 ) channelGroup = 9;
  547. else if ( 149 <= Channel && Channel <= 155 ) channelGroup = 10;
  548. else if ( 157 <= Channel && Channel <= 161 ) channelGroup = 11;
  549. else if ( 165 <= Channel && Channel <= 171 ) channelGroup = 12;
  550. else if ( 173 <= Channel && Channel <= 177 ) channelGroup = 13;
  551. else
  552. {
  553. DBG_871X("==>phy_GetChannelGroup() in 5G, but Channel %d in Group not found \n", Channel );
  554. channelGroup = -1;
  555. }
  556. }
  557. else
  558. {
  559. DBG_871X("==>phy_GetChannelGroup() in unsupported band %d\n", Band );
  560. channelGroup = -1;
  561. }
  562. return channelGroup;
  563. }
  564. u8
  565. phy_getPowerByRateBaseIndex(
  566. IN BAND_TYPE Band,
  567. IN u8 Rate
  568. )
  569. {
  570. u8 index = 0;
  571. if ( Band == BAND_ON_2_4G )
  572. {
  573. switch ( Rate )
  574. {
  575. case MGN_1M: case MGN_2M: case MGN_5_5M: case MGN_11M:
  576. index = 0;
  577. break;
  578. case MGN_6M: case MGN_9M: case MGN_12M: case MGN_18M:
  579. case MGN_24M: case MGN_36M: case MGN_48M: case MGN_54M:
  580. index = 1;
  581. break;
  582. case MGN_MCS0: case MGN_MCS1: case MGN_MCS2: case MGN_MCS3:
  583. case MGN_MCS4: case MGN_MCS5: case MGN_MCS6: case MGN_MCS7:
  584. index = 2;
  585. break;
  586. case MGN_MCS8: case MGN_MCS9: case MGN_MCS10: case MGN_MCS11:
  587. case MGN_MCS12: case MGN_MCS13: case MGN_MCS14: case MGN_MCS15:
  588. index = 3;
  589. break;
  590. default:
  591. DBG_871X("Wrong rate 0x%x to obtain index in 2.4G in phy_getPowerByRateBaseIndex()\n", Rate );
  592. break;
  593. }
  594. }
  595. else if ( Band == BAND_ON_5G )
  596. {
  597. switch ( Rate )
  598. {
  599. case MGN_6M: case MGN_9M: case MGN_12M: case MGN_18M:
  600. case MGN_24M: case MGN_36M: case MGN_48M: case MGN_54M:
  601. index = 0;
  602. break;
  603. case MGN_MCS0: case MGN_MCS1: case MGN_MCS2: case MGN_MCS3:
  604. case MGN_MCS4: case MGN_MCS5: case MGN_MCS6: case MGN_MCS7:
  605. index = 1;
  606. break;
  607. case MGN_MCS8: case MGN_MCS9: case MGN_MCS10: case MGN_MCS11:
  608. case MGN_MCS12: case MGN_MCS13: case MGN_MCS14: case MGN_MCS15:
  609. index = 2;
  610. break;
  611. case MGN_VHT1SS_MCS0: case MGN_VHT1SS_MCS1: case MGN_VHT1SS_MCS2:
  612. case MGN_VHT1SS_MCS3: case MGN_VHT1SS_MCS4: case MGN_VHT1SS_MCS5:
  613. case MGN_VHT1SS_MCS6: case MGN_VHT1SS_MCS7: case MGN_VHT1SS_MCS8:
  614. case MGN_VHT1SS_MCS9:
  615. index = 3;
  616. break;
  617. case MGN_VHT2SS_MCS0: case MGN_VHT2SS_MCS1: case MGN_VHT2SS_MCS2:
  618. case MGN_VHT2SS_MCS3: case MGN_VHT2SS_MCS4: case MGN_VHT2SS_MCS5:
  619. case MGN_VHT2SS_MCS6: case MGN_VHT2SS_MCS7: case MGN_VHT2SS_MCS8:
  620. case MGN_VHT2SS_MCS9:
  621. index = 4;
  622. break;
  623. default:
  624. DBG_871X("Wrong rate 0x%x to obtain index in 5G in phy_getPowerByRateBaseIndex()\n", Rate );
  625. break;
  626. }
  627. }
  628. return index;
  629. }
  630. VOID
  631. PHY_InitPowerLimitTable(
  632. IN PDM_ODM_T pDM_Odm
  633. )
  634. {
  635. PADAPTER Adapter = pDM_Odm->Adapter;
  636. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  637. u8 i, j, k, l, m;
  638. //DBG_871X( "=====> PHY_InitPowerLimitTable()!\n" );
  639. for ( i = 0; i < MAX_REGULATION_NUM; ++i )
  640. {
  641. for ( j = 0; j < MAX_2_4G_BANDWITH_NUM; ++j )
  642. for ( k = 0; k < MAX_2_4G_RATE_SECTION_NUM; ++k )
  643. for ( m = 0; m < MAX_2_4G_CHANNEL_NUM; ++m )
  644. for ( l = 0; l < GET_HAL_RFPATH_NUM(Adapter) ;++l )
  645. pHalData->TxPwrLimit_2_4G[i][j][k][m][l] = MAX_POWER_INDEX;
  646. }
  647. for ( i = 0; i < MAX_REGULATION_NUM; ++i )
  648. {
  649. for ( j = 0; j < MAX_5G_BANDWITH_NUM; ++j )
  650. for ( k = 0; k < MAX_5G_RATE_SECTION_NUM; ++k )
  651. for ( m = 0; m < MAX_5G_CHANNEL_NUM; ++m )
  652. for ( l = 0; l < GET_HAL_RFPATH_NUM(Adapter) ; ++l )
  653. pHalData->TxPwrLimit_5G[i][j][k][m][l] = MAX_POWER_INDEX;
  654. }
  655. //DBG_871X("<===== PHY_InitPowerLimitTable()!\n" );
  656. }
  657. VOID
  658. PHY_ConvertPowerLimitToPowerIndex(
  659. IN PADAPTER Adapter
  660. )
  661. {
  662. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  663. u8 BW40PwrBasedBm2_4G, BW40PwrBasedBm5G;
  664. u8 regulation, bw, channel, rateSection, group;
  665. u8 baseIndex2_4G;
  666. u8 baseIndex5G;
  667. s8 tempValue = 0, tempPwrLmt = 0;
  668. u8 rfPath = 0;
  669. DBG_871X( "=====> PHY_ConvertPowerLimitToPowerIndex()\n" );
  670. for ( regulation = 0; regulation < MAX_REGULATION_NUM; ++regulation )
  671. {
  672. for ( bw = 0; bw < MAX_2_4G_BANDWITH_NUM; ++bw )
  673. {
  674. for ( group = 0; group < MAX_2_4G_CHANNEL_NUM; ++group )
  675. {
  676. if ( group == 0 )
  677. channel = 1;
  678. else if ( group == 1 )
  679. channel = 3;
  680. else if ( group == 2 )
  681. channel = 6;
  682. else if ( group == 3 )
  683. channel = 9;
  684. else if ( group == 4 )
  685. channel = 12;
  686. else
  687. channel = 14;
  688. for ( rateSection = 0; rateSection < MAX_2_4G_RATE_SECTION_NUM; ++rateSection )
  689. {
  690. if ( pHalData->odmpriv.PhyRegPgValueType == PHY_REG_PG_EXACT_VALUE ) {
  691. // obtain the base dBm values in 2.4G band
  692. // CCK => 11M, OFDM => 54M, HT 1T => MCS7, HT 2T => MCS15
  693. if ( rateSection == 0 ) { //CCK
  694. baseIndex2_4G = phy_getPowerByRateBaseIndex( BAND_ON_2_4G, MGN_11M );
  695. }
  696. else if ( rateSection == 1 ) { //OFDM
  697. baseIndex2_4G = phy_getPowerByRateBaseIndex( BAND_ON_2_4G, MGN_54M );
  698. }
  699. else if ( rateSection == 2 ) { //HT IT
  700. baseIndex2_4G = phy_getPowerByRateBaseIndex( BAND_ON_2_4G, MGN_MCS7 );
  701. }
  702. else if ( rateSection == 3 ) { //HT 2T
  703. baseIndex2_4G = phy_getPowerByRateBaseIndex( BAND_ON_2_4G, MGN_MCS15 );
  704. }
  705. }
  706. // we initially record the raw power limit value in rf path A, so we must obtain the raw
  707. // power limit value by using index rf path A and use it to calculate all the value of
  708. // all the path
  709. tempPwrLmt = pHalData->TxPwrLimit_2_4G[regulation][bw][rateSection][group][ODM_RF_PATH_A];
  710. // process ODM_RF_PATH_A later
  711. for ( rfPath = 0; rfPath < MAX_RF_PATH_NUM; ++rfPath )
  712. {
  713. if ( pHalData->odmpriv.PhyRegPgValueType == PHY_REG_PG_EXACT_VALUE )
  714. BW40PwrBasedBm2_4G = pHalData->TxPwrByRateBase2_4G[rfPath][baseIndex2_4G];
  715. else
  716. BW40PwrBasedBm2_4G = Adapter->registrypriv.RegPowerBase * 2;
  717. if ( tempPwrLmt != MAX_POWER_INDEX ) {
  718. tempValue = tempPwrLmt - BW40PwrBasedBm2_4G;
  719. pHalData->TxPwrLimit_2_4G[regulation][bw][rateSection][group][rfPath] = tempValue;
  720. }
  721. DBG_871X("TxPwrLimit_2_4G[regulation %d][bw %d][rateSection %d][group %d] %d=\n\
  722. (TxPwrLimit in dBm %d - BW40PwrLmt2_4G[channel %d][rfPath %d] %d) \n",
  723. regulation, bw, rateSection, group, pHalData->TxPwrLimit_2_4G[regulation][bw][rateSection][group][rfPath],
  724. tempPwrLmt, channel, rfPath, BW40PwrBasedBm2_4G );
  725. }
  726. }
  727. }
  728. }
  729. }
  730. if ( IS_HARDWARE_TYPE_8812( Adapter ) || IS_HARDWARE_TYPE_8821( Adapter ) )
  731. {
  732. for ( regulation = 0; regulation < MAX_REGULATION_NUM; ++regulation )
  733. {
  734. for ( bw = 0; bw < MAX_5G_BANDWITH_NUM; ++bw )
  735. {
  736. for ( group = 0; group < MAX_5G_CHANNEL_NUM; ++group )
  737. {
  738. /* channels of 5G band in Hal_ReadTxPowerInfo8812A()
  739. 36,38,40,42,44,
  740. 46,48,50,52,54,
  741. 56,58,60,62,64,
  742. 100,102,104,106,108,
  743. 110,112,114,116,118,
  744. 120,122,124,126,128,
  745. 130,132,134,136,138,
  746. 140,142,144,149,151,
  747. 153,155,157,159,161,
  748. 163,165,167,168,169,
  749. 171,173,175,177 */
  750. if ( group == 0 )
  751. channel = 0; // index of chnl 36 in channel5G
  752. else if ( group == 1 )
  753. channel = 4; // index of chnl 44 in chanl5G
  754. else if ( group == 2 )
  755. channel = 7; // index of chnl 50 in chanl5G
  756. else if ( group == 3 )
  757. channel = 12; // index of chnl 60 in chanl5G
  758. else if ( group == 4 )
  759. channel = 15; // index of chnl 100 in chanl5G
  760. else if ( group == 5 )
  761. channel = 19; // index of chnl 108 in chanl5G
  762. else if ( group == 6 )
  763. channel = 23; // index of chnl 116 in chanl5G
  764. else if ( group == 7 )
  765. channel = 27; // index of chnl 124 in chanl5G
  766. else if ( group == 8 )
  767. channel = 31; // index of chnl 132 in chanl5G
  768. else if ( group == 9 )
  769. channel = 35; // index of chnl 140 in chanl5G
  770. else if ( group == 10 )
  771. channel = 38; // index of chnl 149 in chanl5G
  772. else if ( group == 11 )
  773. channel = 42; // index of chnl 157 in chanl5G
  774. else if ( group == 12 )
  775. channel = 46; // index of chnl 165 in chanl5G
  776. else
  777. channel = 51; // index of chnl 173 in chanl5G
  778. for ( rateSection = 1; rateSection < MAX_5G_RATE_SECTION_NUM; ++rateSection )
  779. {
  780. if ( pHalData->odmpriv.PhyRegPgValueType == PHY_REG_PG_EXACT_VALUE ) {
  781. // obtain the base dBm values in 5G band
  782. // OFDM => 54M, HT 1T => MCS7, HT 2T => MCS15,
  783. // VHT => 1SSMCS7, VHT 2T => 2SSMCS7
  784. if ( rateSection == 1 ) { //OFDM
  785. baseIndex5G = phy_getPowerByRateBaseIndex( BAND_ON_5G, MGN_54M );
  786. }
  787. else if ( rateSection == 2 ) { //HT 1T
  788. baseIndex5G = phy_getPowerByRateBaseIndex( BAND_ON_5G, MGN_MCS7 );
  789. }
  790. else if ( rateSection == 3 ) { //HT 2T
  791. baseIndex5G = phy_getPowerByRateBaseIndex( BAND_ON_5G, MGN_MCS15 );
  792. }
  793. else if ( rateSection == 4 ) { //VHT 1T
  794. baseIndex5G = phy_getPowerByRateBaseIndex( BAND_ON_5G, MGN_VHT1SS_MCS7 );
  795. }
  796. else if ( rateSection == 5 ) { //VHT 2T
  797. baseIndex5G = phy_getPowerByRateBaseIndex( BAND_ON_5G, MGN_VHT2SS_MCS7 );
  798. }
  799. }
  800. // we initially record the raw power limit value in rf path A, so we must obtain the raw
  801. // power limit value by using index rf path A and use it to calculate all the value of
  802. // all the path
  803. tempPwrLmt = pHalData->TxPwrLimit_5G[regulation][bw][rateSection][group][ODM_RF_PATH_A];
  804. if ( tempPwrLmt == MAX_POWER_INDEX )
  805. {
  806. if ( bw == 0 || bw == 1 ) { // 5G VHT and HT can cross reference
  807. DBG_871X( "No power limit table of the specified band %d, bandwidth %d, ratesection %d, group %d, rf path %d\n",
  808. 1, bw, rateSection, group, ODM_RF_PATH_A );
  809. if ( rateSection == 2 ) {
  810. pHalData->TxPwrLimit_5G[regulation][bw][2][group][ODM_RF_PATH_A] =
  811. pHalData->TxPwrLimit_5G[regulation][bw][4][group][ODM_RF_PATH_A];
  812. tempPwrLmt = pHalData->TxPwrLimit_5G[regulation]
  813. [bw][4][group][ODM_RF_PATH_A];
  814. }
  815. else if ( rateSection == 4 ) {
  816. pHalData->TxPwrLimit_5G[regulation][bw][4][group][ODM_RF_PATH_A] =
  817. pHalData->TxPwrLimit_5G[regulation][bw][2][group][ODM_RF_PATH_A];
  818. tempPwrLmt = pHalData->TxPwrLimit_5G[regulation]
  819. [bw][2][group][ODM_RF_PATH_A];
  820. }
  821. else if ( rateSection == 3 ) {
  822. pHalData->TxPwrLimit_5G[regulation][bw][3][group][ODM_RF_PATH_A] =
  823. pHalData->TxPwrLimit_5G[regulation][bw][5][group][ODM_RF_PATH_A];
  824. tempPwrLmt = pHalData->TxPwrLimit_5G[regulation]
  825. [bw][5][group][ODM_RF_PATH_A];
  826. }
  827. else if ( rateSection == 5 ) {
  828. pHalData->TxPwrLimit_5G[regulation][bw][5][group][ODM_RF_PATH_A] =
  829. pHalData->TxPwrLimit_5G[regulation][bw][3][group][ODM_RF_PATH_A];
  830. tempPwrLmt = pHalData->TxPwrLimit_5G[regulation]
  831. [bw][3][group][ODM_RF_PATH_A];
  832. }
  833. DBG_871X("use other value %d", tempPwrLmt);
  834. }
  835. }
  836. // process ODM_RF_PATH_A later
  837. for ( rfPath = ODM_RF_PATH_B; rfPath < MAX_RF_PATH_NUM; ++rfPath )
  838. {
  839. if ( pHalData->odmpriv.PhyRegPgValueType == PHY_REG_PG_EXACT_VALUE )
  840. BW40PwrBasedBm5G = pHalData->TxPwrByRateBase5G[rfPath][baseIndex5G];
  841. else
  842. BW40PwrBasedBm5G = Adapter->registrypriv.RegPowerBase * 2;
  843. if ( tempPwrLmt != MAX_POWER_INDEX ) {
  844. tempValue = tempPwrLmt - BW40PwrBasedBm5G;
  845. pHalData->TxPwrLimit_5G[regulation][bw][rateSection][group][rfPath] = tempValue;
  846. }
  847. DBG_871X("TxPwrLimit_5G[regulation %d][bw %d][rateSection %d][group %d] %d=\n\
  848. (TxPwrLimit in dBm %d - BW40PwrLmt5G[channel %d][rfPath %d] %d) \n",
  849. regulation, bw, rateSection, group, pHalData->TxPwrLimit_5G[regulation][bw][rateSection][group][rfPath],
  850. tempPwrLmt, channel, rfPath, BW40PwrBasedBm5G );
  851. }
  852. }
  853. }
  854. }
  855. }
  856. // process value of ODM_RF_PATH_A
  857. for ( regulation = 0; regulation < MAX_REGULATION_NUM; ++regulation )
  858. {
  859. for ( bw = 0; bw < MAX_5G_BANDWITH_NUM; ++bw )
  860. {
  861. for ( group = 0; group < MAX_5G_CHANNEL_NUM; ++group )
  862. {
  863. if ( group == 0 )
  864. channel = 0; // index of chnl 36 in channel5G
  865. else if ( group == 1 )
  866. channel = 4; // index of chnl 44 in chanl5G
  867. else if ( group == 2 )
  868. channel = 7; // index of chnl 50 in chanl5G
  869. else if ( group == 3 )
  870. channel = 12; // index of chnl 60 in chanl5G
  871. else if ( group == 4 )
  872. channel = 15; // index of chnl 100 in chanl5G
  873. else if ( group == 5 )
  874. channel = 19; // index of chnl 108 in chanl5G
  875. else if ( group == 6 )
  876. channel = 23; // index of chnl 116 in chanl5G
  877. else if ( group == 7 )
  878. channel = 27; // index of chnl 124 in chanl5G
  879. else if ( group == 8 )
  880. channel = 31; // index of chnl 132 in chanl5G
  881. else if ( group == 9 )
  882. channel = 35; // index of chnl 140 in chanl5G
  883. else if ( group == 10 )
  884. channel = 38; // index of chnl 149 in chanl5G
  885. else if ( group == 11 )
  886. channel = 42; // index of chnl 157 in chanl5G
  887. else if ( group == 12 )
  888. channel = 46; // index of chnl 165 in chanl5G
  889. else
  890. channel = 51; // index of chnl 173 in chanl5G
  891. for ( rateSection = 0; rateSection < MAX_5G_RATE_SECTION_NUM; ++rateSection )
  892. {
  893. if ( pHalData->odmpriv.PhyRegPgValueType == PHY_REG_PG_EXACT_VALUE ) {
  894. // obtain the base dBm values in 5G band
  895. // OFDM => 54M, HT 1T => MCS7, HT 2T => MCS15,
  896. // VHT => 1SSMCS7, VHT 2T => 2SSMCS7
  897. if ( rateSection == 1 ) { //OFDM
  898. baseIndex5G = phy_getPowerByRateBaseIndex( BAND_ON_5G, MGN_54M );
  899. }
  900. else if ( rateSection == 2 ) { //HT 1T
  901. baseIndex5G = phy_getPowerByRateBaseIndex( BAND_ON_5G, MGN_MCS7 );
  902. }
  903. else if ( rateSection == 3 ) { //HT 2T
  904. baseIndex5G = phy_getPowerByRateBaseIndex( BAND_ON_5G, MGN_MCS15 );
  905. }
  906. else if ( rateSection == 4 ) { //VHT 1T
  907. baseIndex5G = phy_getPowerByRateBaseIndex( BAND_ON_5G, MGN_VHT1SS_MCS7 );
  908. }
  909. else if ( rateSection == 5 ) { //VHT 2T
  910. baseIndex5G = phy_getPowerByRateBaseIndex( BAND_ON_5G, MGN_VHT2SS_MCS7 );
  911. }
  912. }
  913. tempPwrLmt = pHalData->TxPwrLimit_5G[regulation][bw][rateSection][group][ODM_RF_PATH_A];
  914. if ( tempPwrLmt == MAX_POWER_INDEX )
  915. {
  916. if ( bw == 0 || bw == 1 ) { // 5G VHT and HT can cross reference
  917. DBG_871X("No power limit table of the specified band %d, bandwidth %d, ratesection %d, group %d, rf path %d\n",
  918. 1, bw, rateSection, group, ODM_RF_PATH_A );
  919. if ( rateSection == 2 )
  920. tempPwrLmt = pHalData->TxPwrLimit_5G[regulation]
  921. [bw][4][group][ODM_RF_PATH_A];
  922. else if ( rateSection == 4 )
  923. tempPwrLmt = pHalData->TxPwrLimit_5G[regulation]
  924. [bw][2][group][ODM_RF_PATH_A];
  925. else if ( rateSection == 3 )
  926. tempPwrLmt = pHalData->TxPwrLimit_5G[regulation]
  927. [bw][5][group][ODM_RF_PATH_A];
  928. else if ( rateSection == 5 )
  929. tempPwrLmt = pHalData->TxPwrLimit_5G[regulation]
  930. [bw][3][group][ODM_RF_PATH_A];
  931. DBG_871X("use other value %d", tempPwrLmt );
  932. }
  933. }
  934. if ( pHalData->odmpriv.PhyRegPgValueType == PHY_REG_PG_EXACT_VALUE )
  935. BW40PwrBasedBm5G = pHalData->TxPwrByRateBase5G[ODM_RF_PATH_A][baseIndex5G];
  936. else
  937. BW40PwrBasedBm5G = Adapter->registrypriv.RegPowerBase * 2;
  938. if ( tempPwrLmt != MAX_POWER_INDEX ) {
  939. tempValue = tempPwrLmt - BW40PwrBasedBm5G;
  940. pHalData->TxPwrLimit_5G[regulation][bw][rateSection][group][ODM_RF_PATH_A] = tempValue;
  941. }
  942. DBG_871X("TxPwrLimit_5G[regulation %d][bw %d][rateSection %d][group %d] %d=\n\
  943. (TxPwrLimit in dBm %d - BW40PwrLmt5G[channel %d][rfPath %d] %d) \n",
  944. regulation, bw, rateSection, group, pHalData->TxPwrLimit_5G[regulation][bw][rateSection][group][ODM_RF_PATH_A],
  945. tempPwrLmt, channel, ODM_RF_PATH_A, BW40PwrBasedBm5G );
  946. }
  947. }
  948. }
  949. }
  950. }
  951. DBG_871X("<===== PHY_ConvertPowerLimitToPowerIndex()\n" );
  952. }
  953. VOID
  954. PHY_SetPowerLimitTableValue(
  955. IN PDM_ODM_T pDM_Odm,
  956. IN s8* Regulation,
  957. IN s8* Band,
  958. IN s8* Bandwidth,
  959. IN s8* RateSection,
  960. IN s8* RfPath,
  961. IN s8* Channel,
  962. IN s8* PowerLimit
  963. )
  964. {
  965. PADAPTER Adapter = pDM_Odm->Adapter;
  966. HAL_DATA_TYPE *pHalData = GET_HAL_DATA( Adapter );
  967. u8 regulation=0, bandwidth=0, rateSection=0,
  968. channel, powerLimit, channelGroup;
  969. DBG_871X( "Index of power limit table \
  970. [band %s][regulation %s][bw %s][rate section %s][rf path %s][chnl %s][val %s]\n",
  971. Band, Regulation, Bandwidth, RateSection, RfPath, Channel, PowerLimit ) ;
  972. if ( !GetU1ByteIntegerFromStringInDecimal( Channel, &channel ) ||
  973. !GetU1ByteIntegerFromStringInDecimal( PowerLimit, &powerLimit ) )
  974. {
  975. DBG_871X("Illegal index of power limit table [chnl %s][val %s]\n", Channel, PowerLimit );
  976. }
  977. powerLimit = powerLimit > MAX_POWER_INDEX ? MAX_POWER_INDEX : powerLimit;
  978. if ( eqNByte( Regulation, "FCC", 3 ) ) regulation = 0;
  979. else if ( eqNByte( Regulation, "MKK", 3 ) ) regulation = 1;
  980. else if ( eqNByte( Regulation, "ETSI", 4 ) ) regulation = 2;
  981. if ( eqNByte( RateSection, "CCK", 3 ) )
  982. rateSection = 0;
  983. else if ( eqNByte( RateSection, "OFDM", 4 ) )
  984. rateSection = 1;
  985. else if ( eqNByte( RateSection, "HT", 2 ) && eqNByte( RfPath, "1T", 2 ) )
  986. rateSection = 2;
  987. else if ( eqNByte( RateSection, "HT", 2 ) && eqNByte( RfPath, "2T", 2 ) )
  988. rateSection = 3;
  989. else if ( eqNByte( RateSection, "VHT", 3 ) && eqNByte( RfPath, "1T", 2 ) )
  990. rateSection = 4;
  991. else if ( eqNByte( RateSection, "VHT", 3 ) && eqNByte( RfPath, "2T", 2 ) )
  992. rateSection = 5;
  993. if ( eqNByte( Bandwidth, "20M", 3 ) ) bandwidth = 0;
  994. else if ( eqNByte( Bandwidth, "40M", 3 ) ) bandwidth = 1;
  995. else if ( eqNByte( Bandwidth, "80M", 3 ) ) bandwidth = 2;
  996. else if ( eqNByte( Bandwidth, "160M", 4 ) ) bandwidth = 3;
  997. if ( eqNByte( Band, "2.4G", 4 ) )
  998. {
  999. DBG_871X( "2.4G Band value : [regulation %d][bw %d][rate_section %d][chnl %d][val %d]\n",
  1000. regulation, bandwidth, rateSection, channel, powerLimit );
  1001. channelGroup = phy_GetChannelGroup( BAND_ON_2_4G, channel );
  1002. pHalData->TxPwrLimit_2_4G[regulation][bandwidth][rateSection][channelGroup][ODM_RF_PATH_A] = powerLimit;
  1003. }
  1004. else if ( eqNByte( Band, "5G", 2 ) )
  1005. {
  1006. DBG_871X("5G Band value : [regulation %d][bw %d][rate_section %d][chnl %d][val %d]\n",
  1007. regulation, bandwidth, rateSection, channel, powerLimit );
  1008. channelGroup = phy_GetChannelGroup( BAND_ON_5G, channel );
  1009. pHalData->TxPwrLimit_5G[regulation][bandwidth][rateSection][channelGroup][ODM_RF_PATH_A] = powerLimit;
  1010. }
  1011. else
  1012. {
  1013. DBG_871X("Cannot recognize the band info in %s\n", Band );
  1014. return;
  1015. }
  1016. }
  1017. u8
  1018. PHY_GetPowerLimitValue(
  1019. IN PADAPTER Adapter,
  1020. IN u32 RegPwrTblSel,
  1021. IN BAND_TYPE Band,
  1022. IN CHANNEL_WIDTH Bandwidth,
  1023. IN RF_PATH RfPath,
  1024. IN u8 DataRate,
  1025. IN u8 Channel
  1026. )
  1027. {
  1028. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  1029. s16 band = -1, regulation = -1, bandwidth = -1,
  1030. rfPath = -1, rateSection = -1, channelGroup = -1;
  1031. u8 powerLimit = MAX_POWER_INDEX;
  1032. if ( ( Adapter->registrypriv.RegEnableTxPowerLimit == 0 && pHalData->EEPROMRegulatory != 1 ) ||
  1033. pHalData->EEPROMRegulatory == 2 )
  1034. return MAX_POWER_INDEX;
  1035. switch( RegPwrTblSel )
  1036. {
  1037. case 1:
  1038. regulation = TXPWR_LMT_ETSI;
  1039. break;
  1040. case 2:
  1041. regulation = TXPWR_LMT_MKK;
  1042. break;
  1043. case 3:
  1044. regulation = TXPWR_LMT_FCC;
  1045. break;
  1046. default:
  1047. regulation = TXPWR_LMT_FCC;
  1048. break;
  1049. }
  1050. //DBG_871X("pregistrypriv->RegPwrTblSel %d\n", RegPwrTblSel);
  1051. if ( Band == BAND_ON_2_4G ) band = 0;
  1052. else if ( Band == BAND_ON_5G ) band = 1;
  1053. if ( Bandwidth == CHANNEL_WIDTH_20 ) bandwidth = 0;
  1054. else if ( Bandwidth == CHANNEL_WIDTH_40 ) bandwidth = 1;
  1055. else if ( Bandwidth == CHANNEL_WIDTH_80 ) bandwidth = 2;
  1056. else if ( Bandwidth == CHANNEL_WIDTH_160 ) bandwidth = 3;
  1057. switch ( DataRate )
  1058. {
  1059. case MGN_1M: case MGN_2M: case MGN_5_5M: case MGN_11M:
  1060. rateSection = 0;
  1061. break;
  1062. case MGN_6M: case MGN_9M: case MGN_12M: case MGN_18M:
  1063. case MGN_24M: case MGN_36M: case MGN_48M: case MGN_54M:
  1064. rateSection = 1;
  1065. break;
  1066. case MGN_MCS0: case MGN_MCS1: case MGN_MCS2: case MGN_MCS3:
  1067. case MGN_MCS4: case MGN_MCS5: case MGN_MCS6: case MGN_MCS7:
  1068. rateSection = 2;
  1069. break;
  1070. case MGN_MCS8: case MGN_MCS9: case MGN_MCS10: case MGN_MCS11:
  1071. case MGN_MCS12: case MGN_MCS13: case MGN_MCS14: case MGN_MCS15:
  1072. rateSection = 3;
  1073. break;
  1074. case MGN_VHT1SS_MCS0: case MGN_VHT1SS_MCS1: case MGN_VHT1SS_MCS2:
  1075. case MGN_VHT1SS_MCS3: case MGN_VHT1SS_MCS4: case MGN_VHT1SS_MCS5:
  1076. case MGN_VHT1SS_MCS6: case MGN_VHT1SS_MCS7: case MGN_VHT1SS_MCS8:
  1077. case MGN_VHT1SS_MCS9:
  1078. rateSection = 4;
  1079. break;
  1080. case MGN_VHT2SS_MCS0: case MGN_VHT2SS_MCS1: case MGN_VHT2SS_MCS2:
  1081. case MGN_VHT2SS_MCS3: case MGN_VHT2SS_MCS4: case MGN_VHT2SS_MCS5:
  1082. case MGN_VHT2SS_MCS6: case MGN_VHT2SS_MCS7: case MGN_VHT2SS_MCS8:
  1083. case MGN_VHT2SS_MCS9:
  1084. rateSection = 5;
  1085. break;
  1086. default:
  1087. DBG_871X("Wrong rate 0x%x\n", DataRate );
  1088. break;
  1089. }
  1090. if ( BAND_ON_2_4G && rateSection > 3 )
  1091. DBG_871X("Wrong rate 0x%x: No VHT in 2.4G Band\n", DataRate );
  1092. if ( BAND_ON_5G && rateSection == 0 )
  1093. DBG_871X("Wrong rate 0x%x: No CCK in 5G Band\n", DataRate );
  1094. // workaround for wrong index combination to obtain tx power limit,
  1095. // OFDM only exists in BW 20M
  1096. if ( rateSection == 1 )
  1097. bandwidth = 0;
  1098. // workaround for wrong indxe combination to obtain tx power limit,
  1099. // HT on 80M will reference to HT on 40M
  1100. if ( ( rateSection == 2 || rateSection == 3 ) && Band == BAND_ON_5G && bandwidth == 2 ) {
  1101. bandwidth = 1;
  1102. }
  1103. if ( Band == BAND_ON_2_4G )
  1104. channelGroup = phy_GetChannelGroup( BAND_ON_2_4G, Channel );
  1105. else if ( Band == BAND_ON_5G )
  1106. channelGroup = phy_GetChannelGroup( BAND_ON_5G, Channel );
  1107. else if ( Band == BAND_ON_BOTH )
  1108. {
  1109. // BAND_ON_BOTH don't care temporarily
  1110. }
  1111. if ( band == -1 || regulation == -1 || bandwidth == -1 ||
  1112. rateSection == -1 || channelGroup == -1 )
  1113. {
  1114. DBG_871X("Wrong index value to access power limit table \
  1115. [band %d][regulation %d][bandwidth %d][rf_path %d][rate_section %d][chnlGroup %d]\n",
  1116. band, regulation, bandwidth, RfPath, rateSection, channelGroup );
  1117. return 0xFF;
  1118. }
  1119. if ( Band == BAND_ON_2_4G )
  1120. powerLimit = pHalData->TxPwrLimit_2_4G[regulation]
  1121. [bandwidth][rateSection][channelGroup][RfPath];
  1122. else if ( Band == BAND_ON_5G )
  1123. powerLimit = pHalData->TxPwrLimit_5G[regulation]
  1124. [bandwidth][rateSection][channelGroup][RfPath];
  1125. else
  1126. DBG_871X("No power limit table of the specified band\n" );
  1127. // combine 5G VHT & HT rate
  1128. // 5G 20M and 40M HT and VHT can cross reference
  1129. /*if ( Band == BAND_ON_5G && powerLimit == MAX_POWER_INDEX ) {
  1130. if ( bandwidth == 0 || bandwidth == 1 ) {
  1131. if ( rateSection == 2 )
  1132. powerLimit = pHalData->TxPwrLimit_5G[regulation]
  1133. [bandwidth][4][channelGroup][RfPath];
  1134. else if ( rateSection == 4 )
  1135. powerLimit = pHalData->TxPwrLimit_5G[regulation]
  1136. [bandwidth][2][channelGroup][RfPath];
  1137. else if ( rateSection == 3 )
  1138. powerLimit = pHalData->TxPwrLimit_5G[regulation]
  1139. [bandwidth][5][channelGroup][RfPath];
  1140. else if ( rateSection == 5 )
  1141. powerLimit = pHalData->TxPwrLimit_5G[regulation]
  1142. [bandwidth][3][channelGroup][RfPath];
  1143. }
  1144. }*/
  1145. //DBG_871X("TxPwrLmt[Regulation %d][Band %d][BW %d][RFPath %d][Rate 0x%x][Chnl %d] = %d\n",
  1146. // regulation, pHalData->CurrentBandType, Bandwidth, RfPath, DataRate, Channel, powerLimit);
  1147. return powerLimit;
  1148. }
  1149. //
  1150. // 2012/10/18
  1151. //
  1152. VOID
  1153. PHY_StorePwrByRateIndexVhtSeries(
  1154. IN PADAPTER Adapter,
  1155. IN u32 RegAddr,
  1156. IN u32 BitMask,
  1157. IN u32 Data
  1158. )
  1159. {
  1160. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  1161. u8 rf_path, rate_section;
  1162. //
  1163. // For VHT series TX power by rate table.
  1164. // VHT TX power by rate off setArray =
  1165. // Band:-2G&5G = 0 / 1
  1166. // RF: at most 4*4 = ABCD=0/1/2/3
  1167. // CCK=0 11/5.5/2/1
  1168. // OFDM=1/2 18/12/9/6 54/48/36/24
  1169. // HT=3/4/56 MCS0-3 MCS4-7 MCS8-11 MCS12-15
  1170. // VHT=7/8/9/10/11 1SSMCS0-3 1SSMCS4-7 2SSMCS1/0/1SSMCS/9/8 2SSMCS2-5
  1171. //
  1172. // #define TX_PWR_BY_RATE_NUM_BAND 2
  1173. // #define TX_PWR_BY_RATE_NUM_RF 4
  1174. // #define TX_PWR_BY_RATE_NUM_SECTION 12
  1175. //
  1176. //
  1177. // 1. Judge TX power by rate array band type.
  1178. //
  1179. //if(RegAddr == rTxAGC_A_CCK11_CCK1_JAguar || RegAddr == rTxAGC_B_CCK11_CCK1_JAguar)
  1180. if ((RegAddr & 0xFFF) == 0xC20)
  1181. {
  1182. pHalData->TxPwrByRateTable++; // Record that it is the first data to record.
  1183. pHalData->TxPwrByRateBand = 0;
  1184. }
  1185. if ((RegAddr & 0xFFF) == 0xe20)
  1186. {
  1187. pHalData->TxPwrByRateTable++; // The value should be 2 now.
  1188. }
  1189. if ((RegAddr & 0xFFF) == 0xC24 && pHalData->TxPwrByRateTable != 1)
  1190. {
  1191. pHalData->TxPwrByRateTable++; // The value should be 3 bow.
  1192. pHalData->TxPwrByRateBand = 1;
  1193. }
  1194. //
  1195. // 2. Judge TX power by rate array RF type
  1196. //
  1197. if ((RegAddr & 0xF00) == 0xC00)
  1198. {
  1199. rf_path = 0;
  1200. }
  1201. else if ((RegAddr & 0xF00) == 0xE00)
  1202. {
  1203. rf_path = 1;
  1204. }
  1205. //
  1206. // 3. Judge TX power by rate array rate section
  1207. //
  1208. if (rf_path == 0)
  1209. {
  1210. rate_section = (u8)((RegAddr&0xFFF)-0xC20)/4;
  1211. }
  1212. else if (rf_path == 1)
  1213. {
  1214. rate_section = (u8)((RegAddr&0xFFF)-0xE20)/4;
  1215. }
  1216. pHalData->TxPwrByRateOffset[pHalData->TxPwrByRateBand][rf_path][rate_section] = Data;
  1217. //DBG_871X("VHT TxPwrByRateOffset Addr-%x==>BAND/RF/SEC=%d/%d/%d = %08x\n",
  1218. // RegAddr, pHalData->TxPwrByRateBand, rf_path, rate_section, Data);
  1219. }
  1220. VOID
  1221. phy_ChangePGDataFromExactToRelativeValue(
  1222. IN u32* pData,
  1223. IN u8 Start,
  1224. IN u8 End,
  1225. IN u8 BaseValue
  1226. )
  1227. {
  1228. s8 i = 0;
  1229. u8 TempValue = 0;
  1230. u32 TempData = 0;
  1231. //BaseValue = ( BaseValue & 0xf ) + ( ( BaseValue >> 4 ) & 0xf ) * 10;
  1232. //RT_TRACE(COMP_INIT, DBG_LOUD, ("Corrected BaseValue %u\n", BaseValue ) );
  1233. for ( i = 3; i >= 0; --i )
  1234. {
  1235. if ( i >= Start && i <= End )
  1236. {
  1237. // Get the exact value
  1238. TempValue = ( u8 ) ( *pData >> ( i * 8 ) ) & 0xF;
  1239. TempValue += ( ( u8 ) ( ( *pData >> ( i * 8 + 4 ) ) & 0xF ) ) * 10;
  1240. // Change the value to a relative value
  1241. TempValue = ( TempValue > BaseValue ) ? TempValue - BaseValue : BaseValue - TempValue;
  1242. }
  1243. else
  1244. {
  1245. TempValue = ( u8 ) ( *pData >> ( i * 8 ) ) & 0xFF;
  1246. }
  1247. TempData <<= 8;
  1248. TempData |= TempValue;
  1249. }
  1250. *pData = TempData;
  1251. }
  1252. VOID phy_PreprocessVHTPGDataFromExactToRelativeValue(
  1253. IN PADAPTER Adapter,
  1254. IN u32 RegAddr,
  1255. IN u32 BitMask,
  1256. IN u32* pData
  1257. )
  1258. {
  1259. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  1260. u8 rf_path, rate_section, BaseValue = 0;
  1261. //
  1262. // For VHT series TX power by rate table.
  1263. // VHT TX power by rate off setArray =
  1264. // Band:-2G&5G = 0 / 1
  1265. // RF: at most 4*4 = ABCD=0/1/2/3
  1266. // CCK=0 11/5.5/2/1
  1267. // OFDM=1/2 18/12/9/6 54/48/36/24
  1268. // HT=3/4/56 MCS0-3 MCS4-7 MCS8-11 MCS12-15
  1269. // VHT=7/8/9/10/11 1SSMCS0-3 1SSMCS4-7 2SSMCS1/0/1SSMCS/9/8 2SSMCS2-5
  1270. //
  1271. // #define TX_PWR_BY_RATE_NUM_BAND 2
  1272. // #define TX_PWR_BY_RATE_NUM_RF 4
  1273. // #define TX_PWR_BY_RATE_NUM_SECTION 12
  1274. //
  1275. // Judge TX power by rate array RF type
  1276. //
  1277. if ( ( RegAddr & 0xF00 ) == 0xC00 )
  1278. {
  1279. rf_path = 0;
  1280. }
  1281. else if ( ( RegAddr & 0xF00 ) == 0xE00 )
  1282. {
  1283. rf_path = 1;
  1284. }
  1285. //
  1286. // Judge TX power by rate array rate section
  1287. //
  1288. if ( rf_path == 0 )
  1289. {
  1290. rate_section = ( u8) ( ( RegAddr & 0xFFF ) - 0xC20 ) / 4;
  1291. }
  1292. else if ( rf_path == 1 )
  1293. {
  1294. rate_section = ( u8 ) ( ( RegAddr & 0xFFF ) - 0xE20 ) / 4;
  1295. }
  1296. switch ( RegAddr )
  1297. {
  1298. case 0xC20:
  1299. case 0xE20:
  1300. //RT_TRACE(COMP_INIT, DBG_LOUD, ("RegAddr %x\n", RegAddr ));
  1301. //RT_TRACE(COMP_INIT, DBG_LOUD, ("pHalData->TxPwrByRateOffset[%d][%d][%d] = 0x%x, before changing to relative\n",
  1302. // pHalData->TxPwrByRateBand, rf_path, rate_section, *pData ));
  1303. BaseValue = ( ( u8 ) ( *pData >> 28 ) & 0xF ) *10 + ( ( u8 ) ( *pData >> 24 ) & 0xF );
  1304. phy_ChangePGDataFromExactToRelativeValue( pData, 0, 3, BaseValue );
  1305. //RT_TRACE(COMP_INIT, DBG_LOUD, ("pHalData->TxPwrByRateOffset[%d][%d][%d] = 0x%x, after changing to relative\n",
  1306. // pHalData->TxPwrByRateBand, rf_path, rate_section, *pData ));
  1307. break;
  1308. case 0xC28:
  1309. case 0xE28:
  1310. case 0xC30:
  1311. case 0xE30:
  1312. case 0xC38:
  1313. case 0xE38:
  1314. //RT_TRACE(COMP_INIT, DBG_LOUD, ("RegAddr %x\n", RegAddr ));
  1315. //RT_TRACE(COMP_INIT, DBG_LOUD, ("pHalData->TxPwrByRateOffset[%d][%d][%d] = 0x%x, before changing to relative\n",
  1316. // pHalData->TxPwrByRateBand, rf_path, rate_section, *pData ));
  1317. //RT_TRACE(COMP_INIT, DBG_LOUD, ("pHalData->TxPwrByRateOffset[%d][%d][%d] = 0x%x, before changing to relative\n",
  1318. // pHalData->TxPwrByRateBand, rf_path, rate_section - 1, pHalData->TxPwrByRateOffset[pHalData->TxPwrByRateBand][rf_path][rate_section - 1] ));
  1319. BaseValue = ( ( u8 ) ( *pData >> 28 ) & 0xF ) *10 + ( ( u8 ) ( *pData >> 24 ) & 0xF );
  1320. phy_ChangePGDataFromExactToRelativeValue( pData, 0, 3, BaseValue );
  1321. phy_ChangePGDataFromExactToRelativeValue(
  1322. &( pHalData->TxPwrByRateOffset[pHalData->TxPwrByRateBand][rf_path][rate_section - 1] ),
  1323. 0, 3, BaseValue);
  1324. //RT_TRACE(COMP_INIT, DBG_LOUD, ("pHalData->TxPwrByRateOffset[%d][%d][%d] = 0x%x, after changing to relative\n",
  1325. // pHalData->TxPwrByRateBand, rf_path, rate_section, *pData ));
  1326. //RT_TRACE(COMP_INIT, DBG_LOUD, ("pHalData->TxPwrByRateOffset[%d][%d][%d] = 0x%x, after changing to relative\n",
  1327. // pHalData->TxPwrByRateBand, rf_path, rate_section - 1, pHalData->TxPwrByRateOffset[pHalData->TxPwrByRateBand][rf_path][rate_section - 1] ));
  1328. break;
  1329. case 0xC44:
  1330. case 0xE44:
  1331. //RT_TRACE(COMP_INIT, DBG_LOUD, ("RegAddr %x\n", RegAddr ));
  1332. //RT_TRACE(COMP_INIT, DBG_LOUD, ("pHalData->TxPwrByRateOffset[%d][%d][%d] = 0x%x, before changing to relative\n",
  1333. // pHalData->TxPwrByRateBand, rf_path, rate_section, *pData ));
  1334. //RT_TRACE(COMP_INIT, DBG_LOUD, ("pHalData->TxPwrByRateOffset[%d][%d][%d] = 0x%x, before changing to relative\n",
  1335. // pHalData->TxPwrByRateBand, rf_path, rate_section - 1, pHalData->TxPwrByRateOffset[pHalData->TxPwrByRateBand][rf_path][rate_section - 1] ));
  1336. //RT_TRACE(COMP_INIT, DBG_LOUD, ("pHalData->TxPwrByRateOffset[%d][%d][%d] = 0x%x, before changing to relative\n",
  1337. // pHalData->TxPwrByRateBand, rf_path, rate_section - 2, pHalData->TxPwrByRateOffset[pHalData->TxPwrByRateBand][rf_path][rate_section - 2] ));
  1338. BaseValue = ( ( u8 ) ( pHalData->TxPwrByRateOffset[pHalData->TxPwrByRateBand][rf_path][rate_section - 1] >> 28 ) & 0xF ) * 10 +
  1339. ( ( u8 ) ( pHalData->TxPwrByRateOffset[pHalData->TxPwrByRateBand][rf_path][rate_section - 1] >> 24 ) & 0xF );
  1340. phy_ChangePGDataFromExactToRelativeValue( pData, 0, 1, BaseValue );
  1341. phy_ChangePGDataFromExactToRelativeValue(
  1342. &( pHalData->TxPwrByRateOffset[pHalData->TxPwrByRateBand][rf_path][rate_section - 1] ),
  1343. 0, 3, BaseValue);
  1344. phy_ChangePGDataFromExactToRelativeValue(
  1345. &( pHalData->TxPwrByRateOffset[pHalData->TxPwrByRateBand][rf_path][rate_section - 2] ),
  1346. 0, 3, BaseValue);
  1347. //RT_TRACE(COMP_INIT, DBG_LOUD, ("pHalData->TxPwrByRateOffset[%d][%d][%d] = 0x%x, after changing to relative\n",
  1348. // pHalData->TxPwrByRateBand, rf_path, rate_section, *pData ));
  1349. //RT_TRACE(COMP_INIT, DBG_LOUD, ("pHalData->TxPwrByRateOffset[%d][%d][%d] = 0x%x, after changing to relative\n",
  1350. // pHalData->TxPwrByRateBand, rf_path, rate_section - 1, pHalData->TxPwrByRateOffset[pHalData->TxPwrByRateBand][rf_path][rate_section - 1] ));
  1351. //RT_TRACE(COMP_INIT, DBG_LOUD, ("pHalData->TxPwrByRateOffset[%d][%d][%d] = 0x%x, after changing to relative\n",
  1352. // pHalData->TxPwrByRateBand, rf_path, rate_section - 2, pHalData->TxPwrByRateOffset[pHalData->TxPwrByRateBand][rf_path][rate_section - 2] ));
  1353. break;
  1354. case 0xC4C:
  1355. case 0xE4C:
  1356. //RT_TRACE(COMP_INIT, DBG_LOUD, ("RegAddr %x\n", RegAddr ));
  1357. //RT_TRACE(COMP_INIT, DBG_LOUD, ("pHalData->TxPwrByRateOffset[%d][%d][%d] = 0x%x, before changing to relative\n",
  1358. // pHalData->TxPwrByRateBand, rf_path, rate_section, *pData ));
  1359. //RT_TRACE(COMP_INIT, DBG_LOUD, ("pHalData->TxPwrByRateOffset[%d][%d][%d] = 0x%x, before changing to relative\n",
  1360. // pHalData->TxPwrByRateBand, rf_path, rate_section - 1, pHalData->TxPwrByRateOffset[pHalData->TxPwrByRateBand][rf_path][rate_section - 1] ));
  1361. //RT_TRACE(COMP_INIT, DBG_LOUD, ("pHalData->TxPwrByRateOffset[%d][%d][%d] = 0x%x, before changing to relative\n",
  1362. // pHalData->TxPwrByRateBand, rf_path, rate_section - 2, pHalData->TxPwrByRateOffset[pHalData->TxPwrByRateBand][rf_path][rate_section - 2] ));
  1363. BaseValue = ( ( u8 ) ( *pData >> 12 ) & 0xF ) *10 + ( ( u8 ) ( *pData >> 8 ) & 0xF );
  1364. phy_ChangePGDataFromExactToRelativeValue( pData, 0, 3, BaseValue );
  1365. phy_ChangePGDataFromExactToRelativeValue(
  1366. &( pHalData->TxPwrByRateOffset[pHalData->TxPwrByRateBand][rf_path][rate_section - 1] ),
  1367. 0, 3, BaseValue);
  1368. phy_ChangePGDataFromExactToRelativeValue(
  1369. &( pHalData->TxPwrByRateOffset[pHalData->TxPwrByRateBand][rf_path][rate_section - 2] ),
  1370. 2, 3, BaseValue);
  1371. //RT_TRACE(COMP_INIT, DBG_LOUD, ("pHalData->TxPwrByRateOffset[%d][%d][%d] = 0x%x, after changing to relative\n",
  1372. // pHalData->TxPwrByRateBand, rf_path, rate_section, *pData ));
  1373. //RT_TRACE(COMP_INIT, DBG_LOUD, ("pHalData->TxPwrByRateOffset[%d][%d][%d] = 0x%x, after changing to relative\n",
  1374. // pHalData->TxPwrByRateBand, rf_path, rate_section - 1, pHalData->TxPwrByRateOffset[pHalData->TxPwrByRateBand][rf_path][rate_section - 1] ));
  1375. //RT_TRACE(COMP_INIT, DBG_LOUD, ("pHalData->TxPwrByRateOffset[%d][%d][%d] = 0x%x, after changing to relative\n",
  1376. // pHalData->TxPwrByRateBand, rf_path, rate_section - 2, pHalData->TxPwrByRateOffset[pHalData->TxPwrByRateBand][rf_path][rate_section - 2] ));
  1377. break;
  1378. }
  1379. }
  1380. VOID
  1381. phy_PreprocessPGDataFromExactToRelativeValue(
  1382. IN PADAPTER Adapter,
  1383. IN u4Byte RegAddr,
  1384. IN u4Byte BitMask,
  1385. IN pu4Byte pData
  1386. )
  1387. {
  1388. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  1389. u1Byte BaseValue = 0;
  1390. if ( RegAddr == rTxAGC_A_Rate54_24 )
  1391. {
  1392. //DBG_871X("RegAddr %x\n", RegAddr );
  1393. //DBG_871X("pHalData->MCSTxPowerLevelOriginalOffset[%d][1] = 0x%x, before changing to relative\n",
  1394. // pHalData->pwrGroupCnt, *pData );
  1395. //DBG_871X("pHalData->MCSTxPowerLevelOriginalOffset[%d][0] = 0x%x, before changing to relative\n",
  1396. // pHalData->pwrGroupCnt, pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][0] );
  1397. BaseValue = ( ( u8 ) ( *pData >> 28 ) & 0xF ) *10 + ( ( u8 ) ( *pData >> 24 ) & 0xF );
  1398. //DBG_871X("BaseValue = %d\n", BaseValue );
  1399. phy_ChangePGDataFromExactToRelativeValue( pData, 0, 3, BaseValue );
  1400. phy_ChangePGDataFromExactToRelativeValue(
  1401. &( pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][0] ),
  1402. 0, 3, BaseValue);
  1403. //DBG_871X("pHalData->MCSTxPowerLevelOriginalOffset[%d][1] = 0x%x, after changing to relative\n",
  1404. // pHalData->pwrGroupCnt, *pData );
  1405. //DBG_871X("pHalData->MCSTxPowerLevelOriginalOffset[%d][0] = 0x%x, after changing to relative\n",
  1406. // pHalData->pwrGroupCnt, pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][0] );
  1407. }
  1408. if ( RegAddr == rTxAGC_A_CCK1_Mcs32 )
  1409. {
  1410. pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][6] = *pData;
  1411. //DBG_871X("MCSTxPowerLevelOriginalOffset[%d][6] = 0x%x\n", pHalData->pwrGroupCnt,
  1412. // pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][6]);
  1413. }
  1414. if ( RegAddr == rTxAGC_B_CCK11_A_CCK2_11 && BitMask == 0xffffff00 )
  1415. {
  1416. pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][7] = *pData;
  1417. //DBG_871X("MCSTxPowerLevelOriginalOffset[%d][7] = 0x%x\n", pHalData->pwrGroupCnt,
  1418. // pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][7]);
  1419. }
  1420. if ( RegAddr == rTxAGC_A_Mcs07_Mcs04 )
  1421. {
  1422. //DBG_871X("RegAddr %x\n", RegAddr );
  1423. //DBG_871X("pHalData->MCSTxPowerLevelOriginalOffset[%d][3] = 0x%x, before changing to relative\n",
  1424. // pHalData->pwrGroupCnt, *pData );
  1425. //DBG_871X("pHalData->MCSTxPowerLevelOriginalOffset[%d][2] = 0x%x, before changing to relative\n",
  1426. // pHalData->pwrGroupCnt, pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][2] );
  1427. BaseValue = ( ( u8 ) ( *pData >> 28 ) & 0xF ) *10 + ( ( u8 ) ( *pData >> 24 ) & 0xF );
  1428. //DBG_871X("BaseValue = %d\n", BaseValue );
  1429. phy_ChangePGDataFromExactToRelativeValue( pData, 0, 3, BaseValue );
  1430. phy_ChangePGDataFromExactToRelativeValue(
  1431. &( pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][2] ),
  1432. 0, 3, BaseValue);
  1433. //DBG_871X("pHalData->MCSTxPowerLevelOriginalOffset[%d][3] = 0x%x, after changing to relative\n",
  1434. // pHalData->pwrGroupCnt, *pData );
  1435. //DBG_871X("pHalData->MCSTxPowerLevelOriginalOffset[%d][2] = 0x%x, after changing to relative\n",
  1436. // pHalData->pwrGroupCnt, pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][2] );
  1437. }
  1438. if ( RegAddr == rTxAGC_A_Mcs11_Mcs08 )
  1439. {
  1440. pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][4] = *pData;
  1441. //DBG_871X("MCSTxPowerLevelOriginalOffset[%d][4] = 0x%x\n", pHalData->pwrGroupCnt,
  1442. // pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][4]);
  1443. }
  1444. if ( RegAddr == rTxAGC_A_Mcs15_Mcs12 )
  1445. {
  1446. //DBG_871X("RegAddr %x\n", RegAddr );
  1447. //DBG_871X("pHalData->MCSTxPowerLevelOriginalOffset[%d][5] = 0x%x, before changing to relative\n",
  1448. // pHalData->pwrGroupCnt, *pData );
  1449. //DBG_871X("pHalData->MCSTxPowerLevelOriginalOffset[%d][4] = 0x%x, before changing to relative\n",
  1450. // pHalData->pwrGroupCnt, pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][4] );
  1451. BaseValue = ( ( u8 ) ( *pData >> 28 ) & 0xF ) *10 + ( ( u8 ) ( *pData >> 24 ) & 0xF );
  1452. //DBG_871X("BaseValue = %d\n", BaseValue );
  1453. phy_ChangePGDataFromExactToRelativeValue( pData, 0, 3, BaseValue );
  1454. phy_ChangePGDataFromExactToRelativeValue(
  1455. &( pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][4] ),
  1456. 0, 3, BaseValue);
  1457. //DBG_871X("pHalData->MCSTxPowerLevelOriginalOffset[%d][5] = 0x%x, after changing to relative\n",
  1458. // pHalData->pwrGroupCnt, *pData );
  1459. //DBG_871X("pHalData->MCSTxPowerLevelOriginalOffset[%d][4] = 0x%x, after changing to relative\n",
  1460. // pHalData->pwrGroupCnt, pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][4] );
  1461. }
  1462. if ( RegAddr == rTxAGC_B_Rate54_24 )
  1463. {
  1464. //DBG_871X("RegAddr %x\n", RegAddr );
  1465. //DBG_871X("pHalData->MCSTxPowerLevelOriginalOffset[%d][9] = 0x%x, before changing to relative\n",
  1466. // pHalData->pwrGroupCnt, *pData );
  1467. //DBG_871X("pHalData->MCSTxPowerLevelOriginalOffset[%d][8] = 0x%x, before changing to relative\n",
  1468. // pHalData->pwrGroupCnt, pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][8] );
  1469. BaseValue = ( ( u8 ) ( *pData >> 28 ) & 0xF ) *10 + ( ( u8 ) ( *pData >> 24 ) & 0xF );
  1470. //DBG_871X("BaseValue = %d\n", BaseValue );
  1471. phy_ChangePGDataFromExactToRelativeValue( pData, 0, 3, BaseValue );
  1472. phy_ChangePGDataFromExactToRelativeValue(
  1473. &( pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][8] ),
  1474. 0, 3, BaseValue);
  1475. //DBG_871X("pHalData->MCSTxPowerLevelOriginalOffset[%d][9] = 0x%x, after changing to relative\n",
  1476. // pHalData->pwrGroupCnt, *pData );
  1477. //DBG_871X("pHalData->MCSTxPowerLevelOriginalOffset[%d][8] = 0x%x, after changing to relative\n",
  1478. // pHalData->pwrGroupCnt, pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][8] );
  1479. }
  1480. if ( RegAddr == rTxAGC_B_CCK1_55_Mcs32 )
  1481. {
  1482. pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][14] = *pData;
  1483. //DBG_871X("MCSTxPowerLevelOriginalOffset[%d][14] = 0x%x\n", pHalData->pwrGroupCnt,
  1484. // pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][14]);
  1485. }
  1486. if ( RegAddr == rTxAGC_B_CCK11_A_CCK2_11 && BitMask == 0x000000ff )
  1487. {
  1488. pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][15] = *pData;
  1489. //DBG_871X("MCSTxPowerLevelOriginalOffset[%d][15] = 0x%x\n", pHalData->pwrGroupCnt,
  1490. // pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][15]);
  1491. }
  1492. if ( RegAddr == rTxAGC_B_Mcs07_Mcs04 )
  1493. {
  1494. //DBG_871X("RegAddr %x\n", RegAddr );
  1495. //DBG_871X("pHalData->MCSTxPowerLevelOriginalOffset[%d][11] = 0x%x, before changing to relative\n",
  1496. // pHalData->pwrGroupCnt, *pData );
  1497. //DBG_871X("pHalData->MCSTxPowerLevelOriginalOffset[%d][10] = 0x%x, before changing to relative\n",
  1498. // pHalData->pwrGroupCnt, pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][10] );
  1499. BaseValue = ( ( u8 ) ( *pData >> 28 ) & 0xF ) *10 + ( ( u8 ) ( *pData >> 24 ) & 0xF );
  1500. //DBG_871X("BaseValue = %d\n", BaseValue );
  1501. phy_ChangePGDataFromExactToRelativeValue( pData, 0, 3, BaseValue );
  1502. phy_ChangePGDataFromExactToRelativeValue(
  1503. &( pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][10] ),
  1504. 0, 3, BaseValue);
  1505. //DBG_871X("pHalData->MCSTxPowerLevelOriginalOffset[%d][11] = 0x%x, after changing to relative\n",
  1506. // pHalData->pwrGroupCnt, *pData );
  1507. //DBG_871X("pHalData->MCSTxPowerLevelOriginalOffset[%d][10] = 0x%x, after changing to relative\n",
  1508. // pHalData->pwrGroupCnt, pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][10] );
  1509. }
  1510. if ( RegAddr == rTxAGC_B_Mcs15_Mcs12 )
  1511. {
  1512. //DBG_871X("RegAddr %x\n", RegAddr );
  1513. //DBG_871X("pHalData->MCSTxPowerLevelOriginalOffset[%d][13] = 0x%x, before changing to relative\n",
  1514. // pHalData->pwrGroupCnt, *pData );
  1515. //DBG_871X("pHalData->MCSTxPowerLevelOriginalOffset[%d][12] = 0x%x, before changing to relative\n",
  1516. // pHalData->pwrGroupCnt, pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][12] );
  1517. BaseValue = ( ( u8 ) ( *pData >> 28 ) & 0xF ) *10 + ( ( u8 ) ( *pData >> 24 ) & 0xF );
  1518. //DBG_871X("BaseValue = %d\n", BaseValue );
  1519. phy_ChangePGDataFromExactToRelativeValue( pData, 0, 3, BaseValue );
  1520. phy_ChangePGDataFromExactToRelativeValue(
  1521. &( pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][12] ),
  1522. 0, 3, BaseValue);
  1523. //DBG_871X("pHalData->MCSTxPowerLevelOriginalOffset[%d][13] = 0x%x, after changing to relative\n",
  1524. // pHalData->pwrGroupCnt, *pData );
  1525. //DBG_871X("pHalData->MCSTxPowerLevelOriginalOffset[%d][12] = 0x%x, after changing to relative\n",
  1526. // pHalData->pwrGroupCnt, pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][12] );
  1527. }
  1528. //
  1529. // 1. Judge TX power by rate array band type.
  1530. //
  1531. //if(RegAddr == rTxAGC_A_CCK11_CCK1_JAguar || RegAddr == rTxAGC_B_CCK11_CCK1_JAguar)
  1532. if ( IS_HARDWARE_TYPE_8812( Adapter ) ||
  1533. IS_HARDWARE_TYPE_8821( Adapter ) )
  1534. {
  1535. phy_PreprocessVHTPGDataFromExactToRelativeValue( Adapter, RegAddr,
  1536. BitMask, pData );
  1537. }
  1538. }
  1539. VOID
  1540. phy_StorePwrByRateIndexBase(
  1541. IN PADAPTER Adapter,
  1542. IN u32 RegAddr,
  1543. IN u32 Data
  1544. )
  1545. {
  1546. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  1547. u8 Base = 0;
  1548. if( pHalData->TxPwrByRateTable == 1 && pHalData->TxPwrByRateBand == 0 ) // 2.4G
  1549. {
  1550. if ( pHalData->odmpriv.PhyRegPgValueType == PHY_REG_PG_EXACT_VALUE )
  1551. {
  1552. Base = ( ( ( u8 ) ( Data >> 28 ) & 0xF ) * 10 +
  1553. ( ( u8 ) ( Data >> 24 ) & 0xF ) );
  1554. switch( RegAddr ) {
  1555. case 0xC20:
  1556. pHalData->TxPwrByRateBase2_4G[ODM_RF_PATH_A][0] = Base;
  1557. //RT_DISP(FPHY, PHY_TXPWR, ("2.4G power by rate of CCK (RF path A) = %d\n",
  1558. // pHalData->TxPwrByRateBase2_4G[ODM_RF_PATH_A][0] ) );
  1559. break;
  1560. case 0xC28:
  1561. pHalData->TxPwrByRateBase2_4G[ODM_RF_PATH_A][1] = Base;
  1562. //RT_DISP(FPHY, PHY_TXPWR, ("2.4G power by rate of OFDM 54M (RF path A) = %d\n",
  1563. // pHalData->TxPwrByRateBase2_4G[ODM_RF_PATH_A][1] ) );
  1564. break;
  1565. case 0xC30:
  1566. pHalData->TxPwrByRateBase2_4G[ODM_RF_PATH_A][2] = Base;
  1567. //RT_DISP(FPHY, PHY_TXPWR, ("2.4G power by rate of MCS7 (RF path A) = %d\n",
  1568. // pHalData->TxPwrByRateBase2_4G[ODM_RF_PATH_A][2] ) );
  1569. break;
  1570. case 0xC38:
  1571. pHalData->TxPwrByRateBase2_4G[ODM_RF_PATH_A][3] = Base;
  1572. //RT_DISP(FPHY, PHY_TXPWR, ("2.4G power by rate of MCS15 (RF path A) = %d\n",
  1573. // pHalData->TxPwrByRateBase2_4G[ODM_RF_PATH_A][3] ) );
  1574. break;
  1575. default:
  1576. break;
  1577. };
  1578. }
  1579. else
  1580. {
  1581. Base = ( u8 ) ( Data >> 24 );
  1582. switch( RegAddr ) {
  1583. case 0xC20:
  1584. pHalData->TxPwrByRateBase2_4G[ODM_RF_PATH_A][0] = Base;
  1585. //RT_DISP(FPHY, PHY_TXPWR, ("2.4G power by rate of CCK (RF path A) = %d\n",
  1586. // pHalData->TxPwrByRateBase2_4G[ODM_RF_PATH_A][0] ) );
  1587. break;
  1588. case 0xC28:
  1589. pHalData->TxPwrByRateBase2_4G[ODM_RF_PATH_A][1] = Base;
  1590. //RT_DISP(FPHY, PHY_TXPWR, ("2.4G power by rate of OFDM 54M (RF path A) = %d\n",
  1591. // pHalData->TxPwrByRateBase2_4G[ODM_RF_PATH_A][1] ) );
  1592. break;
  1593. case 0xC30:
  1594. pHalData->TxPwrByRateBase2_4G[ODM_RF_PATH_A][2] = Base;
  1595. //RT_DISP(FPHY, PHY_TXPWR, ("2.4G power by rate of MCS7 (RF path A) = %d\n",
  1596. // pHalData->TxPwrByRateBase2_4G[ODM_RF_PATH_A][2] ) );
  1597. break;
  1598. case 0xC38:
  1599. pHalData->TxPwrByRateBase2_4G[ODM_RF_PATH_A][3] = Base;
  1600. //RT_DISP(FPHY, PHY_TXPWR, ("2.4G power by rate of MCS15 (RF path A) = %d\n",
  1601. // pHalData->TxPwrByRateBase2_4G[ODM_RF_PATH_A][3] ) );
  1602. break;
  1603. default:
  1604. break;
  1605. };
  1606. }
  1607. }
  1608. else if ( pHalData->TxPwrByRateTable == 3 && pHalData->TxPwrByRateBand == 1 ) // 5G
  1609. {
  1610. if ( pHalData->odmpriv.PhyRegPgValueType == PHY_REG_PG_EXACT_VALUE )
  1611. {
  1612. Base = ( ( ( u8 ) ( Data >> 28 ) & 0xF ) * 10 +
  1613. ( ( u8 ) ( Data >> 24 ) & 0xF ) );
  1614. switch( RegAddr )
  1615. {
  1616. case 0xC28:
  1617. pHalData->TxPwrByRateBase5G[ODM_RF_PATH_A][0] = Base;
  1618. //RT_DISP(FPHY, PHY_TXPWR, ("5G power by rate of OFDM 54M (RF path A) = %d\n",
  1619. // pHalData->TxPwrByRateBase5G[ODM_RF_PATH_A][0] ) );
  1620. break;
  1621. case 0xC30:
  1622. pHalData->TxPwrByRateBase5G[ODM_RF_PATH_A][1] = Base;
  1623. //RT_DISP(FPHY, PHY_TXPWR, ("5G power by rate of MCS7 (RF path A) = %d\n",
  1624. // pHalData->TxPwrByRateBase5G[ODM_RF_PATH_A][1] ) );
  1625. break;
  1626. case 0xC38:
  1627. pHalData->TxPwrByRateBase5G[ODM_RF_PATH_A][2] = Base;
  1628. //RT_DISP(FPHY, PHY_TXPWR, ("5G power by rate of MCS15 (RF path A) = %d\n",
  1629. // pHalData->TxPwrByRateBase5G[ODM_RF_PATH_A][2] ) );
  1630. break;
  1631. case 0xC40:
  1632. pHalData->TxPwrByRateBase5G[ODM_RF_PATH_A][3] = Base;
  1633. //RT_DISP(FPHY, PHY_TXPWR, ("5G power by rate of 1SS MCS7 (RF path A) = %d\n",
  1634. // pHalData->TxPwrByRateBase5G[ODM_RF_PATH_A][3] ) );
  1635. break;
  1636. case 0xC4C:
  1637. pHalData->TxPwrByRateBase5G[ODM_RF_PATH_A][4] =
  1638. ( u8 ) ( ( Data >> 12 ) & 0xF ) * 10 +
  1639. ( u8 ) ( ( Data >> 8 ) & 0xF );
  1640. //RT_DISP(FPHY, PHY_TXPWR, ("5G power by rate of 2SS MCS7 (RF path A) = %d\n",
  1641. // pHalData->TxPwrByRateBase5G[ODM_RF_PATH_A][4] ) );
  1642. break;
  1643. case 0xE28:
  1644. pHalData->TxPwrByRateBase5G[ODM_RF_PATH_B][0] = Base;
  1645. //RT_DISP(FPHY, PHY_TXPWR, ("5G power by rate of OFDM 54M (RF path B) = %d\n",
  1646. // pHalData->TxPwrByRateBase5G[ODM_RF_PATH_B][0] ) );
  1647. break;
  1648. case 0xE30:
  1649. pHalData->TxPwrByRateBase5G[ODM_RF_PATH_B][1] = Base;
  1650. //RT_DISP(FPHY, PHY_TXPWR, ("5G power by rate of MCS7 (RF path B) = %d\n",
  1651. // pHalData->TxPwrByRateBase5G[ODM_RF_PATH_B][1] ) );
  1652. break;
  1653. case 0xE38:
  1654. pHalData->TxPwrByRateBase5G[ODM_RF_PATH_B][2] = Base;
  1655. //RT_DISP(FPHY, PHY_TXPWR, ("5G power by rate of MCS15 (RF path B) = %d\n",
  1656. // pHalData->TxPwrByRateBase5G[ODM_RF_PATH_B][2] ) );
  1657. break;
  1658. case 0xE40:
  1659. pHalData->TxPwrByRateBase5G[ODM_RF_PATH_B][3] = Base;
  1660. //RT_DISP(FPHY, PHY_TXPWR, ("5G power by rate of 1SS MCS7 (RF path B) = %d\n",
  1661. // pHalData->TxPwrByRateBase5G[ODM_RF_PATH_B][3] ) );
  1662. break;
  1663. case 0xE4C:
  1664. pHalData->TxPwrByRateBase5G[ODM_RF_PATH_B][4] =
  1665. ( u8 ) ( ( Data >> 12 ) & 0xF ) * 10 +
  1666. ( u8 ) ( ( Data >> 8 ) & 0xF );
  1667. //RT_DISP(FPHY, PHY_TXPWR, ("5G power by rate of 2SS MCS7 (RF path B) = %d\n",
  1668. // pHalData->TxPwrByRateBase5G[ODM_RF_PATH_B][4] ) );
  1669. break;
  1670. default:
  1671. break;
  1672. };
  1673. }
  1674. else
  1675. {
  1676. Base = ( u8 ) ( Data >> 24 );
  1677. switch( RegAddr ) {
  1678. case 0xC28:
  1679. pHalData->TxPwrByRateBase5G[ODM_RF_PATH_A][0] = Base;
  1680. //RT_DISP(FPHY, PHY_TXPWR, ("5G power by rate of OFDM 54M (RF path A) = %d\n",
  1681. // pHalData->TxPwrByRateBase5G[ODM_RF_PATH_A][0] ) );
  1682. break;
  1683. case 0xC30:
  1684. pHalData->TxPwrByRateBase5G[ODM_RF_PATH_A][1] = Base;
  1685. //RT_DISP(FPHY, PHY_TXPWR, ("5G power by rate of MCS7 (RF path A) = %d\n",
  1686. // pHalData->TxPwrByRateBase5G[ODM_RF_PATH_A][1] ) );
  1687. break;
  1688. case 0xC38:
  1689. pHalData->TxPwrByRateBase5G[ODM_RF_PATH_A][2] = Base;
  1690. //RT_DISP(FPHY, PHY_TXPWR, ("5G power by rate of MCS15 (RF path A) = %d\n",
  1691. // pHalData->TxPwrByRateBase5G[ODM_RF_PATH_A][2] ) );
  1692. break;
  1693. case 0xC40:
  1694. pHalData->TxPwrByRateBase5G[ODM_RF_PATH_A][3] = Base;
  1695. //RT_DISP(FPHY, PHY_TXPWR, ("5G power by rate of 1SS MCS7 (RF path A) = %d\n",
  1696. // pHalData->TxPwrByRateBase5G[ODM_RF_PATH_A][3] ) );
  1697. break;
  1698. case 0xC4C:
  1699. pHalData->TxPwrByRateBase5G[ODM_RF_PATH_A][4] = ( u8 ) ( ( Data >> 8 ) & 0xFF );
  1700. //RT_DISP(FPHY, PHY_TXPWR, ("5G power by rate of 2SS MCS7 (RF path A) = %d\n",
  1701. // pHalData->TxPwrByRateBase5G[ODM_RF_PATH_A][4] ) );
  1702. break;
  1703. case 0xE28:
  1704. pHalData->TxPwrByRateBase5G[ODM_RF_PATH_B][0] = Base;
  1705. //RT_DISP(FPHY, PHY_TXPWR, ("5G power by rate of OFDM 54M (RF path B) = %d\n",
  1706. // pHalData->TxPwrByRateBase5G[ODM_RF_PATH_B][0] ) );
  1707. break;
  1708. case 0xE30:
  1709. pHalData->TxPwrByRateBase5G[ODM_RF_PATH_B][1] = Base;
  1710. //RT_DISP(FPHY, PHY_TXPWR, ("5G power by rate of MCS7 (RF path B) = %d\n",
  1711. // pHalData->TxPwrByRateBase5G[ODM_RF_PATH_B][1] ) );
  1712. break;
  1713. case 0xE38:
  1714. pHalData->TxPwrByRateBase5G[ODM_RF_PATH_B][2] = Base;
  1715. //RT_DISP(FPHY, PHY_TXPWR, ("5G power by rate of MCS15 (RF path B) = %d\n",
  1716. // pHalData->TxPwrByRateBase5G[ODM_RF_PATH_B][2] ) );
  1717. break;
  1718. case 0xE40:
  1719. pHalData->TxPwrByRateBase5G[ODM_RF_PATH_B][3] = Base;
  1720. //RT_DISP(FPHY, PHY_TXPWR, ("5G power by rate of 1SS MCS7 (RF path B) = %d\n",
  1721. // pHalData->TxPwrByRateBase5G[ODM_RF_PATH_B][3] ) );
  1722. break;
  1723. case 0xE4C:
  1724. pHalData->TxPwrByRateBase5G[ODM_RF_PATH_B][4] = ( u8 ) ( ( Data >> 8 ) & 0xFF );
  1725. //RT_DISP(FPHY, PHY_TXPWR, ("5G power by rate of 2SS MCS7 (RF path B) = %d\n",
  1726. // pHalData->TxPwrByRateBase5G[ODM_RF_PATH_B][4] ) );
  1727. break;
  1728. default:
  1729. break;
  1730. };
  1731. }
  1732. }
  1733. else if( pHalData->TxPwrByRateTable == 2 && pHalData->TxPwrByRateBand == 0 ) // 2.4G
  1734. {
  1735. if ( pHalData->odmpriv.PhyRegPgValueType == PHY_REG_PG_EXACT_VALUE )
  1736. {
  1737. Base = ( ( ( u8 ) ( Data >> 28 ) & 0xF ) * 10 +
  1738. ( ( u8 ) ( Data >> 24 ) & 0xF ) );
  1739. switch( RegAddr ) {
  1740. case 0xE20:
  1741. pHalData->TxPwrByRateBase2_4G[ODM_RF_PATH_B][0] = Base;
  1742. //RT_DISP(FPHY, PHY_TXPWR, ("2.4G power by rate of CCK (RF path B) = %d\n",
  1743. // pHalData->TxPwrByRateBase2_4G[ODM_RF_PATH_B][0] ) );
  1744. break;
  1745. case 0xE28:
  1746. pHalData->TxPwrByRateBase2_4G[ODM_RF_PATH_B][1] = Base;
  1747. //RT_DISP(FPHY, PHY_TXPWR, ("2.4G power by rate of OFDM 54M (RF path B) = %d\n",
  1748. // pHalData->TxPwrByRateBase2_4G[ODM_RF_PATH_B][1] ) );
  1749. break;
  1750. case 0xE30:
  1751. pHalData->TxPwrByRateBase2_4G[ODM_RF_PATH_B][2] = Base;
  1752. //RT_DISP(FPHY, PHY_TXPWR, ("2.4G power by rate of MCS7 (RF path B) = %d\n",
  1753. // pHalData->TxPwrByRateBase2_4G[ODM_RF_PATH_B][2] ) );
  1754. break;
  1755. case 0xE38:
  1756. pHalData->TxPwrByRateBase2_4G[ODM_RF_PATH_B][3] = Base;
  1757. //RT_DISP(FPHY, PHY_TXPWR, ("2.4G power by rate of MCS15 (RF path B) = %d\n",
  1758. // pHalData->TxPwrByRateBase2_4G[ODM_RF_PATH_B][3] ) );
  1759. break;
  1760. default:
  1761. break;
  1762. };
  1763. }
  1764. else
  1765. {
  1766. Base = ( u8 ) ( Data >> 24 );
  1767. switch( RegAddr ) {
  1768. case 0xC20:
  1769. pHalData->TxPwrByRateBase2_4G[ODM_RF_PATH_B][0] = Base;
  1770. //RT_DISP(FPHY, PHY_TXPWR, ("2.4G power by rate of CCK (RF path B) = %d\n",
  1771. // pHalData->TxPwrByRateBase2_4G[ODM_RF_PATH_B][0] ) );
  1772. break;
  1773. case 0xC28:
  1774. pHalData->TxPwrByRateBase2_4G[ODM_RF_PATH_B][1] = Base;
  1775. //RT_DISP(FPHY, PHY_TXPWR, ("2.4G power by rate of OFDM 54M (RF path B) = %d\n",
  1776. // pHalData->TxPwrByRateBase2_4G[ODM_RF_PATH_B][1] ) );
  1777. break;
  1778. case 0xC30:
  1779. pHalData->TxPwrByRateBase2_4G[ODM_RF_PATH_B][2] = Base;
  1780. //RT_DISP(FPHY, PHY_TXPWR, ("2.4G power by rate of MCS7 (RF path B) = %d\n",
  1781. // pHalData->TxPwrByRateBase2_4G[ODM_RF_PATH_B][2] ) );
  1782. break;
  1783. case 0xC38:
  1784. pHalData->TxPwrByRateBase2_4G[ODM_RF_PATH_B][3] = Base;
  1785. //RT_DISP(FPHY, PHY_TXPWR, ("2.4G power by rate of MCS15 (RF path B) = %d\n",
  1786. // pHalData->TxPwrByRateBase2_4G[ODM_RF_PATH_B][3] ) );
  1787. break;
  1788. default:
  1789. break;
  1790. };
  1791. }
  1792. }
  1793. //-------------- following code is for 88E ----------------//
  1794. if ( pHalData->odmpriv.PhyRegPgValueType == PHY_REG_PG_EXACT_VALUE )
  1795. {
  1796. Base = ( u8 ) ( ( Data >> 28 ) & 0xF ) * 10 +
  1797. ( u8 ) ( ( Data >> 24 ) & 0xF );
  1798. }
  1799. else
  1800. {
  1801. Base = ( u8 ) ( ( Data >> 24 ) & 0xFF );
  1802. }
  1803. switch ( RegAddr )
  1804. {
  1805. case rTxAGC_A_Rate54_24:
  1806. pHalData->TxPwrByRateBase2_4G[ODM_RF_PATH_A][1] = Base;
  1807. pHalData->TxPwrByRateBase2_4G[ODM_RF_PATH_B][1] = Base;
  1808. //RT_DISP(FPHY, PHY_TXPWR, ("2.4G power by rate of OFDM 54M (RF path A) = %d\n", pHalData->TxPwrByRateBase2_4G[ODM_RF_PATH_A][1]));
  1809. break;
  1810. case rTxAGC_A_Mcs07_Mcs04:
  1811. pHalData->TxPwrByRateBase2_4G[ODM_RF_PATH_A][2] = Base;
  1812. pHalData->TxPwrByRateBase2_4G[ODM_RF_PATH_B][2] = Base;
  1813. //RT_DISP(FPHY, PHY_TXPWR, ("2.4G power by rate of MCS7 (RF path A) = %d\n", pHalData->TxPwrByRateBase2_4G[ODM_RF_PATH_A][2]));
  1814. break;
  1815. case rTxAGC_A_Mcs15_Mcs12:
  1816. pHalData->TxPwrByRateBase2_4G[ODM_RF_PATH_A][3] = Base;
  1817. pHalData->TxPwrByRateBase2_4G[ODM_RF_PATH_B][3] = Base;
  1818. //RT_DISP(FPHY, PHY_TXPWR, ("2.4G power by rate of MCS15 (RF path A) = %d\n", pHalData->TxPwrByRateBase2_4G[ODM_RF_PATH_A][3]));
  1819. break;
  1820. default:
  1821. break;
  1822. };
  1823. }
  1824. VOID
  1825. storePwrIndexDiffRateOffset(
  1826. IN PADAPTER Adapter,
  1827. IN u32 RegAddr,
  1828. IN u32 BitMask,
  1829. IN u32 Data
  1830. )
  1831. {
  1832. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  1833. u32 tmpData = Data;
  1834. // If the pHalData->DM_OutSrc.PhyRegPgValueType == 1, which means that the data in PHY_REG_PG data are
  1835. // exact value, we must change them into relative values
  1836. if ( pHalData->odmpriv.PhyRegPgValueType == PHY_REG_PG_EXACT_VALUE )
  1837. {
  1838. //DBG_871X("PhyRegPgValueType = PHY_REG_PG_EXACT_VALUE\n");
  1839. phy_PreprocessPGDataFromExactToRelativeValue( Adapter, RegAddr, BitMask, &Data );
  1840. //DBG_871X("Data = 0x%x, tmpData = 0x%x\n", Data, tmpData );
  1841. }
  1842. //
  1843. // 2012/09/26 MH Add for VHT series. The power by rate table is diffeent as before.
  1844. // 2012/10/24 MH Add description for the old tx power by rate method is only used
  1845. // for 11 n series. T
  1846. //
  1847. if (IS_HARDWARE_TYPE_8812(Adapter) ||
  1848. IS_HARDWARE_TYPE_8821(Adapter))
  1849. {
  1850. PHY_StorePwrByRateIndexVhtSeries(Adapter, RegAddr, BitMask, Data);
  1851. }
  1852. // Awk add to stroe the base power by rate value
  1853. phy_StorePwrByRateIndexBase(Adapter, RegAddr, tmpData );
  1854. if(RegAddr == rTxAGC_A_Rate18_06)
  1855. {
  1856. pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][0] = Data;
  1857. //RT_TRACE(COMP_INIT, DBG_TRACE, ("MCSTxPowerLevelOriginalOffset[%d][0] = 0x%lx\n", pHalData->pwrGroupCnt,
  1858. // pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][0]));
  1859. }
  1860. if(RegAddr == rTxAGC_A_Rate54_24)
  1861. {
  1862. pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][1] = Data;
  1863. //RT_TRACE(COMP_INIT, DBG_TRACE, ("MCSTxPowerLevelOriginalOffset[%d][1] = 0x%lx\n", pHalData->pwrGroupCnt,
  1864. // pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][1]));
  1865. }
  1866. if(RegAddr == rTxAGC_A_CCK1_Mcs32)
  1867. {
  1868. pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][6] = Data;
  1869. //RT_TRACE(COMP_INIT, DBG_TRACE, ("MCSTxPowerLevelOriginalOffset[%d][6] = 0x%lx\n", pHalData->pwrGroupCnt,
  1870. // pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][6]));
  1871. }
  1872. if(RegAddr == rTxAGC_B_CCK11_A_CCK2_11 && BitMask == 0xffffff00)
  1873. {
  1874. pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][7] = Data;
  1875. //RT_TRACE(COMP_INIT, DBG_TRACE, ("MCSTxPowerLevelOriginalOffset[%d][7] = 0x%lx\n", pHalData->pwrGroupCnt,
  1876. // pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][7]));
  1877. }
  1878. if(RegAddr == rTxAGC_A_Mcs03_Mcs00)
  1879. {
  1880. pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][2] = Data;
  1881. //RT_TRACE(COMP_INIT, DBG_TRACE, ("MCSTxPowerLevelOriginalOffset[%d][2] = 0x%lx\n", pHalData->pwrGroupCnt,
  1882. // pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][2]));
  1883. }
  1884. if(RegAddr == rTxAGC_A_Mcs07_Mcs04)
  1885. {
  1886. pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][3] = Data;
  1887. //RT_TRACE(COMP_INIT, DBG_TRACE, ("MCSTxPowerLevelOriginalOffset[%d][3] = 0x%lx\n", pHalData->pwrGroupCnt,
  1888. // pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][3]));
  1889. }
  1890. if(RegAddr == rTxAGC_A_Mcs11_Mcs08)
  1891. {
  1892. pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][4] = Data;
  1893. //RT_TRACE(COMP_INIT, DBG_TRACE, ("MCSTxPowerLevelOriginalOffset[%d][4] = 0x%lx\n", pHalData->pwrGroupCnt,
  1894. // pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][4]));
  1895. }
  1896. if(RegAddr == rTxAGC_A_Mcs15_Mcs12)
  1897. {
  1898. pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][5] = Data;
  1899. //RT_TRACE(COMP_INIT, DBG_TRACE, ("MCSTxPowerLevelOriginalOffset[%d][5] = 0x%lx\n", pHalData->pwrGroupCnt,
  1900. // pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][5]));
  1901. if(pHalData->rf_type== RF_1T1R)
  1902. {
  1903. pHalData->pwrGroupCnt++;
  1904. //RT_TRACE(COMP_INIT, DBG_TRACE, ("pwrGroupCnt = %d\n", pHalData->pwrGroupCnt));
  1905. }
  1906. }
  1907. if(RegAddr == rTxAGC_B_Rate18_06)
  1908. {
  1909. pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][8] = Data;
  1910. //RT_TRACE(COMP_INIT, DBG_TRACE, ("MCSTxPowerLevelOriginalOffset[%d][8] = 0x%lx\n", pHalData->pwrGroupCnt,
  1911. // pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][8]));
  1912. }
  1913. if(RegAddr == rTxAGC_B_Rate54_24)
  1914. {
  1915. pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][9] = Data;
  1916. //RT_TRACE(COMP_INIT, DBG_TRACE, ("MCSTxPowerLevelOriginalOffset[%d][9] = 0x%lx\n", pHalData->pwrGroupCnt,
  1917. // pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][9]));
  1918. }
  1919. if(RegAddr == rTxAGC_B_CCK1_55_Mcs32)
  1920. {
  1921. pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][14] = Data;
  1922. //RT_TRACE(COMP_INIT, DBG_TRACE, ("MCSTxPowerLevelOriginalOffset[%d][14] = 0x%lx\n", pHalData->pwrGroupCnt,
  1923. // pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][14]));
  1924. }
  1925. if(RegAddr == rTxAGC_B_CCK11_A_CCK2_11 && BitMask == 0x000000ff)
  1926. {
  1927. pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][15] = Data;
  1928. //RT_TRACE(COMP_INIT, DBG_TRACE, ("MCSTxPowerLevelOriginalOffset[%d][15] = 0x%lx\n", pHalData->pwrGroupCnt,
  1929. // pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][15]));
  1930. }
  1931. if(RegAddr == rTxAGC_B_Mcs03_Mcs00)
  1932. {
  1933. pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][10] = Data;
  1934. //RT_TRACE(COMP_INIT, DBG_TRACE, ("MCSTxPowerLevelOriginalOffset[%d][10] = 0x%lx\n", pHalData->pwrGroupCnt,
  1935. // pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][10]));
  1936. }
  1937. if(RegAddr == rTxAGC_B_Mcs07_Mcs04)
  1938. {
  1939. pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][11] = Data;
  1940. //RT_TRACE(COMP_INIT, DBG_TRACE, ("MCSTxPowerLevelOriginalOffset[%d][11] = 0x%lx\n", pHalData->pwrGroupCnt,
  1941. // pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][11]));
  1942. }
  1943. if(RegAddr == rTxAGC_B_Mcs11_Mcs08)
  1944. {
  1945. pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][12] = Data;
  1946. //RT_TRACE(COMP_INIT, DBG_TRACE, ("MCSTxPowerLevelOriginalOffset[%d][12] = 0x%lx\n", pHalData->pwrGroupCnt,
  1947. // pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][12]));
  1948. }
  1949. if(RegAddr == rTxAGC_B_Mcs15_Mcs12)
  1950. {
  1951. pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][13] = Data;
  1952. //RT_TRACE(COMP_INIT, DBG_TRACE, ("MCSTxPowerLevelOriginalOffset[%d][13] = 0x%lx\n", pHalData->pwrGroupCnt,
  1953. // pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][13]));
  1954. if(pHalData->rf_type != RF_1T1R)
  1955. pHalData->pwrGroupCnt++;
  1956. }
  1957. }
  1958. static u8
  1959. phy_DbmToTxPwrIdx(
  1960. IN PADAPTER Adapter,
  1961. IN WIRELESS_MODE WirelessMode,
  1962. IN int PowerInDbm
  1963. )
  1964. {
  1965. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  1966. u8 TxPwrIdx = 0;
  1967. s32 Offset = 0;
  1968. #if 0
  1969. //
  1970. // Tested by MP, we found that CCK Index 0 equals to 8dbm, OFDM legacy equals to
  1971. // 3dbm, and OFDM HT equals to 0dbm repectively.
  1972. // Note:
  1973. // The mapping may be different by different NICs. Do not use this formula for what needs accurate result.
  1974. // By Bruce, 2008-01-29.
  1975. //
  1976. switch(WirelessMode)
  1977. {
  1978. case WIRELESS_MODE_B:
  1979. //Offset = -7;
  1980. Offset = -6; // For 88 RU test only
  1981. TxPwrIdx = (u8)((pHalData->OriginalCckTxPwrIdx*( PowerInDbm-pHalData->MinCCKDbm))/(pHalData->MaxCCKDbm-pHalData->MinCCKDbm));
  1982. break;
  1983. case WIRELESS_MODE_G:
  1984. case WIRELESS_MODE_N_24G:
  1985. Offset = -8;
  1986. TxPwrIdx = (u8)((pHalData->OriginalOfdm24GTxPwrIdx* (PowerInDbm-pHalData->MinHOFDMDbm))/(pHalData->MaxHOFDMDbm-pHalData->MinHOFDMDbm));
  1987. break;
  1988. default: //for MacOSX compiler warning
  1989. break;
  1990. }
  1991. if (PowerInDbm <= pHalData->MinCCKDbm ||
  1992. PowerInDbm <= pHalData->MinLOFDMDbm ||
  1993. PowerInDbm <= pHalData->MinHOFDMDbm)
  1994. {
  1995. TxPwrIdx = 0;
  1996. }
  1997. // Simple judge to prevent tx power exceed the limitation.
  1998. if (PowerInDbm >= pHalData->MaxCCKDbm ||
  1999. PowerInDbm >= pHalData->MaxLOFDMDbm ||
  2000. PowerInDbm >= pHalData->MaxHOFDMDbm)
  2001. {
  2002. if (WirelessMode == WIRELESS_MODE_B)
  2003. TxPwrIdx = pHalData->OriginalCckTxPwrIdx;
  2004. else
  2005. TxPwrIdx = pHalData->OriginalOfdm24GTxPwrIdx;
  2006. }
  2007. #endif
  2008. return TxPwrIdx;
  2009. }
  2010. static int
  2011. phy_TxPwrIdxToDbm(
  2012. IN PADAPTER Adapter,
  2013. IN WIRELESS_MODE WirelessMode,
  2014. IN u8 TxPwrIdx
  2015. )
  2016. {
  2017. int Offset = 0;
  2018. int PwrOutDbm = 0;
  2019. //
  2020. // Tested by MP, we found that CCK Index 0 equals to -7dbm, OFDM legacy equals to -8dbm.
  2021. // Note:
  2022. // The mapping may be different by different NICs. Do not use this formula for what needs accurate result.
  2023. // By Bruce, 2008-01-29.
  2024. //
  2025. switch(WirelessMode)
  2026. {
  2027. case WIRELESS_MODE_B:
  2028. Offset = -7;
  2029. break;
  2030. case WIRELESS_MODE_G:
  2031. case WIRELESS_MODE_N_24G:
  2032. Offset = -8;
  2033. break;
  2034. default: //for MacOSX compiler warning
  2035. break;
  2036. }
  2037. PwrOutDbm = TxPwrIdx / 2 + Offset; // Discard the decimal part.
  2038. return PwrOutDbm;
  2039. }
  2040. VOID
  2041. PHY_GetTxPowerLevel8812(
  2042. IN PADAPTER Adapter,
  2043. OUT u32* powerlevel
  2044. )
  2045. {
  2046. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  2047. u8 TxPwrLevel = 0;
  2048. int TxPwrDbm;
  2049. #if 0
  2050. //
  2051. // Because the Tx power indexes are different, we report the maximum of them to
  2052. // meet the CCX TPC request. By Bruce, 2008-01-31.
  2053. //
  2054. // CCK
  2055. TxPwrLevel = pHalData->CurrentCckTxPwrIdx;
  2056. TxPwrDbm = phy_TxPwrIdxToDbm(Adapter, WIRELESS_MODE_B, TxPwrLevel);
  2057. pHalData->MaxCCKDbm = TxPwrDbm;
  2058. // Legacy OFDM
  2059. TxPwrLevel = pHalData->CurrentOfdm24GTxPwrIdx + pHalData->LegacyHTTxPowerDiff;
  2060. // Compare with Legacy OFDM Tx power.
  2061. pHalData->MaxLOFDMDbm = phy_TxPwrIdxToDbm(Adapter, WIRELESS_MODE_G, TxPwrLevel);
  2062. if(phy_TxPwrIdxToDbm(Adapter, WIRELESS_MODE_G, TxPwrLevel) > TxPwrDbm)
  2063. TxPwrDbm = phy_TxPwrIdxToDbm(Adapter, WIRELESS_MODE_G, TxPwrLevel);
  2064. // HT OFDM
  2065. TxPwrLevel = pHalData->CurrentOfdm24GTxPwrIdx;
  2066. // Compare with HT OFDM Tx power.
  2067. pHalData->MaxHOFDMDbm = phy_TxPwrIdxToDbm(Adapter, WIRELESS_MODE_G, TxPwrLevel);
  2068. if(phy_TxPwrIdxToDbm(Adapter, WIRELESS_MODE_N_24G, TxPwrLevel) > TxPwrDbm)
  2069. TxPwrDbm = phy_TxPwrIdxToDbm(Adapter, WIRELESS_MODE_N_24G, TxPwrLevel);
  2070. pHalData->MaxHOFDMDbm = TxPwrDbm;
  2071. *powerlevel = TxPwrDbm;
  2072. #endif
  2073. }
  2074. void phy_PowerIndexCheck8812(
  2075. IN PADAPTER Adapter,
  2076. IN u8 channel,
  2077. IN OUT u8 * cckPowerLevel,
  2078. IN OUT u8 * ofdmPowerLevel,
  2079. IN OUT u8 * BW20PowerLevel,
  2080. IN OUT u8 * BW40PowerLevel
  2081. )
  2082. {
  2083. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  2084. #if 0//(CCX_SUPPORT == 1)
  2085. PMGNT_INFO pMgntInfo = &(Adapter->MgntInfo);
  2086. PRT_CCX_INFO pCcxInfo = GET_CCX_INFO(pMgntInfo);
  2087. //
  2088. // CCX 2 S31, AP control of client transmit power:
  2089. // 1. We shall not exceed Cell Power Limit as possible as we can.
  2090. // 2. Tolerance is +/- 5dB.
  2091. // 3. 802.11h Power Contraint takes higher precedence over CCX Cell Power Limit.
  2092. //
  2093. // TODO:
  2094. // 1. 802.11h power contraint
  2095. //
  2096. // 071011, by rcnjko.
  2097. //
  2098. if( pMgntInfo->OpMode == RT_OP_MODE_INFRASTRUCTURE &&
  2099. pMgntInfo->mAssoc &&
  2100. pCcxInfo->bUpdateCcxPwr &&
  2101. pCcxInfo->bWithCcxCellPwr &&
  2102. channel == pMgntInfo->dot11CurrentChannelNumber)
  2103. {
  2104. u1Byte CckCellPwrIdx = phy_DbmToTxPwrIdx(Adapter, WIRELESS_MODE_B, pCcxInfo->CcxCellPwr);
  2105. u1Byte LegacyOfdmCellPwrIdx = phy_DbmToTxPwrIdx(Adapter, WIRELESS_MODE_G, pCcxInfo->CcxCellPwr);
  2106. u1Byte OfdmCellPwrIdx = phy_DbmToTxPwrIdx(Adapter, WIRELESS_MODE_N_24G, pCcxInfo->CcxCellPwr);
  2107. RT_TRACE(COMP_TXAGC, DBG_LOUD,
  2108. ("CCX Cell Limit: %d dbm => CCK Tx power index : %d, Legacy OFDM Tx power index : %d, OFDM Tx power index: %d\n",
  2109. pCcxInfo->CcxCellPwr, CckCellPwrIdx, LegacyOfdmCellPwrIdx, OfdmCellPwrIdx));
  2110. RT_TRACE(COMP_TXAGC, DBG_LOUD,
  2111. ("EEPROM channel(%d) => CCK Tx power index: %d, Legacy OFDM Tx power index : %d, OFDM Tx power index: %d\n",
  2112. channel, cckPowerLevel[0], ofdmPowerLevel[0] + pHalData->LegacyHTTxPowerDiff, ofdmPowerLevel[0]));
  2113. // CCK
  2114. if(cckPowerLevel[0] > CckCellPwrIdx)
  2115. cckPowerLevel[0] = CckCellPwrIdx;
  2116. // Legacy OFDM, HT OFDM
  2117. if(ofdmPowerLevel[0] + pHalData->LegacyHTTxPowerDiff > LegacyOfdmCellPwrIdx)
  2118. {
  2119. if((OfdmCellPwrIdx - pHalData->LegacyHTTxPowerDiff) > 0)
  2120. {
  2121. ofdmPowerLevel[0] = OfdmCellPwrIdx - pHalData->LegacyHTTxPowerDiff;
  2122. }
  2123. else
  2124. {
  2125. ofdmPowerLevel[0] = 0;
  2126. }
  2127. }
  2128. RT_TRACE(COMP_TXAGC, DBG_LOUD,
  2129. ("Altered CCK Tx power index : %d, Legacy OFDM Tx power index: %d, OFDM Tx power index: %d\n",
  2130. cckPowerLevel[0], ofdmPowerLevel[0] + pHalData->LegacyHTTxPowerDiff, ofdmPowerLevel[0]));
  2131. }
  2132. #else
  2133. // Add or not ???
  2134. #endif
  2135. pHalData->CurrentCckTxPwrIdx = cckPowerLevel[0];
  2136. pHalData->CurrentOfdm24GTxPwrIdx = ofdmPowerLevel[0];
  2137. pHalData->CurrentBW2024GTxPwrIdx = BW20PowerLevel[0];
  2138. pHalData->CurrentBW4024GTxPwrIdx = BW40PowerLevel[0];
  2139. //RT_TRACE(COMP_TXAGC, DBG_LOUD,
  2140. // ("phy_PowerIndexCheck8812(): CurrentCckTxPwrIdx : 0x%x,CurrentOfdm24GTxPwrIdx: 0x%x, CurrentBW2024GTxPwrIdx: 0x%dx, CurrentBW4024GTxPwrIdx: 0x%x \n",
  2141. // pHalData->CurrentCckTxPwrIdx, pHalData->CurrentOfdm24GTxPwrIdx, pHalData->CurrentBW2024GTxPwrIdx, pHalData->CurrentBW4024GTxPwrIdx));
  2142. }
  2143. BOOLEAN
  2144. phy_GetChnlIndex8812A(
  2145. IN u8 Channel,
  2146. OUT u8* ChannelIdx
  2147. )
  2148. {
  2149. u8 channel5G[CHANNEL_MAX_NUMBER_5G] =
  2150. {36,38,40,42,44,46,48,50,52,54,56,58,60,62,64,100,102,104,106,108,110,112,
  2151. 114,116,118,120,122,124,126,128,130,132,134,136,138,140,142,144,149,151,
  2152. 153,155,157,159,161,163,165,167,168,169,171,173,175,177};
  2153. u8 i = 0;
  2154. BOOLEAN bIn24G=_TRUE;
  2155. if(Channel <= 14)
  2156. {
  2157. bIn24G=_TRUE;
  2158. *ChannelIdx = Channel -1;
  2159. }
  2160. else
  2161. {
  2162. bIn24G = _FALSE;
  2163. for (i = 0; i < sizeof(channel5G)/sizeof(u8); ++i)
  2164. {
  2165. if ( channel5G[i] == Channel) {
  2166. *ChannelIdx = i;
  2167. return bIn24G;
  2168. }
  2169. }
  2170. }
  2171. return bIn24G;
  2172. }
  2173. //
  2174. // For VHT series, we will use a new TX pwr by rate array to meet new spec.
  2175. //
  2176. u32
  2177. phy_GetTxPwrByRateOffset_8812(
  2178. IN PADAPTER pAdapter,
  2179. IN u8 Band,
  2180. IN u8 Rf_Path,
  2181. IN u8 Rate_Section
  2182. )
  2183. {
  2184. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(pAdapter);
  2185. u8 shift = 0, original_rate = Rate_Section;
  2186. u32 tx_pwr_diff = 0;
  2187. //
  2188. // For VHT series TX power by rate table.
  2189. // VHT TX power by rate off setArray =
  2190. // Band:-2G&5G = 0 / 1
  2191. // RF: at most 4*4 = ABCD=0/1/2/3
  2192. // CCK=0 11/5.5/2/1
  2193. // OFDM=1/2 18/12/9/6 54/48/36/24
  2194. // HT=3/4/5/6 MCS0-3 MCS4-7 MCS8-11 MCS12-15
  2195. // VHT=7/8/9/10/11 1SSMCS0-3 1SSMCS4-7 2SSMCS1/0/1SSMCS/9/8 2SSMCS2-5
  2196. //
  2197. // #define TX_PWR_BY_RATE_NUM_BAND 2
  2198. // #define TX_PWR_BY_RATE_NUM_RF 4
  2199. // #define TX_PWR_BY_RATE_NUM_SECTION 12
  2200. //
  2201. switch (Rate_Section)
  2202. {
  2203. case MGN_1M:
  2204. case MGN_2M:
  2205. case MGN_5_5M:
  2206. case MGN_11M:
  2207. Rate_Section =0;
  2208. break;
  2209. case MGN_6M:
  2210. case MGN_9M:
  2211. case MGN_12M:
  2212. case MGN_18M:
  2213. Rate_Section =1;
  2214. break;
  2215. case MGN_24M:
  2216. case MGN_36M:
  2217. case MGN_48M:
  2218. case MGN_54M:
  2219. Rate_Section =2;
  2220. break;
  2221. case MGN_MCS0:
  2222. case MGN_MCS1:
  2223. case MGN_MCS2:
  2224. case MGN_MCS3:
  2225. Rate_Section =3;
  2226. break;
  2227. case MGN_MCS4:
  2228. case MGN_MCS5:
  2229. case MGN_MCS6:
  2230. case MGN_MCS7:
  2231. Rate_Section =4;
  2232. break;
  2233. case MGN_MCS8:
  2234. case MGN_MCS9:
  2235. case MGN_MCS10:
  2236. case MGN_MCS11:
  2237. Rate_Section =5;
  2238. break;
  2239. case MGN_MCS12:
  2240. case MGN_MCS13:
  2241. case MGN_MCS14:
  2242. case MGN_MCS15:
  2243. Rate_Section =6;
  2244. break;
  2245. case MGN_VHT1SS_MCS0:
  2246. case MGN_VHT1SS_MCS1:
  2247. case MGN_VHT1SS_MCS2:
  2248. case MGN_VHT1SS_MCS3:
  2249. Rate_Section =7;
  2250. break;
  2251. case MGN_VHT1SS_MCS4:
  2252. case MGN_VHT1SS_MCS5:
  2253. case MGN_VHT1SS_MCS6:
  2254. case MGN_VHT1SS_MCS7:
  2255. Rate_Section =8;
  2256. break;
  2257. case MGN_VHT1SS_MCS8:
  2258. case MGN_VHT1SS_MCS9:
  2259. case MGN_VHT2SS_MCS0:
  2260. case MGN_VHT2SS_MCS1:
  2261. Rate_Section =9;
  2262. break;
  2263. case MGN_VHT2SS_MCS2:
  2264. case MGN_VHT2SS_MCS3:
  2265. case MGN_VHT2SS_MCS4:
  2266. case MGN_VHT2SS_MCS5:
  2267. Rate_Section =10;
  2268. break;
  2269. case MGN_VHT2SS_MCS6:
  2270. case MGN_VHT2SS_MCS7:
  2271. case MGN_VHT2SS_MCS8:
  2272. case MGN_VHT2SS_MCS9:
  2273. Rate_Section =11;
  2274. break;
  2275. default:
  2276. DBG_871X("Rate_Section is Illegal\n");
  2277. break;
  2278. }
  2279. switch (original_rate)
  2280. {
  2281. case MGN_1M: shift = 0; break;
  2282. case MGN_2M: shift = 8; break;
  2283. case MGN_5_5M: shift = 16; break;
  2284. case MGN_11M: shift = 24; break;
  2285. case MGN_6M: shift = 0; break;
  2286. case MGN_9M: shift = 8; break;
  2287. case MGN_12M: shift = 16; break;
  2288. case MGN_18M: shift = 24; break;
  2289. case MGN_24M: shift = 0; break;
  2290. case MGN_36M: shift = 8; break;
  2291. case MGN_48M: shift = 16; break;
  2292. case MGN_54M: shift = 24; break;
  2293. case MGN_MCS0: shift = 0; break;
  2294. case MGN_MCS1: shift = 8; break;
  2295. case MGN_MCS2: shift = 16; break;
  2296. case MGN_MCS3: shift = 24; break;
  2297. case MGN_MCS4: shift = 0; break;
  2298. case MGN_MCS5: shift = 8; break;
  2299. case MGN_MCS6: shift = 16; break;
  2300. case MGN_MCS7: shift = 24; break;
  2301. case MGN_MCS8: shift = 0; break;
  2302. case MGN_MCS9: shift = 8; break;
  2303. case MGN_MCS10: shift = 16; break;
  2304. case MGN_MCS11: shift = 24; break;
  2305. case MGN_MCS12: shift = 0; break;
  2306. case MGN_MCS13: shift = 8; break;
  2307. case MGN_MCS14: shift = 16; break;
  2308. case MGN_MCS15: shift = 24; break;
  2309. case MGN_VHT1SS_MCS0: shift = 0; break;
  2310. case MGN_VHT1SS_MCS1: shift = 8; break;
  2311. case MGN_VHT1SS_MCS2: shift = 16; break;
  2312. case MGN_VHT1SS_MCS3: shift = 24; break;
  2313. case MGN_VHT1SS_MCS4: shift = 0; break;
  2314. case MGN_VHT1SS_MCS5: shift = 8; break;
  2315. case MGN_VHT1SS_MCS6: shift = 16; break;
  2316. case MGN_VHT1SS_MCS7: shift = 24; break;
  2317. case MGN_VHT1SS_MCS8: shift = 0; break;
  2318. case MGN_VHT1SS_MCS9: shift = 8; break;
  2319. case MGN_VHT2SS_MCS0: shift = 16; break;
  2320. case MGN_VHT2SS_MCS1: shift = 24; break;
  2321. case MGN_VHT2SS_MCS2: shift = 0; break;
  2322. case MGN_VHT2SS_MCS3: shift = 8; break;
  2323. case MGN_VHT2SS_MCS4: shift = 16; break;
  2324. case MGN_VHT2SS_MCS5: shift = 24; break;
  2325. case MGN_VHT2SS_MCS6: shift = 0; break;
  2326. case MGN_VHT2SS_MCS7: shift = 8; break;
  2327. case MGN_VHT2SS_MCS8: shift = 16; break;
  2328. case MGN_VHT2SS_MCS9: shift = 24; break;
  2329. default:
  2330. DBG_871X("Rate_Section is Illegal\n");
  2331. break;
  2332. }
  2333. // Willis suggest to adopt 5G VHT power by rate for 2.4G
  2334. if ( Band == BAND_ON_2_4G && ( Rate_Section >= 7 && Rate_Section <= 11 ) )
  2335. Band = BAND_ON_5G;
  2336. tx_pwr_diff = (pHalData->TxPwrByRateOffset[Band][Rf_Path][Rate_Section] >> shift) & 0xff;
  2337. //DBG_871X("TxPwrByRateOffset-BAND(%d)-RF(%d)-RAS(%d)=%x tx_pwr_diff=%d shift=%d\n",
  2338. //Band, Rf_Path, Rate_Section, pHalData->TxPwrByRateOffset[Band][Rf_Path][Rate_Section], tx_pwr_diff, shift);
  2339. return tx_pwr_diff;
  2340. } // phy_GetTxPwrByRateOffset_8812
  2341. //
  2342. // Description:
  2343. // Subtract number of TxPwr index from different advance settings.
  2344. //
  2345. // 2010.03.09, added by Roger.
  2346. //
  2347. VOID
  2348. phy_TxPwrAdjInPercentage(
  2349. IN PADAPTER Adapter,
  2350. OUT u8* pTxPwrIdx)
  2351. {
  2352. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  2353. u8 TxPwrInPercentage = 0;
  2354. // Retrieve default TxPwr index settings from registry.
  2355. TxPwrInPercentage = pHalData->TxPwrInPercentage;
  2356. if(*pTxPwrIdx > RF6052_MAX_TX_PWR)
  2357. *pTxPwrIdx = RF6052_MAX_TX_PWR;
  2358. //
  2359. // <Roger_Notes> NEC Spec: dB = 10*log(X/Y), X: target value, Y: default value.
  2360. // For example: TxPower 50%, 10*log(50/100)=(nearly)-3dB
  2361. // 2010.07.26.
  2362. //
  2363. if(TxPwrInPercentage & TX_PWR_PERCENTAGE_0)// 12.5% , -9dB
  2364. {
  2365. *pTxPwrIdx -=18;
  2366. }
  2367. else if(TxPwrInPercentage & TX_PWR_PERCENTAGE_1)// 25%, -6dB
  2368. {
  2369. *pTxPwrIdx -=12;
  2370. }
  2371. else if(TxPwrInPercentage & TX_PWR_PERCENTAGE_2)// 50%, -3dB
  2372. {
  2373. *pTxPwrIdx -=6;
  2374. }
  2375. if(*pTxPwrIdx > RF6052_MAX_TX_PWR) // Avoid underflow condition.
  2376. *pTxPwrIdx = RF6052_MAX_TX_PWR;
  2377. }
  2378. /**************************************************************************************************************
  2379. * Description:
  2380. * The low-level interface to get the FINAL Tx Power Index , called by both MP and Normal Driver.
  2381. *
  2382. * <20120830, Kordan>
  2383. **************************************************************************************************************/
  2384. u32
  2385. PHY_GetTxPowerIndex_8812A(
  2386. IN PADAPTER pAdapter,
  2387. IN u8 RFPath,
  2388. IN u8 Rate,
  2389. IN CHANNEL_WIDTH BandWidth,
  2390. IN u8 Channel
  2391. )
  2392. {
  2393. PHAL_DATA_TYPE pHalData = GET_HAL_DATA(pAdapter);
  2394. PDM_ODM_T pDM_Odm = &pHalData->odmpriv;
  2395. u8 i = 0; //default set to 1S
  2396. struct registry_priv *pregistrypriv = &pAdapter->registrypriv;
  2397. u32 powerDiffByRate = 0;
  2398. u32 txPower = 0;
  2399. u8 chnlIdx = (Channel-1);
  2400. BOOLEAN bIn24G = _FALSE;
  2401. //DBG_871X("===> PHY_GetTxPowerIndex_8812A\n");
  2402. if (HAL_IsLegalChannel(pAdapter, Channel) == _FALSE)
  2403. {
  2404. chnlIdx = 0;
  2405. DBG_871X("Illegal channel!!\n");
  2406. }
  2407. bIn24G = phy_GetChnlIndex8812A(Channel, &chnlIdx);
  2408. //DBG_871X("[%s] Channel Index: %d\n", (bIn24G?"2.4G":"5G"), chnlIdx);
  2409. if (bIn24G) //3 ============================== 2.4 G ==============================
  2410. {
  2411. if ( IS_CCK_RATE(Rate) )
  2412. {
  2413. txPower = pHalData->Index24G_CCK_Base[RFPath][chnlIdx];
  2414. }
  2415. else if ( MGN_6M <= Rate )
  2416. {
  2417. txPower = pHalData->Index24G_BW40_Base[RFPath][chnlIdx];
  2418. }
  2419. else
  2420. {
  2421. DBG_871X("===> mpt_ProQueryCaltxPower_Jaguar: INVALID Rate.\n");
  2422. }
  2423. //DBG_871X("Base Tx power(RF-%c, Rate #%d, Channel Index %d) = 0x%X\n", ((RFPath==0)?'A':'B'), Rate, chnlIdx, txPower);
  2424. // OFDM-1T
  2425. if ( MGN_6M <= Rate && Rate <= MGN_54M && ! IS_CCK_RATE(Rate) )
  2426. {
  2427. txPower += pHalData->OFDM_24G_Diff[RFPath][TX_1S];
  2428. //DBG_871X("+PowerDiff 2.4G (RF-%c): (OFDM-1T) = (%d)\n", ((RFPath==0)?'A':'B'), pHalData->OFDM_24G_Diff[RFPath][TX_1S]);
  2429. }
  2430. // BW20-1S, BW20-2S
  2431. if (BandWidth == CHANNEL_WIDTH_20)
  2432. {
  2433. if ( (MGN_MCS0 <= Rate && Rate <= MGN_MCS15) || (MGN_VHT2SS_MCS0 <= Rate && Rate <= MGN_VHT2SS_MCS9))
  2434. txPower += pHalData->BW20_24G_Diff[RFPath][TX_1S];
  2435. if ( (MGN_MCS8 <= Rate && Rate <= MGN_MCS15) || (MGN_VHT2SS_MCS0 <= Rate && Rate <= MGN_VHT2SS_MCS9))
  2436. txPower += pHalData->BW20_24G_Diff[RFPath][TX_2S];
  2437. //DBG_871X("+PowerDiff 2.4G (RF-%c): (BW20-1S, BW20-2S) = (%d, %d)\n", ((RFPath==0)?'A':'B'),
  2438. // pHalData->BW20_24G_Diff[RFPath][TX_1S], pHalData->BW20_24G_Diff[RFPath][TX_2S]);
  2439. }
  2440. // BW40-1S, BW40-2S
  2441. else if (BandWidth == CHANNEL_WIDTH_40)
  2442. {
  2443. if ( (MGN_MCS0 <= Rate && Rate <= MGN_MCS15) || (MGN_VHT1SS_MCS0 <= Rate && Rate <= MGN_VHT2SS_MCS9))
  2444. txPower += pHalData->BW40_24G_Diff[RFPath][TX_1S];
  2445. if ( (MGN_MCS8 <= Rate && Rate <= MGN_MCS15) || (MGN_VHT2SS_MCS0 <= Rate && Rate <= MGN_VHT2SS_MCS9))
  2446. txPower += pHalData->BW40_24G_Diff[RFPath][TX_2S];
  2447. //DBG_871X("+PowerDiff 2.4G (RF-%c): (BW40-1S, BW40-2S) = (%d, %d)\n", ((RFPath==0)?'A':'B'),
  2448. // pHalData->BW40_24G_Diff[RFPath][TX_1S], pHalData->BW40_24G_Diff[RFPath][TX_2S]);
  2449. }
  2450. // Willis suggest adopt BW 40M power index while in BW 80 mode
  2451. else if ( BandWidth == CHANNEL_WIDTH_80 )
  2452. {
  2453. if ( (MGN_MCS0 <= Rate && Rate <= MGN_MCS15) || (MGN_VHT1SS_MCS0 <= Rate && Rate <= MGN_VHT2SS_MCS9))
  2454. txPower += pHalData->BW40_24G_Diff[RFPath][TX_1S];
  2455. if ( (MGN_MCS8 <= Rate && Rate <= MGN_MCS15) || (MGN_VHT2SS_MCS0 <= Rate && Rate <= MGN_VHT2SS_MCS9))
  2456. txPower += pHalData->BW40_24G_Diff[RFPath][TX_2S];
  2457. //DBG_871X("+PowerDiff 2.4G (RF-%c): (BW40-1S, BW40-2S) = (%d, %d) P.S. Current is in BW 80MHz\n", ((RFPath==0)?'A':'B'),
  2458. // pHalData->BW40_24G_Diff[RFPath][TX_1S], pHalData->BW40_24G_Diff[RFPath][TX_2S]);
  2459. }
  2460. //
  2461. // 2012/09/26 MH Accordng to BB team's opinion, there might 40M VHT mode in the future.?
  2462. // We need to judge VHT mode by what?
  2463. //
  2464. }
  2465. else //3 ============================== 5 G ==============================
  2466. {
  2467. if ( MGN_6M <= Rate )
  2468. {
  2469. txPower = pHalData->Index5G_BW40_Base[RFPath][chnlIdx];
  2470. }
  2471. else
  2472. {
  2473. DBG_871X("===> mpt_ProQueryCalTxPower_Jaguar: INVALID Rate.\n");
  2474. }
  2475. //DBG_871X("Base Tx power(RF-%c, Rate #%d, Channel Index %d) = 0x%X\n", ((RFPath==0)?'A':'B'), Rate, chnlIdx, txPower);
  2476. // OFDM-1T
  2477. if ( MGN_6M <= Rate && Rate <= MGN_54M && ! IS_CCK_RATE(Rate))
  2478. {
  2479. txPower += pHalData->OFDM_5G_Diff[RFPath][TX_1S];
  2480. //DBG_871X("+PowerDiff 5G (RF-%c): (OFDM-1T) = (%d)\n", ((RFPath==0)?'A':'B'), pHalData->OFDM_5G_Diff[RFPath][TX_1S]);
  2481. }
  2482. // BW20-1S, BW20-2S
  2483. if (BandWidth == CHANNEL_WIDTH_20)
  2484. {
  2485. if ( (MGN_MCS0 <= Rate && Rate <= MGN_MCS15) || (MGN_VHT1SS_MCS0 <= Rate && Rate <= MGN_VHT2SS_MCS9))
  2486. txPower += pHalData->BW20_5G_Diff[RFPath][TX_1S];
  2487. if ( (MGN_MCS8 <= Rate && Rate <= MGN_MCS15) || (MGN_VHT2SS_MCS0 <= Rate && Rate <= MGN_VHT2SS_MCS9))
  2488. txPower += pHalData->BW20_5G_Diff[RFPath][TX_2S];
  2489. //DBG_871X("+PowerDiff 5G (RF-%c): (BW20-1S, BW20-2S) = (%d, %d)\n", ((RFPath==0)?'A':'B'),
  2490. // pHalData->BW20_5G_Diff[RFPath][TX_1S], pHalData->BW20_5G_Diff[RFPath][TX_2S]);
  2491. }
  2492. // BW40-1S, BW40-2S
  2493. else if (BandWidth == CHANNEL_WIDTH_40)
  2494. {
  2495. if ( (MGN_MCS0 <= Rate && Rate <= MGN_MCS15) || (MGN_VHT1SS_MCS0 <= Rate && Rate <= MGN_VHT2SS_MCS9))
  2496. txPower += pHalData->BW40_5G_Diff[RFPath][TX_1S];
  2497. if ( (MGN_MCS8 <= Rate && Rate <= MGN_MCS15) || (MGN_VHT2SS_MCS0 <= Rate && Rate <= MGN_VHT2SS_MCS9))
  2498. txPower += pHalData->BW40_5G_Diff[RFPath][TX_2S];
  2499. //DBG_871X("+PowerDiff 5G(RF-%c): (BW40-1S, BW40-2S) = (%d, %d)\n", ((RFPath==0)?'A':'B'),
  2500. // pHalData->BW40_5G_Diff[RFPath][TX_1S], pHalData->BW40_5G_Diff[RFPath][TX_2S]);
  2501. }
  2502. // BW80-1S, BW80-2S
  2503. else if (BandWidth== CHANNEL_WIDTH_80)
  2504. {
  2505. // <20121220, Kordan> Get the index of array "Index5G_BW80_Base".
  2506. u8 channel5G_80M[CHANNEL_MAX_NUMBER_5G_80M] = {42, 58, 106, 122, 138, 155, 171};
  2507. for (i = 0; i < sizeof(channel5G_80M)/sizeof(u8); ++i)
  2508. if ( channel5G_80M[i] == Channel)
  2509. chnlIdx = i;
  2510. if ( (MGN_MCS0 <= Rate && Rate <= MGN_MCS15) || (MGN_VHT1SS_MCS0 <= Rate && Rate <= MGN_VHT2SS_MCS9))
  2511. txPower = pHalData->Index5G_BW80_Base[RFPath][chnlIdx] + pHalData->BW80_5G_Diff[RFPath][TX_1S];
  2512. if ( (MGN_MCS8 <= Rate && Rate <= MGN_MCS15) || (MGN_VHT2SS_MCS0 <= Rate && Rate <= MGN_VHT2SS_MCS9))
  2513. txPower = pHalData->Index5G_BW80_Base[RFPath][chnlIdx] + pHalData->BW80_5G_Diff[RFPath][TX_1S] + pHalData->BW80_5G_Diff[RFPath][TX_2S];
  2514. //DBG_871X("+PowerDiff 5G(RF-%c): (BW80-1S, BW80-2S) = (%d, %d)\n", ((RFPath==0)?'A':'B'),
  2515. // pHalData->BW80_5G_Diff[RFPath][TX_1S], pHalData->BW80_5G_Diff[RFPath][TX_2S]);
  2516. }
  2517. }
  2518. // Band:-2G&5G = 0 / 1
  2519. // Becasue in the functionwe use the bIn24G = 1=2.4G. Then we need to convert the value.
  2520. // RF: at most 4*4 = ABCD=0/1/2/3
  2521. // CCK=0 11/5.5/2/1
  2522. // OFDM=1/2 18/12/9/6 54/48/36/24
  2523. // HT=3/4/5/6 MCS0-3 MCS4-7 MCS8-11 MCS12-15
  2524. // VHT=7/8/9/10/11 1SSMCS0-3 1SSMCS4-7 2SSMCS1/0/1SSMCS/9/8 2SSMCS2-5
  2525. if (pregistrypriv->RegPwrByRate == _FALSE && pHalData->EEPROMRegulatory != 2)
  2526. {
  2527. powerDiffByRate = phy_GetTxPwrByRateOffset_8812(pAdapter, (u8)(!bIn24G), RFPath, Rate);
  2528. if ( ( pregistrypriv->RegEnableTxPowerLimit == 1 && pHalData->EEPROMRegulatory != 2 ) ||
  2529. pHalData->EEPROMRegulatory == 1 )
  2530. {
  2531. u8 limit = 0;
  2532. limit = PHY_GetPowerLimitValue(pAdapter, pregistrypriv->RegPwrTblSel, (u8)(!bIn24G) ? BAND_ON_5G : BAND_ON_2_4G, BandWidth, (ODM_RF_RADIO_PATH_E)RFPath, Rate, Channel);
  2533. if ( Rate == MGN_VHT1SS_MCS8 || Rate == MGN_VHT1SS_MCS9 ||
  2534. Rate == MGN_VHT2SS_MCS8 || Rate == MGN_VHT2SS_MCS9 )
  2535. {
  2536. if ( limit < 0 )
  2537. {
  2538. if ( powerDiffByRate < -limit )
  2539. powerDiffByRate = -limit;
  2540. }
  2541. }
  2542. else
  2543. {
  2544. if ( limit < 0 )
  2545. powerDiffByRate = limit;
  2546. else
  2547. powerDiffByRate = powerDiffByRate > limit ? limit : powerDiffByRate;
  2548. }
  2549. //DBG_871X("Maximum power by rate %d, final power by rate %d\n", limit, powerDiffByRate );
  2550. }
  2551. }
  2552. //DBG_871X("Rate-%x txPower=%x +PowerDiffByRate(RF-%c) = %d\n", Rate, txPower, ((RFPath==0)?'A':'B'), powerDiffByRate);
  2553. // We need to reduce power index for VHT MCS 8 & 9.
  2554. if (Rate == MGN_VHT1SS_MCS8 || Rate == MGN_VHT1SS_MCS9 ||
  2555. Rate == MGN_VHT2SS_MCS8 || Rate == MGN_VHT2SS_MCS9)
  2556. {
  2557. txPower -= powerDiffByRate;
  2558. }
  2559. else
  2560. {
  2561. #ifdef CONFIG_USB_HCI
  2562. //
  2563. // 2013/01/29 MH For preventing VHT rate of 8812AU to be used in USB 2.0 mode
  2564. // and the current will be more than 500mA and card disappear. We need to limit
  2565. // TX power with any power by rate for VHT in U2.
  2566. // 2013/01/30 MH According to power current test compare with BCM AC NIC, we
  2567. // decide to use host hub = 2.0 mode to enable tx power limit behavior.
  2568. //
  2569. if (adapter_to_dvobj(pAdapter)->usb_speed <= RTW_USB_SPEED_2 && IS_HARDWARE_TYPE_8812AU(pAdapter))
  2570. {
  2571. powerDiffByRate = 0;
  2572. }
  2573. #endif // CONFIG_USB_HCI
  2574. txPower += powerDiffByRate;
  2575. }
  2576. //DBG_871X("BASE ON HT MCS7\n");
  2577. //DBG_871X("Final Tx Power(RF-%c, Channel: %d) = %d(0x%X)\n", ((RFPath==0)?'A':'B'), chnlIdx+1, txPower, txPower);
  2578. if(pDM_Odm->Modify_TxAGC_Flag_PathA || pDM_Odm->Modify_TxAGC_Flag_PathB) //20130424 Mimic whether path A or B has to modify TxAGC
  2579. {
  2580. //DBG_871X("Before add Remanant_OFDMSwingIdx[rfpath %u] %d", txPower);
  2581. txPower += pDM_Odm->Remnant_OFDMSwingIdx[RFPath];
  2582. //DBG_871X("After add Remanant_OFDMSwingIdx[rfpath %u] %d => txPower %d", RFPath, pDM_Odm->Remnant_OFDMSwingIdx[RFPath], txPower);
  2583. }
  2584. if(txPower > MAX_POWER_INDEX)
  2585. txPower = MAX_POWER_INDEX;
  2586. // 2012/09/26 MH We need to take care high power device limiation to prevent destroy EXT_PA.
  2587. // This case had ever happened in CU/SU high power module. THe limitation = 0x20.
  2588. // But for 8812, we still not know the value.
  2589. phy_TxPwrAdjInPercentage(pAdapter, (u8 *)&txPower);
  2590. return txPower;
  2591. }
  2592. /**************************************************************************************************************
  2593. * Description:
  2594. * The low-level interface to set TxAGC , called by both MP and Normal Driver.
  2595. *
  2596. * <20120830, Kordan>
  2597. **************************************************************************************************************/
  2598. VOID
  2599. PHY_SetTxPowerIndex_8812A(
  2600. IN PADAPTER Adapter,
  2601. IN u4Byte PowerIndex,
  2602. IN u1Byte RFPath,
  2603. IN u1Byte Rate
  2604. )
  2605. {
  2606. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  2607. BOOLEAN Direction = FALSE;
  2608. u4Byte TxagcOffset = 0;
  2609. // <20120928, Kordan> A workaround in 8812A/8821A testchip, to fix the bug of odd Tx power indexes.
  2610. if ( (PowerIndex % 2 == 1) && IS_HARDWARE_TYPE_JAGUAR(Adapter) && IS_TEST_CHIP(pHalData->VersionID) )
  2611. PowerIndex -= 1;
  2612. //2013.01.18 LukeLee: Modify TXAGC by dcmd_Dynamic_Ctrl()
  2613. if(RFPath == RF_PATH_A)
  2614. {
  2615. Direction = pHalData->odmpriv.IsTxagcOffsetPositiveA;
  2616. TxagcOffset = pHalData->odmpriv.TxagcOffsetValueA;
  2617. }
  2618. else if(RFPath == RF_PATH_B)
  2619. {
  2620. Direction = pHalData->odmpriv.IsTxagcOffsetPositiveB;
  2621. TxagcOffset = pHalData->odmpriv.TxagcOffsetValueB;
  2622. }
  2623. if(Direction == FALSE)
  2624. {
  2625. if(PowerIndex > TxagcOffset)
  2626. PowerIndex -= TxagcOffset;
  2627. else
  2628. PowerIndex = 0;
  2629. }
  2630. else
  2631. {
  2632. PowerIndex += TxagcOffset;
  2633. if(PowerIndex > 0x3F)
  2634. PowerIndex = 0x3F;
  2635. }
  2636. if (RFPath == RF_PATH_A)
  2637. {
  2638. switch (Rate)
  2639. {
  2640. case MGN_1M: PHY_SetBBReg(Adapter, rTxAGC_A_CCK11_CCK1_JAguar, bMaskByte0, PowerIndex); break;
  2641. case MGN_2M: PHY_SetBBReg(Adapter, rTxAGC_A_CCK11_CCK1_JAguar, bMaskByte1, PowerIndex); break;
  2642. case MGN_5_5M: PHY_SetBBReg(Adapter, rTxAGC_A_CCK11_CCK1_JAguar, bMaskByte2, PowerIndex); break;
  2643. case MGN_11M: PHY_SetBBReg(Adapter, rTxAGC_A_CCK11_CCK1_JAguar, bMaskByte3, PowerIndex); break;
  2644. case MGN_6M: PHY_SetBBReg(Adapter, rTxAGC_A_Ofdm18_Ofdm6_JAguar, bMaskByte0, PowerIndex); break;
  2645. case MGN_9M: PHY_SetBBReg(Adapter, rTxAGC_A_Ofdm18_Ofdm6_JAguar, bMaskByte1, PowerIndex); break;
  2646. case MGN_12M: PHY_SetBBReg(Adapter, rTxAGC_A_Ofdm18_Ofdm6_JAguar, bMaskByte2, PowerIndex); break;
  2647. case MGN_18M: PHY_SetBBReg(Adapter, rTxAGC_A_Ofdm18_Ofdm6_JAguar, bMaskByte3, PowerIndex); break;
  2648. case MGN_24M: PHY_SetBBReg(Adapter, rTxAGC_A_Ofdm54_Ofdm24_JAguar, bMaskByte0, PowerIndex); break;
  2649. case MGN_36M: PHY_SetBBReg(Adapter, rTxAGC_A_Ofdm54_Ofdm24_JAguar, bMaskByte1, PowerIndex); break;
  2650. case MGN_48M: PHY_SetBBReg(Adapter, rTxAGC_A_Ofdm54_Ofdm24_JAguar, bMaskByte2, PowerIndex); break;
  2651. case MGN_54M: PHY_SetBBReg(Adapter, rTxAGC_A_Ofdm54_Ofdm24_JAguar, bMaskByte3, PowerIndex); break;
  2652. case MGN_MCS0: PHY_SetBBReg(Adapter, rTxAGC_A_MCS3_MCS0_JAguar, bMaskByte0, PowerIndex); break;
  2653. case MGN_MCS1: PHY_SetBBReg(Adapter, rTxAGC_A_MCS3_MCS0_JAguar, bMaskByte1, PowerIndex); break;
  2654. case MGN_MCS2: PHY_SetBBReg(Adapter, rTxAGC_A_MCS3_MCS0_JAguar, bMaskByte2, PowerIndex); break;
  2655. case MGN_MCS3: PHY_SetBBReg(Adapter, rTxAGC_A_MCS3_MCS0_JAguar, bMaskByte3, PowerIndex); break;
  2656. case MGN_MCS4: PHY_SetBBReg(Adapter, rTxAGC_A_MCS7_MCS4_JAguar, bMaskByte0, PowerIndex); break;
  2657. case MGN_MCS5: PHY_SetBBReg(Adapter, rTxAGC_A_MCS7_MCS4_JAguar, bMaskByte1, PowerIndex); break;
  2658. case MGN_MCS6: PHY_SetBBReg(Adapter, rTxAGC_A_MCS7_MCS4_JAguar, bMaskByte2, PowerIndex); break;
  2659. case MGN_MCS7: PHY_SetBBReg(Adapter, rTxAGC_A_MCS7_MCS4_JAguar, bMaskByte3, PowerIndex); break;
  2660. case MGN_MCS8: PHY_SetBBReg(Adapter, rTxAGC_A_MCS11_MCS8_JAguar, bMaskByte0, PowerIndex); break;
  2661. case MGN_MCS9: PHY_SetBBReg(Adapter, rTxAGC_A_MCS11_MCS8_JAguar, bMaskByte1, PowerIndex); break;
  2662. case MGN_MCS10: PHY_SetBBReg(Adapter, rTxAGC_A_MCS11_MCS8_JAguar, bMaskByte2, PowerIndex); break;
  2663. case MGN_MCS11: PHY_SetBBReg(Adapter, rTxAGC_A_MCS11_MCS8_JAguar, bMaskByte3, PowerIndex); break;
  2664. case MGN_MCS12: PHY_SetBBReg(Adapter, rTxAGC_A_MCS15_MCS12_JAguar, bMaskByte0, PowerIndex); break;
  2665. case MGN_MCS13: PHY_SetBBReg(Adapter, rTxAGC_A_MCS15_MCS12_JAguar, bMaskByte1, PowerIndex); break;
  2666. case MGN_MCS14: PHY_SetBBReg(Adapter, rTxAGC_A_MCS15_MCS12_JAguar, bMaskByte2, PowerIndex); break;
  2667. case MGN_MCS15: PHY_SetBBReg(Adapter, rTxAGC_A_MCS15_MCS12_JAguar, bMaskByte3, PowerIndex); break;
  2668. case MGN_VHT1SS_MCS0: PHY_SetBBReg(Adapter, rTxAGC_A_Nss1Index3_Nss1Index0_JAguar, bMaskByte0, PowerIndex); break;
  2669. case MGN_VHT1SS_MCS1: PHY_SetBBReg(Adapter, rTxAGC_A_Nss1Index3_Nss1Index0_JAguar, bMaskByte1, PowerIndex); break;
  2670. case MGN_VHT1SS_MCS2: PHY_SetBBReg(Adapter, rTxAGC_A_Nss1Index3_Nss1Index0_JAguar, bMaskByte2, PowerIndex); break;
  2671. case MGN_VHT1SS_MCS3: PHY_SetBBReg(Adapter, rTxAGC_A_Nss1Index3_Nss1Index0_JAguar, bMaskByte3, PowerIndex); break;
  2672. case MGN_VHT1SS_MCS4: PHY_SetBBReg(Adapter, rTxAGC_A_Nss1Index7_Nss1Index4_JAguar, bMaskByte0, PowerIndex); break;
  2673. case MGN_VHT1SS_MCS5: PHY_SetBBReg(Adapter, rTxAGC_A_Nss1Index7_Nss1Index4_JAguar, bMaskByte1, PowerIndex); break;
  2674. case MGN_VHT1SS_MCS6: PHY_SetBBReg(Adapter, rTxAGC_A_Nss1Index7_Nss1Index4_JAguar, bMaskByte2, PowerIndex); break;
  2675. case MGN_VHT1SS_MCS7: PHY_SetBBReg(Adapter, rTxAGC_A_Nss1Index7_Nss1Index4_JAguar, bMaskByte3, PowerIndex); break;
  2676. case MGN_VHT1SS_MCS8: PHY_SetBBReg(Adapter, rTxAGC_A_Nss2Index1_Nss1Index8_JAguar, bMaskByte0, PowerIndex); break;
  2677. case MGN_VHT1SS_MCS9: PHY_SetBBReg(Adapter, rTxAGC_A_Nss2Index1_Nss1Index8_JAguar, bMaskByte1, PowerIndex); break;
  2678. case MGN_VHT2SS_MCS0: PHY_SetBBReg(Adapter, rTxAGC_A_Nss2Index1_Nss1Index8_JAguar, bMaskByte2, PowerIndex); break;
  2679. case MGN_VHT2SS_MCS1: PHY_SetBBReg(Adapter, rTxAGC_A_Nss2Index1_Nss1Index8_JAguar, bMaskByte3, PowerIndex); break;
  2680. case MGN_VHT2SS_MCS2: PHY_SetBBReg(Adapter, rTxAGC_A_Nss2Index5_Nss2Index2_JAguar, bMaskByte0, PowerIndex); break;
  2681. case MGN_VHT2SS_MCS3: PHY_SetBBReg(Adapter, rTxAGC_A_Nss2Index5_Nss2Index2_JAguar, bMaskByte1, PowerIndex); break;
  2682. case MGN_VHT2SS_MCS4: PHY_SetBBReg(Adapter, rTxAGC_A_Nss2Index5_Nss2Index2_JAguar, bMaskByte2, PowerIndex); break;
  2683. case MGN_VHT2SS_MCS5: PHY_SetBBReg(Adapter, rTxAGC_A_Nss2Index5_Nss2Index2_JAguar, bMaskByte3, PowerIndex); break;
  2684. case MGN_VHT2SS_MCS6: PHY_SetBBReg(Adapter, rTxAGC_A_Nss2Index9_Nss2Index6_JAguar, bMaskByte0, PowerIndex); break;
  2685. case MGN_VHT2SS_MCS7: PHY_SetBBReg(Adapter, rTxAGC_A_Nss2Index9_Nss2Index6_JAguar, bMaskByte1, PowerIndex); break;
  2686. case MGN_VHT2SS_MCS8: PHY_SetBBReg(Adapter, rTxAGC_A_Nss2Index9_Nss2Index6_JAguar, bMaskByte2, PowerIndex); break;
  2687. case MGN_VHT2SS_MCS9: PHY_SetBBReg(Adapter, rTxAGC_A_Nss2Index9_Nss2Index6_JAguar, bMaskByte3, PowerIndex); break;
  2688. default:
  2689. DBG_871X("Invalid Rate!!\n");
  2690. break;
  2691. }
  2692. }
  2693. else if (RFPath == RF_PATH_B)
  2694. {
  2695. switch (Rate)
  2696. {
  2697. case MGN_1M: PHY_SetBBReg(Adapter, rTxAGC_B_CCK11_CCK1_JAguar, bMaskByte0, PowerIndex); break;
  2698. case MGN_2M: PHY_SetBBReg(Adapter, rTxAGC_B_CCK11_CCK1_JAguar, bMaskByte1, PowerIndex); break;
  2699. case MGN_5_5M: PHY_SetBBReg(Adapter, rTxAGC_B_CCK11_CCK1_JAguar, bMaskByte2, PowerIndex); break;
  2700. case MGN_11M: PHY_SetBBReg(Adapter, rTxAGC_B_CCK11_CCK1_JAguar, bMaskByte3, PowerIndex); break;
  2701. case MGN_6M: PHY_SetBBReg(Adapter, rTxAGC_B_Ofdm18_Ofdm6_JAguar, bMaskByte0, PowerIndex); break;
  2702. case MGN_9M: PHY_SetBBReg(Adapter, rTxAGC_B_Ofdm18_Ofdm6_JAguar, bMaskByte1, PowerIndex); break;
  2703. case MGN_12M: PHY_SetBBReg(Adapter, rTxAGC_B_Ofdm18_Ofdm6_JAguar, bMaskByte2, PowerIndex); break;
  2704. case MGN_18M: PHY_SetBBReg(Adapter, rTxAGC_B_Ofdm18_Ofdm6_JAguar, bMaskByte3, PowerIndex); break;
  2705. case MGN_24M: PHY_SetBBReg(Adapter, rTxAGC_B_Ofdm54_Ofdm24_JAguar, bMaskByte0, PowerIndex); break;
  2706. case MGN_36M: PHY_SetBBReg(Adapter, rTxAGC_B_Ofdm54_Ofdm24_JAguar, bMaskByte1, PowerIndex); break;
  2707. case MGN_48M: PHY_SetBBReg(Adapter, rTxAGC_B_Ofdm54_Ofdm24_JAguar, bMaskByte2, PowerIndex); break;
  2708. case MGN_54M: PHY_SetBBReg(Adapter, rTxAGC_B_Ofdm54_Ofdm24_JAguar, bMaskByte3, PowerIndex); break;
  2709. case MGN_MCS0: PHY_SetBBReg(Adapter, rTxAGC_B_MCS3_MCS0_JAguar, bMaskByte0, PowerIndex); break;
  2710. case MGN_MCS1: PHY_SetBBReg(Adapter, rTxAGC_B_MCS3_MCS0_JAguar, bMaskByte1, PowerIndex); break;
  2711. case MGN_MCS2: PHY_SetBBReg(Adapter, rTxAGC_B_MCS3_MCS0_JAguar, bMaskByte2, PowerIndex); break;
  2712. case MGN_MCS3: PHY_SetBBReg(Adapter, rTxAGC_B_MCS3_MCS0_JAguar, bMaskByte3, PowerIndex); break;
  2713. case MGN_MCS4: PHY_SetBBReg(Adapter, rTxAGC_B_MCS7_MCS4_JAguar, bMaskByte0, PowerIndex); break;
  2714. case MGN_MCS5: PHY_SetBBReg(Adapter, rTxAGC_B_MCS7_MCS4_JAguar, bMaskByte1, PowerIndex); break;
  2715. case MGN_MCS6: PHY_SetBBReg(Adapter, rTxAGC_B_MCS7_MCS4_JAguar, bMaskByte2, PowerIndex); break;
  2716. case MGN_MCS7: PHY_SetBBReg(Adapter, rTxAGC_B_MCS7_MCS4_JAguar, bMaskByte3, PowerIndex); break;
  2717. case MGN_MCS8: PHY_SetBBReg(Adapter, rTxAGC_B_MCS11_MCS8_JAguar, bMaskByte0, PowerIndex); break;
  2718. case MGN_MCS9: PHY_SetBBReg(Adapter, rTxAGC_B_MCS11_MCS8_JAguar, bMaskByte1, PowerIndex); break;
  2719. case MGN_MCS10: PHY_SetBBReg(Adapter, rTxAGC_B_MCS11_MCS8_JAguar, bMaskByte2, PowerIndex); break;
  2720. case MGN_MCS11: PHY_SetBBReg(Adapter, rTxAGC_B_MCS11_MCS8_JAguar, bMaskByte3, PowerIndex); break;
  2721. case MGN_MCS12: PHY_SetBBReg(Adapter, rTxAGC_B_MCS15_MCS12_JAguar, bMaskByte0, PowerIndex); break;
  2722. case MGN_MCS13: PHY_SetBBReg(Adapter, rTxAGC_B_MCS15_MCS12_JAguar, bMaskByte1, PowerIndex); break;
  2723. case MGN_MCS14: PHY_SetBBReg(Adapter, rTxAGC_B_MCS15_MCS12_JAguar, bMaskByte2, PowerIndex); break;
  2724. case MGN_MCS15: PHY_SetBBReg(Adapter, rTxAGC_B_MCS15_MCS12_JAguar, bMaskByte3, PowerIndex); break;
  2725. case MGN_VHT1SS_MCS0: PHY_SetBBReg(Adapter, rTxAGC_B_Nss1Index3_Nss1Index0_JAguar, bMaskByte0, PowerIndex); break;
  2726. case MGN_VHT1SS_MCS1: PHY_SetBBReg(Adapter, rTxAGC_B_Nss1Index3_Nss1Index0_JAguar, bMaskByte1, PowerIndex); break;
  2727. case MGN_VHT1SS_MCS2: PHY_SetBBReg(Adapter, rTxAGC_B_Nss1Index3_Nss1Index0_JAguar, bMaskByte2, PowerIndex); break;
  2728. case MGN_VHT1SS_MCS3: PHY_SetBBReg(Adapter, rTxAGC_B_Nss1Index3_Nss1Index0_JAguar, bMaskByte3, PowerIndex); break;
  2729. case MGN_VHT1SS_MCS4: PHY_SetBBReg(Adapter, rTxAGC_B_Nss1Index7_Nss1Index4_JAguar, bMaskByte0, PowerIndex); break;
  2730. case MGN_VHT1SS_MCS5: PHY_SetBBReg(Adapter, rTxAGC_B_Nss1Index7_Nss1Index4_JAguar, bMaskByte1, PowerIndex); break;
  2731. case MGN_VHT1SS_MCS6: PHY_SetBBReg(Adapter, rTxAGC_B_Nss1Index7_Nss1Index4_JAguar, bMaskByte2, PowerIndex); break;
  2732. case MGN_VHT1SS_MCS7: PHY_SetBBReg(Adapter, rTxAGC_B_Nss1Index7_Nss1Index4_JAguar, bMaskByte3, PowerIndex); break;
  2733. case MGN_VHT1SS_MCS8: PHY_SetBBReg(Adapter, rTxAGC_B_Nss2Index1_Nss1Index8_JAguar, bMaskByte0, PowerIndex); break;
  2734. case MGN_VHT1SS_MCS9: PHY_SetBBReg(Adapter, rTxAGC_B_Nss2Index1_Nss1Index8_JAguar, bMaskByte1, PowerIndex); break;
  2735. case MGN_VHT2SS_MCS0: PHY_SetBBReg(Adapter, rTxAGC_B_Nss2Index1_Nss1Index8_JAguar, bMaskByte2, PowerIndex); break;
  2736. case MGN_VHT2SS_MCS1: PHY_SetBBReg(Adapter, rTxAGC_B_Nss2Index1_Nss1Index8_JAguar, bMaskByte3, PowerIndex); break;
  2737. case MGN_VHT2SS_MCS2: PHY_SetBBReg(Adapter, rTxAGC_B_Nss2Index5_Nss2Index2_JAguar, bMaskByte0, PowerIndex); break;
  2738. case MGN_VHT2SS_MCS3: PHY_SetBBReg(Adapter, rTxAGC_B_Nss2Index5_Nss2Index2_JAguar, bMaskByte1, PowerIndex); break;
  2739. case MGN_VHT2SS_MCS4: PHY_SetBBReg(Adapter, rTxAGC_B_Nss2Index5_Nss2Index2_JAguar, bMaskByte2, PowerIndex); break;
  2740. case MGN_VHT2SS_MCS5: PHY_SetBBReg(Adapter, rTxAGC_B_Nss2Index5_Nss2Index2_JAguar, bMaskByte3, PowerIndex); break;
  2741. case MGN_VHT2SS_MCS6: PHY_SetBBReg(Adapter, rTxAGC_B_Nss2Index9_Nss2Index6_JAguar, bMaskByte0, PowerIndex); break;
  2742. case MGN_VHT2SS_MCS7: PHY_SetBBReg(Adapter, rTxAGC_B_Nss2Index9_Nss2Index6_JAguar, bMaskByte1, PowerIndex); break;
  2743. case MGN_VHT2SS_MCS8: PHY_SetBBReg(Adapter, rTxAGC_B_Nss2Index9_Nss2Index6_JAguar, bMaskByte2, PowerIndex); break;
  2744. case MGN_VHT2SS_MCS9: PHY_SetBBReg(Adapter, rTxAGC_B_Nss2Index9_Nss2Index6_JAguar, bMaskByte3, PowerIndex); break;
  2745. default:
  2746. DBG_871X("Invalid Rate!!\n");
  2747. break;
  2748. }
  2749. }
  2750. else
  2751. {
  2752. DBG_871X("Invalid RFPath!!\n");
  2753. }
  2754. }
  2755. VOID
  2756. phy_SetTxPowerIndexByRateArray(
  2757. IN PADAPTER pAdapter,
  2758. IN u8 RFPath,
  2759. IN CHANNEL_WIDTH BandWidth,
  2760. IN u8 Channel,
  2761. IN u8* Rates,
  2762. IN u8 RateArraySize
  2763. )
  2764. {
  2765. u32 powerIndex = 0;
  2766. int i = 0;
  2767. for (i = 0; i < RateArraySize; ++i)
  2768. {
  2769. powerIndex = PHY_GetTxPowerIndex_8812A(pAdapter, RFPath, Rates[i], BandWidth, Channel);
  2770. PHY_SetTxPowerIndex_8812A(pAdapter, powerIndex, RFPath, Rates[i]);
  2771. }
  2772. }
  2773. VOID
  2774. PHY_GetTxPowerIndexByRateArray_8812A(
  2775. IN PADAPTER pAdapter,
  2776. IN u8 RFPath,
  2777. IN CHANNEL_WIDTH BandWidth,
  2778. IN u8 Channel,
  2779. IN u8* Rate,
  2780. OUT u8* PowerIndex,
  2781. IN u8 ArraySize
  2782. )
  2783. {
  2784. PHAL_DATA_TYPE pHalData = GET_HAL_DATA(pAdapter);
  2785. u8 i;
  2786. for(i=0 ; i<ArraySize; i++)
  2787. {
  2788. PowerIndex[i] = (u8)PHY_GetTxPowerIndex_8812A(pAdapter, RFPath, Rate[i], BandWidth, Channel);
  2789. if ( (PowerIndex[i] % 2 == 1) && IS_HARDWARE_TYPE_JAGUAR(pAdapter) && ! IS_NORMAL_CHIP(pHalData->VersionID) )
  2790. PowerIndex[i] -= 1;
  2791. }
  2792. }
  2793. VOID
  2794. phy_TxPowerTrainingByPath_8812(
  2795. IN PADAPTER Adapter,
  2796. IN CHANNEL_WIDTH BandWidth,
  2797. IN u8 Channel,
  2798. IN u8 RfPath
  2799. )
  2800. {
  2801. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  2802. u8 i;
  2803. u32 PowerLevel, writeData, writeOffset;
  2804. if(RfPath >= pHalData->NumTotalRFPath)
  2805. return;
  2806. writeData = 0;
  2807. if(RfPath == ODM_RF_PATH_A)
  2808. {
  2809. PowerLevel = PHY_GetTxPowerIndex_8812A(Adapter, ODM_RF_PATH_A, MGN_MCS7, BandWidth, Channel);
  2810. writeOffset = rA_TxPwrTraing_Jaguar;
  2811. }
  2812. else
  2813. {
  2814. PowerLevel = PHY_GetTxPowerIndex_8812A(Adapter, ODM_RF_PATH_B, MGN_MCS7, BandWidth, Channel);
  2815. writeOffset = rB_TxPwrTraing_Jaguar;
  2816. }
  2817. for(i = 0; i < 3; i++)
  2818. {
  2819. if(i == 0)
  2820. PowerLevel = PowerLevel - 10;
  2821. else if(i == 1)
  2822. PowerLevel = PowerLevel - 8;
  2823. else
  2824. PowerLevel = PowerLevel - 6;
  2825. writeData |= (((PowerLevel > 2)?(PowerLevel):2) << (i * 8));
  2826. }
  2827. PHY_SetBBReg(Adapter, writeOffset, 0xffffff, writeData);
  2828. }
  2829. VOID
  2830. PHY_SetTxPowerLevelByPath8812(
  2831. IN PADAPTER Adapter,
  2832. IN u8 channel,
  2833. IN u8 path
  2834. )
  2835. {
  2836. PHAL_DATA_TYPE pHalData = GET_HAL_DATA(Adapter);
  2837. struct registry_priv *pregistrypriv = &Adapter->registrypriv;
  2838. u8 cckRates[] = {MGN_1M, MGN_2M, MGN_5_5M, MGN_11M};
  2839. u8 ofdmRates[] = {MGN_6M, MGN_9M, MGN_12M, MGN_18M, MGN_24M, MGN_36M, MGN_48M, MGN_54M};
  2840. u8 htRates1T[] = {MGN_MCS0, MGN_MCS1, MGN_MCS2, MGN_MCS3, MGN_MCS4, MGN_MCS5, MGN_MCS6, MGN_MCS7};
  2841. u8 htRates2T[] = {MGN_MCS8, MGN_MCS9, MGN_MCS10, MGN_MCS11, MGN_MCS12, MGN_MCS13, MGN_MCS14, MGN_MCS15};
  2842. u8 vhtRates1T[] = {MGN_VHT1SS_MCS0, MGN_VHT1SS_MCS1, MGN_VHT1SS_MCS2, MGN_VHT1SS_MCS3, MGN_VHT1SS_MCS4,
  2843. MGN_VHT1SS_MCS5, MGN_VHT1SS_MCS6, MGN_VHT1SS_MCS7, MGN_VHT1SS_MCS8, MGN_VHT1SS_MCS9};
  2844. u8 vhtRates2T[] = {MGN_VHT2SS_MCS0, MGN_VHT2SS_MCS1, MGN_VHT2SS_MCS2, MGN_VHT2SS_MCS3, MGN_VHT2SS_MCS4,
  2845. MGN_VHT2SS_MCS5, MGN_VHT2SS_MCS6, MGN_VHT2SS_MCS7, MGN_VHT2SS_MCS8, MGN_VHT2SS_MCS9};
  2846. //DBG_871X("==>PHY_SetTxPowerLevelByPath8812()\n");
  2847. #if(MP_DRIVER == 1)
  2848. if (pregistrypriv->mp_mode == 1)
  2849. return;
  2850. #endif
  2851. //if(pMgntInfo->RegNByteAccess == 0)
  2852. {
  2853. if(pHalData->CurrentBandType == BAND_ON_2_4G)
  2854. phy_SetTxPowerIndexByRateArray(Adapter, path, pHalData->CurrentChannelBW, channel,
  2855. cckRates, sizeof(cckRates)/sizeof(u1Byte));
  2856. phy_SetTxPowerIndexByRateArray(Adapter, path, pHalData->CurrentChannelBW, channel,
  2857. ofdmRates, sizeof(ofdmRates)/sizeof(u1Byte));
  2858. phy_SetTxPowerIndexByRateArray(Adapter, path, pHalData->CurrentChannelBW, channel,
  2859. htRates1T, sizeof(htRates1T)/sizeof(u1Byte));
  2860. phy_SetTxPowerIndexByRateArray(Adapter, path, pHalData->CurrentChannelBW, channel,
  2861. vhtRates1T, sizeof(vhtRates1T)/sizeof(u1Byte));
  2862. if(pHalData->NumTotalRFPath >= 2)
  2863. {
  2864. phy_SetTxPowerIndexByRateArray(Adapter, path, pHalData->CurrentChannelBW, channel,
  2865. htRates2T, sizeof(htRates2T)/sizeof(u1Byte));
  2866. phy_SetTxPowerIndexByRateArray(Adapter, path, pHalData->CurrentChannelBW, channel,
  2867. vhtRates2T, sizeof(vhtRates2T)/sizeof(u1Byte));
  2868. }
  2869. }
  2870. /*else
  2871. {
  2872. u1Byte cckRatesSize = sizeof(cckRates)/sizeof(u1Byte);
  2873. u1Byte ofdmRatesSize = sizeof(ofdmRates)/sizeof(u1Byte);
  2874. u1Byte htRates1TSize = sizeof(htRates1T)/sizeof(u1Byte);
  2875. u1Byte htRates2TSize = sizeof(htRates2T)/sizeof(u1Byte);
  2876. u1Byte vhtRates1TSize = sizeof(vhtRates1T)/sizeof(u1Byte);
  2877. u1Byte vhtRates2TSize = sizeof(vhtRates2T)/sizeof(u1Byte);
  2878. u1Byte PowerIndexArray[POWERINDEX_ARRAY_SIZE];
  2879. u1Byte Length;
  2880. u4Byte RegAddress;
  2881. RT_TRACE(COMP_SCAN, DBG_LOUD, ("PHY_SetTxPowerLevel8812ByPath(): path = %d.\n",path));
  2882. PHY_GetTxPowerIndexByRateArray_8812A(Adapter, path,pHalData->CurrentChannelBW, channel,ofdmRates,&PowerIndexArray[cckRatesSize],ofdmRatesSize);
  2883. PHY_GetTxPowerIndexByRateArray_8812A(Adapter, path,pHalData->CurrentChannelBW, channel,htRates1T,&PowerIndexArray[cckRatesSize+ofdmRatesSize],htRates1TSize);
  2884. if(pHalData->CurrentBandType == BAND_ON_2_4G)
  2885. {
  2886. PHY_GetTxPowerIndexByRateArray_8812A(Adapter, path,pHalData->CurrentChannelBW, channel,cckRates,&PowerIndexArray[0],cckRatesSize);
  2887. PHY_GetTxPowerIndexByRateArray_8812A(Adapter, path,pHalData->CurrentChannelBW, channel,vhtRates1T,&PowerIndexArray[cckRatesSize+ofdmRatesSize+htRates1TSize+htRates2TSize],vhtRates1TSize);
  2888. Length = cckRatesSize + ofdmRatesSize + htRates1TSize + htRates2TSize + vhtRates1TSize;
  2889. if(pHalData->NumTotalRFPath >= 2)
  2890. {
  2891. PHY_GetTxPowerIndexByRateArray_8812A(Adapter, path,pHalData->CurrentChannelBW, channel,htRates2T,&PowerIndexArray[cckRatesSize+ofdmRatesSize+htRates1TSize],htRates2TSize);
  2892. PHY_GetTxPowerIndexByRateArray_8812A(Adapter, path,pHalData->CurrentChannelBW, channel,vhtRates2T,&PowerIndexArray[cckRatesSize+ofdmRatesSize+htRates1TSize+htRates2TSize+vhtRates1TSize],vhtRates2TSize);
  2893. Length += vhtRates2TSize;
  2894. }
  2895. if(path == ODM_RF_PATH_A)
  2896. RegAddress = rTxAGC_A_CCK11_CCK1_JAguar;
  2897. else //ODM_RF_PATH_B
  2898. RegAddress = rTxAGC_B_CCK11_CCK1_JAguar;
  2899. #ifdef CONFIG_USB_HCI
  2900. if(pMgntInfo->RegNByteAccess == 2) //N Byte access
  2901. {
  2902. PlatformIOWriteNByte(Adapter,RegAddress,Length,PowerIndexArray);
  2903. }
  2904. else if(pMgntInfo->RegNByteAccess == 1) //DW access
  2905. #endif
  2906. {
  2907. u1Byte i, j;
  2908. for(i = 0;i < Length;i+=4)
  2909. {
  2910. u4Byte powerIndex = 0;
  2911. for(j = 0;j < 4; j++)
  2912. {
  2913. powerIndex |= (PowerIndexArray[i+j]<<(8*j));
  2914. }
  2915. PHY_SetBBReg(Adapter, RegAddress+i, bMaskDWord, powerIndex);
  2916. }
  2917. }
  2918. }
  2919. else if(pHalData->CurrentBandType == BAND_ON_5G)
  2920. {
  2921. PHY_GetTxPowerIndexByRateArray_8812A(Adapter, path,pHalData->CurrentChannelBW, channel,vhtRates1T,&PowerIndexArray[cckRatesSize+ofdmRatesSize+htRates1TSize+htRates2TSize],vhtRates1TSize);
  2922. if(pHalData->NumTotalRFPath >= 2)
  2923. {
  2924. PHY_GetTxPowerIndexByRateArray_8812A(Adapter, path,pHalData->CurrentChannelBW, channel,htRates2T,&PowerIndexArray[cckRatesSize+ofdmRatesSize+htRates1TSize],htRates2TSize);
  2925. PHY_GetTxPowerIndexByRateArray_8812A(Adapter, path,pHalData->CurrentChannelBW, channel,vhtRates2T,&PowerIndexArray[cckRatesSize+ofdmRatesSize+htRates1TSize+htRates2TSize+vhtRates1TSize],vhtRates2TSize);
  2926. Length = ofdmRatesSize + htRates1TSize + htRates2TSize + vhtRates1TSize + vhtRates2TSize;
  2927. }
  2928. else
  2929. {
  2930. if(path == ODM_RF_PATH_A)
  2931. RegAddress = rTxAGC_A_Nss1Index3_Nss1Index0_JAguar;
  2932. else // ODM_RF_PATH_B
  2933. RegAddress = rTxAGC_B_Nss1Index3_Nss1Index0_JAguar;
  2934. #ifdef CONFIG_USB_HCI
  2935. if(pMgntInfo->RegNByteAccess == 2)
  2936. {
  2937. PlatformIOWriteNByte(Adapter,RegAddress,vhtRates1TSize,&PowerIndexArray[cckRatesSize + ofdmRatesSize + htRates1TSize + htRates2TSize]);
  2938. }
  2939. else if(pMgntInfo->RegNByteAccess == 1) //DW access
  2940. #endif
  2941. {
  2942. u1Byte i, j;
  2943. for(i = 0;i < vhtRates1TSize;i+=4)
  2944. {
  2945. u4Byte powerIndex = 0;
  2946. for(j = 0;j < 4; j++)
  2947. {
  2948. powerIndex |= (PowerIndexArray[cckRatesSize + ofdmRatesSize + htRates1TSize + htRates2TSize+i+j]<<(8*j));
  2949. }
  2950. PHY_SetBBReg(Adapter, RegAddress+i, bMaskDWord, powerIndex);
  2951. }
  2952. {
  2953. u4Byte powerIndex = 0;
  2954. //i+=4;
  2955. for(j = 0;j < vhtRates1TSize%4;j++) // for Nss1 MCS8,9
  2956. {
  2957. powerIndex |= (PowerIndexArray[cckRatesSize + ofdmRatesSize + htRates1TSize + htRates2TSize+i+j]<<(8*j));
  2958. }
  2959. PHY_SetBBReg(Adapter, RegAddress+i, bMaskLWord, powerIndex);
  2960. }
  2961. }
  2962. Length = ofdmRatesSize + htRates1TSize;
  2963. }
  2964. if(path == ODM_RF_PATH_A)
  2965. RegAddress = rTxAGC_A_Ofdm18_Ofdm6_JAguar;
  2966. else // ODM_RF_PATH_B
  2967. RegAddress = rTxAGC_B_Ofdm18_Ofdm6_JAguar;
  2968. #ifdef CONFIG_USB_HCI
  2969. if(pMgntInfo->RegNByteAccess == 2)
  2970. {
  2971. PlatformIOWriteNByte(Adapter,RegAddress,Length,&PowerIndexArray[cckRatesSize]);
  2972. }
  2973. else if(pMgntInfo->RegNByteAccess == 1) //DW
  2974. #endif
  2975. {
  2976. u1Byte i, j;
  2977. for(i = 0;i < Length;i+=4)
  2978. {
  2979. u4Byte powerIndex = 0;
  2980. for(j = 0;j < 4; j++)
  2981. {
  2982. powerIndex |= (PowerIndexArray[cckRatesSize+i+j]<<(8*j));
  2983. }
  2984. PHY_SetBBReg(Adapter, RegAddress+i, bMaskDWord, powerIndex);
  2985. }
  2986. }
  2987. }
  2988. }*/
  2989. phy_TxPowerTrainingByPath_8812(Adapter, pHalData->CurrentChannelBW, channel, path);
  2990. //DBG_871X("<==PHY_SetTxPowerLevelByPath8812()\n");
  2991. }
  2992. //create new definition of PHY_SetTxPowerLevel8812 by YP.
  2993. //Page revised on 20121106
  2994. //the new way to set tx power by rate, NByte access, here N byte shall be 4 byte(DWord) or NByte(N>4) access. by page/YP, 20121106
  2995. VOID
  2996. PHY_SetTxPowerLevel8812(
  2997. IN PADAPTER Adapter,
  2998. IN u8 Channel
  2999. )
  3000. {
  3001. PHAL_DATA_TYPE pHalData = GET_HAL_DATA(Adapter);
  3002. u8 path = 0;
  3003. //DBG_871X("==>PHY_SetTxPowerLevel8812()\n");
  3004. for( path = ODM_RF_PATH_A; path < pHalData->NumTotalRFPath; ++path )
  3005. {
  3006. PHY_SetTxPowerLevelByPath8812(Adapter, Channel, path);
  3007. }
  3008. //DBG_871X("<==PHY_SetTxPowerLevel8812()\n");
  3009. }
  3010. BOOLEAN
  3011. PHY_UpdateTxPowerDbm8812(
  3012. IN PADAPTER Adapter,
  3013. IN int powerInDbm
  3014. )
  3015. {
  3016. return _TRUE;
  3017. }
  3018. u32 PHY_GetTxBBSwing_8812A(
  3019. IN PADAPTER Adapter,
  3020. IN BAND_TYPE Band,
  3021. IN u8 RFPath
  3022. )
  3023. {
  3024. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(GetDefaultAdapter(Adapter));
  3025. PDM_ODM_T pDM_Odm = &pHalData->odmpriv;
  3026. PODM_RF_CAL_T pRFCalibrateInfo = &(pDM_Odm->RFCalibrateInfo);
  3027. EEPROM_EFUSE_PRIV *pEEPROM = GET_EEPROM_EFUSE_PRIV(Adapter);
  3028. s8 bbSwing_2G = -1 * GetRegTxBBSwing_2G(Adapter);
  3029. s8 bbSwing_5G = -1 * GetRegTxBBSwing_5G(Adapter);
  3030. u32 out = 0x200;
  3031. const s8 AUTO = -1;
  3032. if (pEEPROM->bautoload_fail_flag)
  3033. {
  3034. if ( Band == BAND_ON_2_4G ) {
  3035. pRFCalibrateInfo->BBSwingDiff2G = bbSwing_2G;
  3036. if (bbSwing_2G == 0) out = 0x200; // 0 dB
  3037. else if (bbSwing_2G == -3) out = 0x16A; // -3 dB
  3038. else if (bbSwing_2G == -6) out = 0x101; // -6 dB
  3039. else if (bbSwing_2G == -9) out = 0x0B6; // -9 dB
  3040. else {
  3041. if ( pHalData->ExternalPA_2G ) {
  3042. pRFCalibrateInfo->BBSwingDiff2G = -3;
  3043. out = 0x16A;
  3044. } else {
  3045. pRFCalibrateInfo->BBSwingDiff2G = 0;
  3046. out = 0x200;
  3047. }
  3048. }
  3049. } else if ( Band == BAND_ON_5G ) {
  3050. pRFCalibrateInfo->BBSwingDiff5G = bbSwing_5G;
  3051. if (bbSwing_5G == 0) out = 0x200; // 0 dB
  3052. else if (bbSwing_5G == -3) out = 0x16A; // -3 dB
  3053. else if (bbSwing_5G == -6) out = 0x101; // -6 dB
  3054. else if (bbSwing_5G == -9) out = 0x0B6; // -9 dB
  3055. else {
  3056. if ( pHalData->ExternalPA_5G ) {
  3057. pRFCalibrateInfo->BBSwingDiff5G = -3;
  3058. out = 0x16A;
  3059. } else {
  3060. pRFCalibrateInfo->BBSwingDiff5G = 0;
  3061. out = 0x200;
  3062. }
  3063. }
  3064. } else {
  3065. pRFCalibrateInfo->BBSwingDiff2G = -3;
  3066. pRFCalibrateInfo->BBSwingDiff5G = -3;
  3067. out = 0x16A; // -3 dB
  3068. }
  3069. }
  3070. else
  3071. {
  3072. u32 swing = 0, swingA = 0, swingB = 0;
  3073. if (Band == BAND_ON_2_4G) {
  3074. if (GetRegTxBBSwing_2G(Adapter) == AUTO)
  3075. {
  3076. EFUSE_ShadowRead(Adapter, 1, EEPROM_TX_BBSWING_2G_8812, (u32 *)&swing);
  3077. swing = (swing == 0xFF) ? 0x00 : swing;
  3078. }
  3079. else if (bbSwing_2G == 0) swing = 0x00; // 0 dB
  3080. else if (bbSwing_2G == -3) swing = 0x05; // -3 dB
  3081. else if (bbSwing_2G == -6) swing = 0x0A; // -6 dB
  3082. else if (bbSwing_2G == -9) swing = 0xFF; // -9 dB
  3083. else swing = 0x00;
  3084. }
  3085. else {
  3086. if (GetRegTxBBSwing_5G(Adapter) == AUTO)
  3087. {
  3088. EFUSE_ShadowRead(Adapter, 1, EEPROM_TX_BBSWING_5G_8812, (u32 *)&swing);
  3089. swing = (swing == 0xFF) ? 0x00 : swing;
  3090. }
  3091. else if (bbSwing_5G == 0) swing = 0x00; // 0 dB
  3092. else if (bbSwing_5G == -3) swing = 0x05; // -3 dB
  3093. else if (bbSwing_5G == -6) swing = 0x0A; // -6 dB
  3094. else if (bbSwing_5G == -9) swing = 0xFF; // -9 dB
  3095. else swing = 0x00;
  3096. }
  3097. swingA = (swing & 0x3) >> 0; // 0xC6/C7[1:0]
  3098. swingB = (swing & 0xC) >> 2; // 0xC6/C7[3:2]
  3099. //DBG_871X("===> PHY_GetTxBBSwing_8812A, swingA: 0x%X, swingB: 0x%X\n", swingA, swingB);
  3100. //3 Path-A
  3101. if (swingA == 0x00) {
  3102. if (Band == BAND_ON_2_4G)
  3103. pRFCalibrateInfo->BBSwingDiff2G = 0;
  3104. else
  3105. pRFCalibrateInfo->BBSwingDiff5G = 0;
  3106. out = 0x200; // 0 dB
  3107. } else if (swingA == 0x01) {
  3108. if (Band == BAND_ON_2_4G)
  3109. pRFCalibrateInfo->BBSwingDiff2G = -3;
  3110. else
  3111. pRFCalibrateInfo->BBSwingDiff5G = -3;
  3112. out = 0x16A; // -3 dB
  3113. } else if (swingA == 0x10) {
  3114. if (Band == BAND_ON_2_4G)
  3115. pRFCalibrateInfo->BBSwingDiff2G = -6;
  3116. else
  3117. pRFCalibrateInfo->BBSwingDiff5G = -6;
  3118. out = 0x101; // -6 dB
  3119. } else if (swingA == 0x11) {
  3120. if (Band == BAND_ON_2_4G)
  3121. pRFCalibrateInfo->BBSwingDiff2G = -9;
  3122. else
  3123. pRFCalibrateInfo->BBSwingDiff5G = -9;
  3124. out = 0x0B6; // -9 dB
  3125. }
  3126. //3 Path-B
  3127. if (swingB == 0x00) {
  3128. if (Band == BAND_ON_2_4G)
  3129. pRFCalibrateInfo->BBSwingDiff2G = 0;
  3130. else
  3131. pRFCalibrateInfo->BBSwingDiff5G = 0;
  3132. out = 0x200; // 0 dB
  3133. } else if (swingB == 0x01) {
  3134. if (Band == BAND_ON_2_4G)
  3135. pRFCalibrateInfo->BBSwingDiff2G = -3;
  3136. else
  3137. pRFCalibrateInfo->BBSwingDiff5G = -3;
  3138. out = 0x16A; // -3 dB
  3139. } else if (swingB == 0x10) {
  3140. if (Band == BAND_ON_2_4G)
  3141. pRFCalibrateInfo->BBSwingDiff2G = -6;
  3142. else
  3143. pRFCalibrateInfo->BBSwingDiff5G = -6;
  3144. out = 0x101; // -6 dB
  3145. } else if (swingB == 0x11) {
  3146. if (Band == BAND_ON_2_4G)
  3147. pRFCalibrateInfo->BBSwingDiff2G = -9;
  3148. else
  3149. pRFCalibrateInfo->BBSwingDiff5G = -9;
  3150. out = 0x0B6; // -9 dB
  3151. }
  3152. }
  3153. //DBG_871X("<=== PHY_GetTxBBSwing_8812A, out = 0x%X\n", out);
  3154. return out;
  3155. }
  3156. VOID
  3157. phy_SetRFEReg8812(
  3158. IN PADAPTER Adapter,
  3159. IN u8 Band
  3160. )
  3161. {
  3162. u1Byte u1tmp = 0;
  3163. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  3164. if(Band == BAND_ON_2_4G)
  3165. {
  3166. switch(pHalData->RFEType){
  3167. case 0: case 1: case 2:
  3168. PHY_SetBBReg(Adapter, rA_RFE_Pinmux_Jaguar,bMaskDWord, 0x77777777);
  3169. PHY_SetBBReg(Adapter, rB_RFE_Pinmux_Jaguar,bMaskDWord, 0x77777777);
  3170. PHY_SetBBReg(Adapter, rA_RFE_Inv_Jaguar,bMask_RFEInv_Jaguar, 0x000);
  3171. PHY_SetBBReg(Adapter, rB_RFE_Inv_Jaguar,bMask_RFEInv_Jaguar, 0x000);
  3172. break;
  3173. case 3:
  3174. PHY_SetBBReg(Adapter, rA_RFE_Pinmux_Jaguar,bMaskDWord, 0x54337770);
  3175. PHY_SetBBReg(Adapter, rB_RFE_Pinmux_Jaguar,bMaskDWord, 0x54337770);
  3176. PHY_SetBBReg(Adapter, rA_RFE_Inv_Jaguar,bMask_RFEInv_Jaguar, 0x010);
  3177. PHY_SetBBReg(Adapter, rB_RFE_Inv_Jaguar,bMask_RFEInv_Jaguar, 0x010);
  3178. PHY_SetBBReg(Adapter, r_ANTSEL_SW_Jaguar,0x00000303, 0x1);
  3179. break;
  3180. case 4:
  3181. PHY_SetBBReg(Adapter, rA_RFE_Pinmux_Jaguar,bMaskDWord, 0x77777777);
  3182. PHY_SetBBReg(Adapter, rB_RFE_Pinmux_Jaguar,bMaskDWord, 0x77777777);
  3183. PHY_SetBBReg(Adapter, rA_RFE_Inv_Jaguar,bMask_RFEInv_Jaguar, 0x001);
  3184. PHY_SetBBReg(Adapter, rB_RFE_Inv_Jaguar,bMask_RFEInv_Jaguar, 0x001);
  3185. break;
  3186. case 5:
  3187. //if(BT_IsBtExist(Adapter))
  3188. {
  3189. //rtw_write16(Adapter, rA_RFE_Pinmux_Jaguar, 0x7777);
  3190. rtw_write8(Adapter, rA_RFE_Pinmux_Jaguar+2, 0x77);
  3191. }
  3192. //else
  3193. //PHY_SetBBReg(Adapter, rA_RFE_Pinmux_Jaguar,bMaskDWord, 0x77777777);
  3194. PHY_SetBBReg(Adapter, rB_RFE_Pinmux_Jaguar,bMaskDWord, 0x77777777);
  3195. //if(BT_IsBtExist(Adapter))
  3196. {
  3197. //u1tmp = rtw_read8(Adapter, rA_RFE_Inv_Jaguar+2);
  3198. //rtw_write8(Adapter, rA_RFE_Inv_Jaguar+2, (u1tmp &0x0f));
  3199. u1tmp = rtw_read8(Adapter, rA_RFE_Inv_Jaguar+3);
  3200. rtw_write8(Adapter, rA_RFE_Inv_Jaguar+3, (u1tmp &= ~BIT0));
  3201. }
  3202. //else
  3203. //PHY_SetBBReg(Adapter, rA_RFE_Inv_Jaguar, bMask_RFEInv_Jaguar, 0x000);
  3204. PHY_SetBBReg(Adapter, rB_RFE_Inv_Jaguar, bMask_RFEInv_Jaguar, 0x000);
  3205. break;
  3206. default:
  3207. break;
  3208. }
  3209. }
  3210. else
  3211. {
  3212. switch(pHalData->RFEType){
  3213. case 0:
  3214. PHY_SetBBReg(Adapter, rA_RFE_Pinmux_Jaguar,bMaskDWord, 0x77337717);
  3215. PHY_SetBBReg(Adapter, rB_RFE_Pinmux_Jaguar,bMaskDWord, 0x77337717);
  3216. PHY_SetBBReg(Adapter, rA_RFE_Inv_Jaguar,bMask_RFEInv_Jaguar, 0x010);
  3217. PHY_SetBBReg(Adapter, rB_RFE_Inv_Jaguar,bMask_RFEInv_Jaguar, 0x010);
  3218. break;
  3219. case 1:
  3220. PHY_SetBBReg(Adapter, rA_RFE_Pinmux_Jaguar,bMaskDWord, 0x77337717);
  3221. PHY_SetBBReg(Adapter, rB_RFE_Pinmux_Jaguar,bMaskDWord, 0x77337717);
  3222. PHY_SetBBReg(Adapter, rA_RFE_Inv_Jaguar,bMask_RFEInv_Jaguar, 0x000);
  3223. PHY_SetBBReg(Adapter, rB_RFE_Inv_Jaguar,bMask_RFEInv_Jaguar, 0x000);
  3224. break;
  3225. case 2: case 4:
  3226. PHY_SetBBReg(Adapter, rA_RFE_Pinmux_Jaguar,bMaskDWord, 0x77337777);
  3227. PHY_SetBBReg(Adapter, rB_RFE_Pinmux_Jaguar,bMaskDWord, 0x77337777);
  3228. PHY_SetBBReg(Adapter, rA_RFE_Inv_Jaguar,bMask_RFEInv_Jaguar, 0x010);
  3229. PHY_SetBBReg(Adapter, rB_RFE_Inv_Jaguar,bMask_RFEInv_Jaguar, 0x010);
  3230. break;
  3231. case 3:
  3232. PHY_SetBBReg(Adapter, rA_RFE_Pinmux_Jaguar,bMaskDWord, 0x54337717);
  3233. PHY_SetBBReg(Adapter, rB_RFE_Pinmux_Jaguar,bMaskDWord, 0x54337717);
  3234. PHY_SetBBReg(Adapter, rA_RFE_Inv_Jaguar,bMask_RFEInv_Jaguar, 0x010);
  3235. PHY_SetBBReg(Adapter, rB_RFE_Inv_Jaguar,bMask_RFEInv_Jaguar, 0x010);
  3236. PHY_SetBBReg(Adapter, r_ANTSEL_SW_Jaguar,0x00000303, 0x1);
  3237. break;
  3238. case 5:
  3239. //if(BT_IsBtExist(Adapter))
  3240. {
  3241. //rtw_write16(Adapter, rA_RFE_Pinmux_Jaguar, 0x7777);
  3242. if(pHalData->ExternalPA_5G)
  3243. PlatformEFIOWrite1Byte(Adapter, rA_RFE_Pinmux_Jaguar+2, 0x33);
  3244. else
  3245. PlatformEFIOWrite1Byte(Adapter, rA_RFE_Pinmux_Jaguar+2, 0x73);
  3246. }
  3247. #if 0
  3248. else
  3249. {
  3250. if (pHalData->ExternalPA_5G)
  3251. PHY_SetBBReg(Adapter, rA_RFE_Pinmux_Jaguar,bMaskDWord, 0x77337777);
  3252. else
  3253. PHY_SetBBReg(Adapter, rA_RFE_Pinmux_Jaguar,bMaskDWord, 0x77737777);
  3254. }
  3255. #endif
  3256. if (pHalData->ExternalPA_5G)
  3257. PHY_SetBBReg(Adapter, rB_RFE_Pinmux_Jaguar,bMaskDWord, 0x77337777);
  3258. else
  3259. PHY_SetBBReg(Adapter, rB_RFE_Pinmux_Jaguar,bMaskDWord, 0x77737777);
  3260. //if(BT_IsBtExist(Adapter))
  3261. {
  3262. //u1tmp = rtw_read8(Adapter, rA_RFE_Inv_Jaguar+2);
  3263. //rtw_write8(Adapter, rA_RFE_Inv_Jaguar+2, (u1tmp &0x0f));
  3264. u1tmp = rtw_read8(Adapter, rA_RFE_Inv_Jaguar+3);
  3265. rtw_write8(Adapter, rA_RFE_Inv_Jaguar+3, (u1tmp |= BIT0));
  3266. }
  3267. //else
  3268. //PHY_SetBBReg(Adapter, rA_RFE_Inv_Jaguar, bMask_RFEInv_Jaguar, 0x010);
  3269. PHY_SetBBReg(Adapter, rB_RFE_Inv_Jaguar, bMask_RFEInv_Jaguar, 0x010);
  3270. break;
  3271. default:
  3272. break;
  3273. }
  3274. }
  3275. }
  3276. s32
  3277. PHY_SwitchWirelessBand8812(
  3278. IN PADAPTER Adapter,
  3279. IN u8 Band
  3280. )
  3281. {
  3282. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  3283. u8 currentBand = pHalData->CurrentBandType;
  3284. //DBG_871X("==>PHY_SwitchWirelessBand8812() %s\n", ((Band==0)?"2.4G":"5G"));
  3285. pHalData->CurrentBandType =(BAND_TYPE)Band;
  3286. if(Band == BAND_ON_2_4G)
  3287. {// 2.4G band
  3288. // STOP Tx/Rx
  3289. PHY_SetBBReg(Adapter, rOFDMCCKEN_Jaguar, bOFDMEN_Jaguar|bCCKEN_Jaguar, 0x00);
  3290. if (IS_HARDWARE_TYPE_8821(Adapter))
  3291. {
  3292. // Turn off RF PA and LNA
  3293. PHY_SetBBReg(Adapter, rA_RFE_Pinmux_Jaguar, 0xF000, 0x7); // 0xCB0[15:12] = 0x7 (LNA_On)
  3294. PHY_SetBBReg(Adapter, rA_RFE_Pinmux_Jaguar, 0xF0, 0x7); // 0xCB0[7:4] = 0x7 (PAPE_A)
  3295. }
  3296. // AGC table select
  3297. if(IS_VENDOR_8821A_MP_CHIP(Adapter))
  3298. PHY_SetBBReg(Adapter, rA_TxScale_Jaguar, 0xF00, 0); // 0xC1C[11:8] = 0
  3299. else
  3300. PHY_SetBBReg(Adapter, rAGC_table_Jaguar, 0x3, 0);
  3301. if(IS_VENDOR_8812A_TEST_CHIP(Adapter))
  3302. {
  3303. // r_select_5G for path_A/B
  3304. PHY_SetBBReg(Adapter, rA_RFE_Jaguar, BIT12, 0x0);
  3305. PHY_SetBBReg(Adapter, rB_RFE_Jaguar, BIT12, 0x0);
  3306. // LANON (5G uses external LNA)
  3307. PHY_SetBBReg(Adapter, rA_RFE_Jaguar, BIT15, 0x1);
  3308. PHY_SetBBReg(Adapter, rB_RFE_Jaguar, BIT15, 0x1);
  3309. }
  3310. else if(IS_VENDOR_8812A_MP_CHIP(Adapter))
  3311. {
  3312. if(GetRegbENRFEType(Adapter))
  3313. phy_SetRFEReg8812(Adapter, Band);
  3314. else
  3315. {
  3316. // PAPE_A (bypass RFE module in 2G)
  3317. PHY_SetBBReg(Adapter, rA_RFE_Pinmux_Jaguar, 0x000000F0, 0x7);
  3318. PHY_SetBBReg(Adapter, rB_RFE_Pinmux_Jaguar, 0x000000F0, 0x7);
  3319. // PAPE_G (bypass RFE module in 5G)
  3320. if (pHalData->ExternalPA_2G) {
  3321. PHY_SetBBReg(Adapter, rA_RFE_Pinmux_Jaguar, 0x0000000F, 0x0);
  3322. PHY_SetBBReg(Adapter, rB_RFE_Pinmux_Jaguar, 0x0000000F, 0x0);
  3323. } else {
  3324. PHY_SetBBReg(Adapter, rA_RFE_Pinmux_Jaguar, 0x0000000F, 0x7);
  3325. PHY_SetBBReg(Adapter, rB_RFE_Pinmux_Jaguar, 0x0000000F, 0x7);
  3326. }
  3327. // TRSW bypass RFE moudle in 2G
  3328. if (pHalData->ExternalLNA_2G) {
  3329. PHY_SetBBReg(Adapter, rA_RFE_Pinmux_Jaguar, bMaskByte2, 0x54);
  3330. PHY_SetBBReg(Adapter, rB_RFE_Pinmux_Jaguar, bMaskByte2, 0x54);
  3331. } else {
  3332. PHY_SetBBReg(Adapter, rA_RFE_Pinmux_Jaguar, bMaskByte2, 0x77);
  3333. PHY_SetBBReg(Adapter, rB_RFE_Pinmux_Jaguar, bMaskByte2, 0x77);
  3334. }
  3335. }
  3336. }
  3337. update_tx_basic_rate(Adapter, WIRELESS_11BG);
  3338. // cck_enable
  3339. PHY_SetBBReg(Adapter, rOFDMCCKEN_Jaguar, bOFDMEN_Jaguar|bCCKEN_Jaguar, 0x3);
  3340. // SYN Setting
  3341. if(IS_VENDOR_8812A_TEST_CHIP(Adapter))
  3342. {
  3343. PHY_SetRFReg(Adapter, RF_PATH_A, 0xEF, bLSSIWrite_data_Jaguar, 0x40000);
  3344. PHY_SetRFReg(Adapter, RF_PATH_A, 0x3E, bLSSIWrite_data_Jaguar, 0x00000);
  3345. PHY_SetRFReg(Adapter, RF_PATH_A, 0x3F, bLSSIWrite_data_Jaguar, 0x0001c);
  3346. PHY_SetRFReg(Adapter, RF_PATH_A, 0xEF, bLSSIWrite_data_Jaguar, 0x00000);
  3347. PHY_SetRFReg(Adapter, RF_PATH_A, 0xB5, bLSSIWrite_data_Jaguar, 0x16BFF);
  3348. }
  3349. // CCK_CHECK_en
  3350. rtw_write8(Adapter, REG_CCK_CHECK_8812, 0x0);
  3351. }
  3352. else //5G band
  3353. {
  3354. u16 count = 0, reg41A = 0;
  3355. if (IS_HARDWARE_TYPE_8821(Adapter))
  3356. {
  3357. PHY_SetBBReg(Adapter, rA_RFE_Pinmux_Jaguar, 0xF000, 0x5); // 0xCB0[15:12] = 0x5 (LNA_On)
  3358. PHY_SetBBReg(Adapter, rA_RFE_Pinmux_Jaguar, 0xF0, 0x4); // 0xCB0[7:4] = 0x4 (PAPE_A)
  3359. }
  3360. // CCK_CHECK_en
  3361. rtw_write8(Adapter, REG_CCK_CHECK_8812, 0x80);
  3362. count = 0;
  3363. reg41A = rtw_read16(Adapter, REG_TXPKT_EMPTY);
  3364. //DBG_871X("Reg41A value %d", reg41A);
  3365. reg41A &= 0x30;
  3366. while((reg41A!= 0x30) && (count < 50))
  3367. {
  3368. rtw_udelay_os(50);
  3369. //DBG_871X("Delay 50us \n");
  3370. reg41A = rtw_read16(Adapter, REG_TXPKT_EMPTY);
  3371. reg41A &= 0x30;
  3372. count++;
  3373. //DBG_871X("Reg41A value %d", reg41A);
  3374. }
  3375. if(count != 0)
  3376. DBG_871X("PHY_SwitchWirelessBand8812(): Switch to 5G Band. Count = %d reg41A=0x%x\n", count, reg41A);
  3377. // STOP Tx/Rx
  3378. PHY_SetBBReg(Adapter, rOFDMCCKEN_Jaguar, bOFDMEN_Jaguar|bCCKEN_Jaguar, 0x00);
  3379. // AGC table select
  3380. if (IS_VENDOR_8821A_MP_CHIP(Adapter))
  3381. PHY_SetBBReg(Adapter, rA_TxScale_Jaguar, 0xF00, 1); // 0xC1C[11:8] = 1
  3382. else
  3383. PHY_SetBBReg(Adapter, rAGC_table_Jaguar, 0x3, 1);
  3384. if(IS_VENDOR_8812A_TEST_CHIP(Adapter))
  3385. {
  3386. // r_select_5G for path_A/B
  3387. PHY_SetBBReg(Adapter, rA_RFE_Jaguar, BIT12, 0x1);
  3388. PHY_SetBBReg(Adapter, rB_RFE_Jaguar, BIT12, 0x1);
  3389. // LANON (5G uses external LNA)
  3390. PHY_SetBBReg(Adapter, rA_RFE_Jaguar, BIT15, 0x0);
  3391. PHY_SetBBReg(Adapter, rB_RFE_Jaguar, BIT15, 0x0);
  3392. }
  3393. else if(IS_VENDOR_8812A_MP_CHIP(Adapter))
  3394. {
  3395. if(GetRegbENRFEType(Adapter))
  3396. phy_SetRFEReg8812(Adapter, Band);
  3397. else
  3398. {
  3399. // PAPE_A (bypass RFE module in 2G)
  3400. if (pHalData->ExternalPA_5G) {
  3401. PHY_SetBBReg(Adapter, rA_RFE_Pinmux_Jaguar, 0x000000F0, 0x1);
  3402. PHY_SetBBReg(Adapter, rB_RFE_Pinmux_Jaguar, 0x000000F0, 0x1);
  3403. } else {
  3404. PHY_SetBBReg(Adapter, rA_RFE_Pinmux_Jaguar, 0x000000F0, 0x0);
  3405. PHY_SetBBReg(Adapter, rB_RFE_Pinmux_Jaguar, 0x000000F0, 0x0);
  3406. }
  3407. // PAPE_G (bypass RFE module in 5G)
  3408. PHY_SetBBReg(Adapter, rA_RFE_Pinmux_Jaguar, 0x0000000F, 0x7);
  3409. PHY_SetBBReg(Adapter, rB_RFE_Pinmux_Jaguar, 0x0000000F, 0x7);
  3410. // TRSW bypass RFE moudle in 2G
  3411. if (pHalData->ExternalLNA_5G) {
  3412. PHY_SetBBReg(Adapter, rA_RFE_Pinmux_Jaguar, bMaskByte2, 0x54);
  3413. PHY_SetBBReg(Adapter, rB_RFE_Pinmux_Jaguar, bMaskByte2, 0x54);
  3414. } else {
  3415. PHY_SetBBReg(Adapter, rA_RFE_Pinmux_Jaguar, bMaskByte2, 0x77);
  3416. PHY_SetBBReg(Adapter, rB_RFE_Pinmux_Jaguar, bMaskByte2, 0x77);
  3417. }
  3418. }
  3419. }
  3420. //avoid using cck rate in 5G band
  3421. // Set RRSR rate table.
  3422. update_tx_basic_rate(Adapter, WIRELESS_11A);
  3423. // cck_enable
  3424. PHY_SetBBReg(Adapter, rOFDMCCKEN_Jaguar, bOFDMEN_Jaguar|bCCKEN_Jaguar, 0x2);
  3425. // SYN Setting
  3426. if(IS_VENDOR_8812A_TEST_CHIP(Adapter))
  3427. {
  3428. PHY_SetRFReg(Adapter, RF_PATH_A, 0xEF, bLSSIWrite_data_Jaguar, 0x40000);
  3429. PHY_SetRFReg(Adapter, RF_PATH_A, 0x3E, bLSSIWrite_data_Jaguar, 0x00000);
  3430. PHY_SetRFReg(Adapter, RF_PATH_A, 0x3F, bLSSIWrite_data_Jaguar, 0x00017);
  3431. PHY_SetRFReg(Adapter, RF_PATH_A, 0xEF, bLSSIWrite_data_Jaguar, 0x00000);
  3432. PHY_SetRFReg(Adapter, RF_PATH_A, 0xB5, bLSSIWrite_data_Jaguar, 0x04BFF);
  3433. }
  3434. //DBG_871X("==>PHY_SwitchWirelessBand8812() BAND_ON_5G settings OFDM index 0x%x\n", pHalData->OFDM_index[RF_PATH_A]);
  3435. }
  3436. //<20120903, Kordan> Tx BB swing setting for RL6286, asked by Ynlin.
  3437. if (IS_NORMAL_CHIP(pHalData->VersionID) || IS_HARDWARE_TYPE_8821(Adapter))
  3438. {
  3439. s8 BBDiffBetweenBand = 0;
  3440. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(GetDefaultAdapter(Adapter));
  3441. PDM_ODM_T pDM_Odm = &pHalData->odmpriv;
  3442. PODM_RF_CAL_T pRFCalibrateInfo = &(pDM_Odm->RFCalibrateInfo);
  3443. PHY_SetBBReg(Adapter, rA_TxScale_Jaguar, 0xFFE00000,
  3444. PHY_GetTxBBSwing_8812A(Adapter, (BAND_TYPE)Band, ODM_RF_PATH_A)); // 0xC1C[31:21]
  3445. PHY_SetBBReg(Adapter, rB_TxScale_Jaguar, 0xFFE00000,
  3446. PHY_GetTxBBSwing_8812A(Adapter, (BAND_TYPE)Band, ODM_RF_PATH_B)); // 0xE1C[31:21]
  3447. // <20121005, Kordan> When TxPowerTrack is ON, we should take care of the change of BB swing.
  3448. // That is, reset all info to trigger Tx power tracking.
  3449. {
  3450. if (Band != currentBand)
  3451. {
  3452. BBDiffBetweenBand = (pRFCalibrateInfo->BBSwingDiff2G - pRFCalibrateInfo->BBSwingDiff5G);
  3453. BBDiffBetweenBand = (Band == BAND_ON_2_4G) ? BBDiffBetweenBand : (-1 * BBDiffBetweenBand);
  3454. pDM_Odm->DefaultOfdmIndex += BBDiffBetweenBand*2;
  3455. }
  3456. ODM_ClearTxPowerTrackingState(pDM_Odm);
  3457. }
  3458. }
  3459. //DBG_871X("<==PHY_SwitchWirelessBand8812():Switch Band OK.\n");
  3460. return _SUCCESS;
  3461. }
  3462. BOOLEAN
  3463. phy_SwBand8812(
  3464. IN PADAPTER pAdapter,
  3465. IN u8 channelToSW
  3466. )
  3467. {
  3468. u8 u1Btmp;
  3469. BOOLEAN ret_value = _TRUE;
  3470. u8 Band = BAND_ON_5G, BandToSW;
  3471. u1Btmp = rtw_read8(pAdapter, REG_CCK_CHECK_8812);
  3472. if(u1Btmp & BIT7)
  3473. Band = BAND_ON_5G;
  3474. else
  3475. Band = BAND_ON_2_4G;
  3476. // Use current channel to judge Band Type and switch Band if need.
  3477. if(channelToSW > 14)
  3478. {
  3479. BandToSW = BAND_ON_5G;
  3480. }
  3481. else
  3482. {
  3483. BandToSW = BAND_ON_2_4G;
  3484. }
  3485. if(BandToSW != Band)
  3486. PHY_SwitchWirelessBand8812(pAdapter,BandToSW);
  3487. return ret_value;
  3488. }
  3489. u8
  3490. phy_GetSecondaryChnl_8812(
  3491. IN PADAPTER Adapter
  3492. )
  3493. {
  3494. u8 SCSettingOf40 = 0, SCSettingOf20 = 0;
  3495. PHAL_DATA_TYPE pHalData = GET_HAL_DATA(Adapter);
  3496. //DBG_871X("SCMapping: VHT Case: pHalData->CurrentChannelBW %d, pHalData->nCur80MhzPrimeSC %d, pHalData->nCur40MhzPrimeSC %d \n",pHalData->CurrentChannelBW,pHalData->nCur80MhzPrimeSC,pHalData->nCur40MhzPrimeSC);
  3497. if(pHalData->CurrentChannelBW== CHANNEL_WIDTH_80)
  3498. {
  3499. if(pHalData->nCur80MhzPrimeSC == HAL_PRIME_CHNL_OFFSET_LOWER)
  3500. SCSettingOf40 = VHT_DATA_SC_40_LOWER_OF_80MHZ;
  3501. else if(pHalData->nCur80MhzPrimeSC == HAL_PRIME_CHNL_OFFSET_UPPER)
  3502. SCSettingOf40 = VHT_DATA_SC_40_UPPER_OF_80MHZ;
  3503. else
  3504. DBG_871X("SCMapping: Not Correct Primary40MHz Setting \n");
  3505. if((pHalData->nCur40MhzPrimeSC == HAL_PRIME_CHNL_OFFSET_LOWER) && (pHalData->nCur80MhzPrimeSC == HAL_PRIME_CHNL_OFFSET_LOWER))
  3506. SCSettingOf20 = VHT_DATA_SC_20_LOWEST_OF_80MHZ;
  3507. else if((pHalData->nCur40MhzPrimeSC == HAL_PRIME_CHNL_OFFSET_UPPER) && (pHalData->nCur80MhzPrimeSC == HAL_PRIME_CHNL_OFFSET_LOWER))
  3508. SCSettingOf20 = VHT_DATA_SC_20_LOWER_OF_80MHZ;
  3509. else if((pHalData->nCur40MhzPrimeSC == HAL_PRIME_CHNL_OFFSET_LOWER) && (pHalData->nCur80MhzPrimeSC == HAL_PRIME_CHNL_OFFSET_UPPER))
  3510. SCSettingOf20 = VHT_DATA_SC_20_UPPER_OF_80MHZ;
  3511. else if((pHalData->nCur40MhzPrimeSC == HAL_PRIME_CHNL_OFFSET_UPPER) && (pHalData->nCur80MhzPrimeSC == HAL_PRIME_CHNL_OFFSET_UPPER))
  3512. SCSettingOf20 = VHT_DATA_SC_20_UPPERST_OF_80MHZ;
  3513. else
  3514. DBG_871X("SCMapping: Not Correct Primary40MHz Setting \n");
  3515. }
  3516. else if(pHalData->CurrentChannelBW == CHANNEL_WIDTH_40)
  3517. {
  3518. //DBG_871X("SCMapping: VHT Case: pHalData->CurrentChannelBW %d, pHalData->nCur40MhzPrimeSC %d \n",pHalData->CurrentChannelBW,pHalData->nCur40MhzPrimeSC);
  3519. if(pHalData->nCur40MhzPrimeSC == HAL_PRIME_CHNL_OFFSET_UPPER)
  3520. SCSettingOf20 = VHT_DATA_SC_20_UPPER_OF_80MHZ;
  3521. else if(pHalData->nCur40MhzPrimeSC == HAL_PRIME_CHNL_OFFSET_LOWER)
  3522. SCSettingOf20 = VHT_DATA_SC_20_LOWER_OF_80MHZ;
  3523. else
  3524. DBG_871X("SCMapping: Not Correct Primary40MHz Setting \n");
  3525. }
  3526. //DBG_871X("SCMapping: SC Value %x \n", ( (SCSettingOf40 << 4) | SCSettingOf20));
  3527. return ( (SCSettingOf40 << 4) | SCSettingOf20);
  3528. }
  3529. VOID
  3530. phy_SetRegBW_8812(
  3531. IN PADAPTER Adapter,
  3532. CHANNEL_WIDTH CurrentBW
  3533. )
  3534. {
  3535. u16 RegRfMod_BW, u2tmp = 0;
  3536. RegRfMod_BW = rtw_read16(Adapter, REG_WMAC_TRXPTCL_CTL);
  3537. switch(CurrentBW)
  3538. {
  3539. case CHANNEL_WIDTH_20:
  3540. rtw_write16(Adapter, REG_WMAC_TRXPTCL_CTL, (RegRfMod_BW & 0xFE7F)); // BIT 7 = 0, BIT 8 = 0
  3541. break;
  3542. case CHANNEL_WIDTH_40:
  3543. u2tmp = RegRfMod_BW | BIT7;
  3544. rtw_write16(Adapter, REG_WMAC_TRXPTCL_CTL, (u2tmp & 0xFEFF)); // BIT 7 = 1, BIT 8 = 0
  3545. break;
  3546. case CHANNEL_WIDTH_80:
  3547. u2tmp = RegRfMod_BW | BIT8;
  3548. rtw_write16(Adapter, REG_WMAC_TRXPTCL_CTL, (u2tmp & 0xFF7F)); // BIT 7 = 0, BIT 8 = 1
  3549. break;
  3550. default:
  3551. DBG_871X("phy_PostSetBWMode8812(): unknown Bandwidth: %#X\n",CurrentBW);
  3552. break;
  3553. }
  3554. }
  3555. void
  3556. phy_FixSpur_8812A(
  3557. IN PADAPTER pAdapter,
  3558. IN CHANNEL_WIDTH Bandwidth,
  3559. IN u1Byte Channel
  3560. )
  3561. {
  3562. // C cut Item12 ADC FIFO CLOCK
  3563. if(IS_VENDOR_8812A_C_CUT(pAdapter))
  3564. {
  3565. if(Bandwidth == CHANNEL_WIDTH_40 && Channel == 11)
  3566. PHY_SetBBReg(pAdapter, rRFMOD_Jaguar, 0xC00, 0x3) ; // 0x8AC[11:10] = 2'b11
  3567. else
  3568. PHY_SetBBReg(pAdapter, rRFMOD_Jaguar, 0xC00, 0x2); // 0x8AC[11:10] = 2'b10
  3569. // <20120914, Kordan> A workarould to resolve 2480Mhz spur by setting ADC clock as 160M. (Asked by Binson)
  3570. if (Bandwidth == CHANNEL_WIDTH_20 &&
  3571. (Channel == 13 || Channel == 14)) {
  3572. PHY_SetBBReg(pAdapter, rRFMOD_Jaguar, 0x300, 0x3); // 0x8AC[9:8] = 2'b11
  3573. PHY_SetBBReg(pAdapter, rADC_Buf_Clk_Jaguar, BIT30, 1); // 0x8C4[30] = 1
  3574. } else if (Bandwidth == CHANNEL_WIDTH_40 &&
  3575. Channel == 11) {
  3576. PHY_SetBBReg(pAdapter, rADC_Buf_Clk_Jaguar, BIT30, 1); // 0x8C4[30] = 1
  3577. } else if (Bandwidth != CHANNEL_WIDTH_80) {
  3578. PHY_SetBBReg(pAdapter, rRFMOD_Jaguar, 0x300, 0x2); // 0x8AC[9:8] = 2'b10
  3579. PHY_SetBBReg(pAdapter, rADC_Buf_Clk_Jaguar, BIT30, 0); // 0x8C4[30] = 0
  3580. }
  3581. }
  3582. else if (IS_HARDWARE_TYPE_8812(pAdapter))
  3583. {
  3584. // <20120914, Kordan> A workarould to resolve 2480Mhz spur by setting ADC clock as 160M. (Asked by Binson)
  3585. if (Bandwidth == CHANNEL_WIDTH_20 &&
  3586. (Channel == 13 || Channel == 14))
  3587. PHY_SetBBReg(pAdapter, rRFMOD_Jaguar, 0x300, 0x3); // 0x8AC[9:8] = 11
  3588. else if (Channel <= 14) // 2.4G only
  3589. PHY_SetBBReg(pAdapter, rRFMOD_Jaguar, 0x300, 0x2); // 0x8AC[9:8] = 10
  3590. }
  3591. }
  3592. VOID
  3593. phy_PostSetBwMode8812(
  3594. IN PADAPTER Adapter
  3595. )
  3596. {
  3597. u8 SubChnlNum = 0;
  3598. u8 L1pkVal = 0;
  3599. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  3600. //3 Set Reg668 Reg440 BW
  3601. phy_SetRegBW_8812(Adapter, pHalData->CurrentChannelBW);
  3602. //3 Set Reg483
  3603. SubChnlNum = phy_GetSecondaryChnl_8812(Adapter);
  3604. rtw_write8(Adapter, REG_DATA_SC_8812, SubChnlNum);
  3605. if(pHalData->rf_chip == RF_PSEUDO_11N)
  3606. {
  3607. DBG_871X("phy_PostSetBwMode8812: return for PSEUDO \n");
  3608. return;
  3609. }
  3610. //DBG_871X("[BW:CHNL], phy_PostSetBwMode8812(), set BW=%s !!\n", GLBwSrc[pHalData->CurrentChannelBW]);
  3611. //3 Set Reg848 Reg864 Reg8AC Reg8C4 RegA00
  3612. switch(pHalData->CurrentChannelBW)
  3613. {
  3614. case CHANNEL_WIDTH_20:
  3615. PHY_SetBBReg(Adapter, rRFMOD_Jaguar, 0x003003C3, 0x00300200); // 0x8ac[21,20,9:6,1,0]=8'b11100000
  3616. PHY_SetBBReg(Adapter, rADC_Buf_Clk_Jaguar, BIT30, 0); // 0x8c4[30] = 1'b0
  3617. PHY_SetBBReg(Adapter, rFPGA0_XB_RFInterfaceOE, 0x001C0000, 4); // 0x864[20:18] = 3'b4
  3618. if(pHalData->rf_type == RF_2T2R)
  3619. PHY_SetBBReg(Adapter, rL1PeakTH_Jaguar, 0x03C00000, 7); // 2R 0x848[25:22] = 0x7
  3620. else
  3621. PHY_SetBBReg(Adapter, rL1PeakTH_Jaguar, 0x03C00000, 8); // 1R 0x848[25:22] = 0x8
  3622. break;
  3623. case CHANNEL_WIDTH_40:
  3624. PHY_SetBBReg(Adapter, rRFMOD_Jaguar, 0x003003C3, 0x00300201); // 0x8ac[21,20,9:6,1,0]=8'b11100000
  3625. PHY_SetBBReg(Adapter, rADC_Buf_Clk_Jaguar, BIT30, 0); // 0x8c4[30] = 1'b0
  3626. PHY_SetBBReg(Adapter, rRFMOD_Jaguar, 0x3C, SubChnlNum);
  3627. PHY_SetBBReg(Adapter, rCCAonSec_Jaguar, 0xf0000000, SubChnlNum);
  3628. PHY_SetBBReg(Adapter, rFPGA0_XB_RFInterfaceOE, 0x001C0000, 2); // 0x864[20:18] = 3'b2
  3629. if(pHalData->Reg837 & BIT2)
  3630. L1pkVal = 6;
  3631. else
  3632. {
  3633. if(pHalData->rf_type == RF_2T2R)
  3634. L1pkVal = 7;
  3635. else
  3636. L1pkVal = 8;
  3637. }
  3638. PHY_SetBBReg(Adapter, rL1PeakTH_Jaguar, 0x03C00000, L1pkVal); // 0x848[25:22] = 0x6
  3639. if(SubChnlNum == VHT_DATA_SC_20_UPPER_OF_80MHZ)
  3640. PHY_SetBBReg(Adapter, rCCK_System_Jaguar, bCCK_System_Jaguar, 1);
  3641. else
  3642. PHY_SetBBReg(Adapter, rCCK_System_Jaguar, bCCK_System_Jaguar, 0);
  3643. break;
  3644. case CHANNEL_WIDTH_80:
  3645. PHY_SetBBReg(Adapter, rRFMOD_Jaguar, 0x003003C3, 0x00300202); // 0x8ac[21,20,9:6,1,0]=8'b11100010
  3646. PHY_SetBBReg(Adapter, rADC_Buf_Clk_Jaguar, BIT30, 1); // 0x8c4[30] = 1
  3647. PHY_SetBBReg(Adapter, rRFMOD_Jaguar, 0x3C, SubChnlNum);
  3648. PHY_SetBBReg(Adapter, rCCAonSec_Jaguar, 0xf0000000, SubChnlNum);
  3649. PHY_SetBBReg(Adapter, rFPGA0_XB_RFInterfaceOE, 0x001C0000, 2); // 0x864[20:18] = 3'b2
  3650. if(pHalData->Reg837 & BIT2)
  3651. L1pkVal = 5;
  3652. else
  3653. {
  3654. if(pHalData->rf_type == RF_2T2R)
  3655. L1pkVal = 6;
  3656. else
  3657. L1pkVal = 7;
  3658. }
  3659. PHY_SetBBReg(Adapter, rL1PeakTH_Jaguar, 0x03C00000, L1pkVal); // 0x848[25:22] = 0x5
  3660. break;
  3661. default:
  3662. DBG_871X("phy_PostSetBWMode8812(): unknown Bandwidth: %#X\n",pHalData->CurrentChannelBW);
  3663. break;
  3664. }
  3665. // <20121109, Kordan> A workaround for 8812A only.
  3666. phy_FixSpur_8812A(Adapter, pHalData->CurrentChannelBW, pHalData->CurrentChannel);
  3667. //DBG_871X("phy_PostSetBwMode8812(): Reg483: %x\n", rtw_read8(Adapter, 0x483));
  3668. //DBG_871X("phy_PostSetBwMode8812(): Reg668: %x\n", rtw_read32(Adapter, 0x668));
  3669. //DBG_871X("phy_PostSetBwMode8812(): Reg8AC: %x\n", PHY_QueryBBReg(Adapter, rRFMOD_Jaguar, 0xffffffff));
  3670. //3 Set RF related register
  3671. PHY_RF6052SetBandwidth8812(Adapter, pHalData->CurrentChannelBW);
  3672. }
  3673. //<20130207, Kordan> The variales initialized here are used in odm_LNAPowerControl().
  3674. VOID phy_InitRssiTRSW(
  3675. IN PADAPTER pAdapter
  3676. )
  3677. {
  3678. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(pAdapter);
  3679. PDM_ODM_T pDM_Odm = &pHalData->odmpriv;
  3680. u8 channel = pHalData->CurrentChannel;
  3681. if (pHalData->RFEType == 3){
  3682. if (channel <= 14) {
  3683. pDM_Odm->RSSI_TRSW_H = 70; // Unit: percentage(%)
  3684. pDM_Odm->RSSI_TRSW_iso = 25;
  3685. } else if (36 <= channel && channel <= 64) {
  3686. pDM_Odm->RSSI_TRSW_H = 70;
  3687. pDM_Odm->RSSI_TRSW_iso = 25;
  3688. } else if (100 <= channel && channel <= 144) {
  3689. pDM_Odm->RSSI_TRSW_H = 80;
  3690. pDM_Odm->RSSI_TRSW_iso = 35;
  3691. } else if (149 <= channel) {
  3692. pDM_Odm->RSSI_TRSW_H = 75;
  3693. pDM_Odm->RSSI_TRSW_iso = 30;
  3694. }
  3695. pDM_Odm->RSSI_TRSW_L = pDM_Odm->RSSI_TRSW_H - pDM_Odm->RSSI_TRSW_iso - 10;
  3696. }
  3697. }
  3698. VOID
  3699. phy_SwChnl8812(
  3700. IN PADAPTER pAdapter
  3701. )
  3702. {
  3703. u8 eRFPath = 0;
  3704. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(pAdapter);
  3705. u8 channelToSW = pHalData->CurrentChannel;
  3706. if (pAdapter->registrypriv.mp_mode == 0) {
  3707. if(phy_SwBand8812(pAdapter, channelToSW) == _FALSE)
  3708. {
  3709. DBG_871X("error Chnl %d !\n", channelToSW);
  3710. }
  3711. }
  3712. //<20130313, Kordan> Sample code to demonstrate how to configure AGC_TAB_DIFF.(Disabled by now)
  3713. #if 0
  3714. if (36 <= channelToSW && channelToSW <= 48)
  3715. AGC_DIFF_CONFIG(8812A,LB);
  3716. else if (50 <= channelToSW && channelToSW <= 64)
  3717. AGC_DIFF_CONFIG(8812A,MB);
  3718. else if (100 <= channelToSW && channelToSW <= 116)
  3719. AGC_DIFF_CONFIG(8812A,HB);
  3720. #endif
  3721. if(pHalData->rf_chip == RF_PSEUDO_11N)
  3722. {
  3723. DBG_871X("phy_SwChnl8812: return for PSEUDO \n");
  3724. return;
  3725. }
  3726. //DBG_871X("[BW:CHNL], phy_SwChnl8812(), switch to channel %d !!\n", channelToSW);
  3727. // fc_area
  3728. if (36 <= channelToSW && channelToSW <= 48)
  3729. PHY_SetBBReg(pAdapter, rFc_area_Jaguar, 0x1ffe0000, 0x494);
  3730. else if (50 <= channelToSW && channelToSW <= 64)
  3731. PHY_SetBBReg(pAdapter, rFc_area_Jaguar, 0x1ffe0000, 0x453);
  3732. else if (100 <= channelToSW && channelToSW <= 116)
  3733. PHY_SetBBReg(pAdapter, rFc_area_Jaguar, 0x1ffe0000, 0x452);
  3734. else if (118 <= channelToSW)
  3735. PHY_SetBBReg(pAdapter, rFc_area_Jaguar, 0x1ffe0000, 0x412);
  3736. else
  3737. PHY_SetBBReg(pAdapter, rFc_area_Jaguar, 0x1ffe0000, 0x96a);
  3738. for(eRFPath = 0; eRFPath < pHalData->NumTotalRFPath; eRFPath++)
  3739. {
  3740. // [2.4G] LC Tank
  3741. if(IS_VENDOR_8812A_TEST_CHIP(pAdapter))
  3742. {
  3743. if (1 <= channelToSW && channelToSW <= 7)
  3744. PHY_SetRFReg(pAdapter, eRFPath, RF_TxLCTank_Jaguar, bLSSIWrite_data_Jaguar, 0x0017e);
  3745. else if (8 <= channelToSW && channelToSW <= 14)
  3746. PHY_SetRFReg(pAdapter, eRFPath, RF_TxLCTank_Jaguar, bLSSIWrite_data_Jaguar, 0x0013e);
  3747. }
  3748. // RF_MOD_AG
  3749. if (36 <= channelToSW && channelToSW <= 64)
  3750. PHY_SetRFReg(pAdapter, eRFPath, RF_CHNLBW_Jaguar, BIT18|BIT17|BIT16|BIT9|BIT8, 0x101); //5'b00101);
  3751. else if (100 <= channelToSW && channelToSW <= 140)
  3752. PHY_SetRFReg(pAdapter, eRFPath, RF_CHNLBW_Jaguar, BIT18|BIT17|BIT16|BIT9|BIT8, 0x301); //5'b01101);
  3753. else if (140 < channelToSW)
  3754. PHY_SetRFReg(pAdapter, eRFPath, RF_CHNLBW_Jaguar, BIT18|BIT17|BIT16|BIT9|BIT8, 0x501); //5'b10101);
  3755. else
  3756. PHY_SetRFReg(pAdapter, eRFPath, RF_CHNLBW_Jaguar, BIT18|BIT17|BIT16|BIT9|BIT8, 0x000); //5'b00000);
  3757. // <20121109, Kordan> A workaround for 8812A only.
  3758. phy_FixSpur_8812A(pAdapter, pHalData->CurrentChannelBW, channelToSW);
  3759. PHY_SetRFReg(pAdapter, eRFPath, RF_CHNLBW_Jaguar, bMaskByte0, channelToSW);
  3760. // <20130104, Kordan> APK for MP chip is done on initialization from folder.
  3761. if (IS_HARDWARE_TYPE_8811AU(pAdapter) && ( !IS_NORMAL_CHIP(pHalData->VersionID)) && channelToSW > 14 )
  3762. {
  3763. // <20121116, Kordan> For better result of APK. Asked by AlexWang.
  3764. if (36 <= channelToSW && channelToSW <= 64)
  3765. PHY_SetRFReg(pAdapter, eRFPath, RF_APK_Jaguar, bRFRegOffsetMask, 0x710E7);
  3766. else if (100 <= channelToSW && channelToSW <= 140)
  3767. PHY_SetRFReg(pAdapter, eRFPath, RF_APK_Jaguar, bRFRegOffsetMask, 0x716E9);
  3768. else
  3769. PHY_SetRFReg(pAdapter, eRFPath, RF_APK_Jaguar, bRFRegOffsetMask, 0x714E9);
  3770. }
  3771. else if ((IS_HARDWARE_TYPE_8821E(pAdapter) || IS_HARDWARE_TYPE_8821S(pAdapter))
  3772. && channelToSW > 14)
  3773. {
  3774. // <20130111, Kordan> For better result of APK. Asked by Willson.
  3775. if (36 <= channelToSW && channelToSW <= 64)
  3776. PHY_SetRFReg(pAdapter, eRFPath, RF_APK_Jaguar, bRFRegOffsetMask, 0x714E9);
  3777. else if (100 <= channelToSW && channelToSW <= 140)
  3778. PHY_SetRFReg(pAdapter, eRFPath, RF_APK_Jaguar, bRFRegOffsetMask, 0x110E9);
  3779. else
  3780. PHY_SetRFReg(pAdapter, eRFPath, RF_APK_Jaguar, bRFRegOffsetMask, 0x714E9);
  3781. }
  3782. }
  3783. }
  3784. VOID
  3785. phy_SwChnlAndSetBwMode8812(
  3786. IN PADAPTER Adapter
  3787. )
  3788. {
  3789. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  3790. //DBG_871X("phy_SwChnlAndSetBwMode8812(): bSwChnl %d, bSetChnlBW %d \n", pHalData->bSwChnl, pHalData->bSetChnlBW);
  3791. if((Adapter->bDriverStopped) || (Adapter->bSurpriseRemoved))
  3792. {
  3793. return;
  3794. }
  3795. if(pHalData->bSwChnl)
  3796. {
  3797. phy_SwChnl8812(Adapter);
  3798. pHalData->bSwChnl = _FALSE;
  3799. }
  3800. if(pHalData->bSetChnlBW)
  3801. {
  3802. phy_PostSetBwMode8812(Adapter);
  3803. pHalData->bSetChnlBW = _FALSE;
  3804. }
  3805. ODM_ClearTxPowerTrackingState(&pHalData->odmpriv);
  3806. PHY_SetTxPowerLevel8812(Adapter, pHalData->CurrentChannel);
  3807. if(IS_HARDWARE_TYPE_8812(Adapter))
  3808. phy_InitRssiTRSW(Adapter);
  3809. if ( (pHalData->bNeedIQK == _TRUE)
  3810. #if (MP_DRIVER == 1)
  3811. || (Adapter->registrypriv.mp_mode == 1)
  3812. #endif
  3813. )
  3814. {
  3815. if(IS_HARDWARE_TYPE_8812(Adapter))
  3816. {
  3817. #if (RTL8812A_SUPPORT == 1)
  3818. PHY_IQCalibrate_8812A(Adapter, _FALSE);
  3819. #endif
  3820. }
  3821. else if(IS_HARDWARE_TYPE_8821(Adapter))
  3822. {
  3823. #if (RTL8821A_SUPPORT == 1)
  3824. PHY_IQCalibrate_8821A(Adapter, _FALSE);
  3825. #endif
  3826. }
  3827. pHalData->bNeedIQK = _FALSE;
  3828. }
  3829. }
  3830. VOID
  3831. PHY_HandleSwChnlAndSetBW8812(
  3832. IN PADAPTER Adapter,
  3833. IN BOOLEAN bSwitchChannel,
  3834. IN BOOLEAN bSetBandWidth,
  3835. IN u8 ChannelNum,
  3836. IN CHANNEL_WIDTH ChnlWidth,
  3837. IN u8 ChnlOffsetOf40MHz,
  3838. IN u8 ChnlOffsetOf80MHz,
  3839. IN u8 CenterFrequencyIndex1
  3840. )
  3841. {
  3842. PADAPTER pDefAdapter = GetDefaultAdapter(Adapter);
  3843. PHAL_DATA_TYPE pHalData = GET_HAL_DATA(pDefAdapter);
  3844. u8 tmpChannel = pHalData->CurrentChannel;
  3845. CHANNEL_WIDTH tmpBW= pHalData->CurrentChannelBW;
  3846. u8 tmpnCur40MhzPrimeSC = pHalData->nCur40MhzPrimeSC;
  3847. u8 tmpnCur80MhzPrimeSC = pHalData->nCur80MhzPrimeSC;
  3848. u8 tmpCenterFrequencyIndex1 =pHalData->CurrentCenterFrequencyIndex1;
  3849. struct mlme_ext_priv *pmlmeext = &Adapter->mlmeextpriv;
  3850. //DBG_871X("=> PHY_HandleSwChnlAndSetBW8812: bSwitchChannel %d, bSetBandWidth %d \n",bSwitchChannel,bSetBandWidth);
  3851. //check is swchnl or setbw
  3852. if(!bSwitchChannel && !bSetBandWidth)
  3853. {
  3854. DBG_871X("PHY_HandleSwChnlAndSetBW8812: not switch channel and not set bandwidth \n");
  3855. return;
  3856. }
  3857. //skip change for channel or bandwidth is the same
  3858. if(bSwitchChannel)
  3859. {
  3860. if(pHalData->CurrentChannel != ChannelNum)
  3861. {
  3862. if (HAL_IsLegalChannel(Adapter, ChannelNum))
  3863. pHalData->bSwChnl = _TRUE;
  3864. else
  3865. return;
  3866. }
  3867. }
  3868. if(bSetBandWidth)
  3869. {
  3870. if(pHalData->bChnlBWInitialzed == _FALSE)
  3871. {
  3872. pHalData->bChnlBWInitialzed = _TRUE;
  3873. pHalData->bSetChnlBW = _TRUE;
  3874. }
  3875. else if((pHalData->CurrentChannelBW != ChnlWidth) ||
  3876. (pHalData->nCur40MhzPrimeSC != ChnlOffsetOf40MHz) ||
  3877. (pHalData->nCur80MhzPrimeSC != ChnlOffsetOf80MHz) ||
  3878. (pHalData->CurrentCenterFrequencyIndex1!= CenterFrequencyIndex1))
  3879. {
  3880. pHalData->bSetChnlBW = _TRUE;
  3881. }
  3882. }
  3883. if(!pHalData->bSetChnlBW && !pHalData->bSwChnl)
  3884. {
  3885. //DBG_871X("<= PHY_HandleSwChnlAndSetBW8812: bSwChnl %d, bSetChnlBW %d \n",pHalData->bSwChnl,pHalData->bSetChnlBW);
  3886. return;
  3887. }
  3888. if(pHalData->bSwChnl)
  3889. {
  3890. pHalData->CurrentChannel=ChannelNum;
  3891. pHalData->CurrentCenterFrequencyIndex1 = ChannelNum;
  3892. }
  3893. if(pHalData->bSetChnlBW)
  3894. {
  3895. pHalData->CurrentChannelBW = ChnlWidth;
  3896. #if 0
  3897. if(ExtChnlOffsetOf40MHz==EXTCHNL_OFFSET_LOWER)
  3898. pHalData->nCur40MhzPrimeSC = HAL_PRIME_CHNL_OFFSET_UPPER;
  3899. else if(ExtChnlOffsetOf40MHz==EXTCHNL_OFFSET_UPPER)
  3900. pHalData->nCur40MhzPrimeSC = HAL_PRIME_CHNL_OFFSET_LOWER;
  3901. else
  3902. pHalData->nCur40MhzPrimeSC = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  3903. if(ExtChnlOffsetOf80MHz==EXTCHNL_OFFSET_LOWER)
  3904. pHalData->nCur80MhzPrimeSC = HAL_PRIME_CHNL_OFFSET_UPPER;
  3905. else if(ExtChnlOffsetOf80MHz==EXTCHNL_OFFSET_UPPER)
  3906. pHalData->nCur80MhzPrimeSC = HAL_PRIME_CHNL_OFFSET_LOWER;
  3907. else
  3908. pHalData->nCur80MhzPrimeSC = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  3909. #else
  3910. pHalData->nCur40MhzPrimeSC = ChnlOffsetOf40MHz;
  3911. pHalData->nCur80MhzPrimeSC = ChnlOffsetOf80MHz;
  3912. #endif
  3913. pHalData->CurrentCenterFrequencyIndex1 = CenterFrequencyIndex1;
  3914. }
  3915. //Switch workitem or set timer to do switch channel or setbandwidth operation
  3916. if((!pDefAdapter->bDriverStopped) && (!pDefAdapter->bSurpriseRemoved))
  3917. {
  3918. phy_SwChnlAndSetBwMode8812(Adapter);
  3919. }
  3920. else
  3921. {
  3922. if(pHalData->bSwChnl)
  3923. {
  3924. pHalData->CurrentChannel = tmpChannel;
  3925. pHalData->CurrentCenterFrequencyIndex1 = tmpChannel;
  3926. }
  3927. if(pHalData->bSetChnlBW)
  3928. {
  3929. pHalData->CurrentChannelBW = tmpBW;
  3930. pHalData->nCur40MhzPrimeSC = tmpnCur40MhzPrimeSC;
  3931. pHalData->nCur80MhzPrimeSC = tmpnCur80MhzPrimeSC;
  3932. pHalData->CurrentCenterFrequencyIndex1 = tmpCenterFrequencyIndex1;
  3933. }
  3934. }
  3935. //DBG_871X("Channel %d ChannelBW %d ",pHalData->CurrentChannel, pHalData->CurrentChannelBW);
  3936. //DBG_871X("40MhzPrimeSC %d 80MhzPrimeSC %d ",pHalData->nCur40MhzPrimeSC, pHalData->nCur80MhzPrimeSC);
  3937. //DBG_871X("CenterFrequencyIndex1 %d \n",pHalData->CurrentCenterFrequencyIndex1);
  3938. //DBG_871X("<= PHY_HandleSwChnlAndSetBW8812: bSwChnl %d, bSetChnlBW %d \n",pHalData->bSwChnl,pHalData->bSetChnlBW);
  3939. }
  3940. VOID
  3941. PHY_SetBWMode8812(
  3942. IN PADAPTER Adapter,
  3943. IN CHANNEL_WIDTH Bandwidth, // 20M or 40M
  3944. IN u8 Offset // Upper, Lower, or Don't care
  3945. )
  3946. {
  3947. PHAL_DATA_TYPE pHalData = GET_HAL_DATA(Adapter);
  3948. //DBG_871X("%s()===>\n",__FUNCTION__);
  3949. PHY_HandleSwChnlAndSetBW8812(Adapter, _FALSE, _TRUE, pHalData->CurrentChannel, Bandwidth, Offset, Offset, pHalData->CurrentChannel);
  3950. //DBG_871X("<==%s()\n",__FUNCTION__);
  3951. }
  3952. VOID
  3953. PHY_SwChnl8812(
  3954. IN PADAPTER Adapter,
  3955. IN u8 channel
  3956. )
  3957. {
  3958. //DBG_871X("%s()===>\n",__FUNCTION__);
  3959. PHY_HandleSwChnlAndSetBW8812(Adapter, _TRUE, _FALSE, channel, 0, 0, 0, channel);
  3960. //DBG_871X("<==%s()\n",__FUNCTION__);
  3961. }
  3962. VOID
  3963. PHY_SetSwChnlBWMode8812(
  3964. IN PADAPTER Adapter,
  3965. IN u8 channel,
  3966. IN CHANNEL_WIDTH Bandwidth,
  3967. IN u8 Offset40,
  3968. IN u8 Offset80
  3969. )
  3970. {
  3971. //DBG_871X("%s()===>\n",__FUNCTION__);
  3972. PHY_HandleSwChnlAndSetBW8812(Adapter, _TRUE, _TRUE, channel, Bandwidth, Offset40, Offset80, channel);
  3973. //DBG_871X("<==%s()\n",__FUNCTION__);
  3974. }