rtl8812a_hal_init.c 162 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043
  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_HAL_INIT_C_
  21. //#include <drv_types.h>
  22. #include <rtl8812a_hal.h>
  23. #if defined(CONFIG_IOL)
  24. void iol_mode_enable(PADAPTER padapter, u8 enable)
  25. {
  26. u8 reg_0xf0 = 0;
  27. if(enable)
  28. {
  29. //Enable initial offload
  30. reg_0xf0 = rtw_read8(padapter, REG_SYS_CFG);
  31. //DBG_871X("%s reg_0xf0:0x%02x, write 0x%02x\n", __FUNCTION__, reg_0xf0, reg_0xf0|IOL_ENABLE);
  32. rtw_write8(padapter, REG_SYS_CFG, reg_0xf0|SW_OFFLOAD_EN);
  33. _8051Reset8812(padapter);
  34. }
  35. else
  36. {
  37. //disable initial offload
  38. reg_0xf0 = rtw_read8(padapter, REG_SYS_CFG);
  39. //DBG_871X("%s reg_0xf0:0x%02x, write 0x%02x\n", __FUNCTION__, reg_0xf0, reg_0xf0& ~IOL_ENABLE);
  40. rtw_write8(padapter, REG_SYS_CFG, reg_0xf0 & ~SW_OFFLOAD_EN);
  41. }
  42. }
  43. s32 iol_execute(PADAPTER padapter, u8 control)
  44. {
  45. s32 status = _FAIL;
  46. u8 reg_0x88 = 0;
  47. u32 start = 0, passing_time = 0;
  48. control = control&0x0f;
  49. reg_0x88 = rtw_read8(padapter, 0x88);
  50. //DBG_871X("%s reg_0x88:0x%02x, write 0x%02x\n", __FUNCTION__, reg_0x88, reg_0x88|control);
  51. rtw_write8(padapter, 0x88, reg_0x88|control);
  52. start = rtw_get_current_time();
  53. while((reg_0x88=rtw_read8(padapter, 0x88)) & control
  54. && (passing_time=rtw_get_passing_time_ms(start))<1000
  55. ) {
  56. DBG_871X("%s polling reg_0x88:0x%02x\n", __FUNCTION__, reg_0x88);
  57. rtw_usleep_os(100);
  58. }
  59. reg_0x88 = rtw_read8(padapter, 0x88);
  60. status = (reg_0x88 & control)?_FAIL:_SUCCESS;
  61. if(reg_0x88 & control<<4)
  62. status = _FAIL;
  63. DBG_871X("%s in %u ms, reg_0x88:0x%02x\n", __FUNCTION__, passing_time, reg_0x88);
  64. return status;
  65. }
  66. s32 iol_InitLLTTable(
  67. PADAPTER padapter,
  68. u8 txpktbuf_bndy
  69. )
  70. {
  71. //DBG_871X("%s txpktbuf_bndy:%u\n", __FUNCTION__, txpktbuf_bndy);
  72. rtw_write8(padapter, REG_TDECTRL+1, txpktbuf_bndy);
  73. return iol_execute(padapter, IOL_INIT_LLT);
  74. }
  75. static VOID
  76. efuse_phymap_to_logical(u8 * phymap, u16 _offset, u16 _size_byte, u8 *pbuf)
  77. {
  78. u8 *efuseTbl = NULL;
  79. u8 rtemp8;
  80. u16 eFuse_Addr = 0;
  81. u8 offset, wren;
  82. u16 i, j;
  83. u16 **eFuseWord = NULL;
  84. u16 efuse_utilized = 0;
  85. u8 efuse_usage = 0;
  86. u8 u1temp = 0;
  87. efuseTbl = (u8*)rtw_zmalloc(EFUSE_MAP_LEN_JAGUAR);
  88. if(efuseTbl == NULL)
  89. {
  90. DBG_871X("%s: alloc efuseTbl fail!\n", __FUNCTION__);
  91. goto exit;
  92. }
  93. eFuseWord= (u16 **)rtw_malloc2d(EFUSE_MAX_SECTION_JAGUAR, EFUSE_MAX_WORD_UNIT, sizeof(u16));
  94. if(eFuseWord == NULL)
  95. {
  96. DBG_871X("%s: alloc eFuseWord fail!\n", __FUNCTION__);
  97. goto exit;
  98. }
  99. // 0. Refresh efuse init map as all oxFF.
  100. for (i = 0; i < EFUSE_MAX_SECTION_JAGUAR; i++)
  101. for (j = 0; j < EFUSE_MAX_WORD_UNIT; j++)
  102. eFuseWord[i][j] = 0xFFFF;
  103. //
  104. // 1. Read the first byte to check if efuse is empty!!!
  105. //
  106. //
  107. rtemp8 = *(phymap+eFuse_Addr);
  108. if(rtemp8 != 0xFF)
  109. {
  110. efuse_utilized++;
  111. //printk("efuse_Addr-%d efuse_data=%x\n", eFuse_Addr, *rtemp8);
  112. eFuse_Addr++;
  113. }
  114. else
  115. {
  116. DBG_871X("EFUSE is empty efuse_Addr-%d efuse_data=%x\n", eFuse_Addr, rtemp8);
  117. goto exit;
  118. }
  119. //
  120. // 2. Read real efuse content. Filter PG header and every section data.
  121. //
  122. while((rtemp8 != 0xFF) && (eFuse_Addr < EFUSE_REAL_CONTENT_LEN_JAGUAR))
  123. {
  124. //RTPRINT(FEEPROM, EFUSE_READ_ALL, ("efuse_Addr-%d efuse_data=%x\n", eFuse_Addr-1, *rtemp8));
  125. // Check PG header for section num.
  126. if((rtemp8 & 0x1F ) == 0x0F) //extended header
  127. {
  128. u1temp =( (rtemp8 & 0xE0) >> 5);
  129. //RTPRINT(FEEPROM, EFUSE_READ_ALL, ("extended header u1temp=%x *rtemp&0xE0 0x%x\n", u1temp, *rtemp8 & 0xE0));
  130. //RTPRINT(FEEPROM, EFUSE_READ_ALL, ("extended header u1temp=%x \n", u1temp));
  131. rtemp8 = *(phymap+eFuse_Addr);
  132. //RTPRINT(FEEPROM, EFUSE_READ_ALL, ("extended header efuse_Addr-%d efuse_data=%x\n", eFuse_Addr, *rtemp8));
  133. if((rtemp8 & 0x0F) == 0x0F)
  134. {
  135. eFuse_Addr++;
  136. rtemp8 = *(phymap+eFuse_Addr);
  137. if(rtemp8 != 0xFF && (eFuse_Addr < EFUSE_REAL_CONTENT_LEN_JAGUAR))
  138. {
  139. eFuse_Addr++;
  140. }
  141. continue;
  142. }
  143. else
  144. {
  145. offset = ((rtemp8 & 0xF0) >> 1) | u1temp;
  146. wren = (rtemp8 & 0x0F);
  147. eFuse_Addr++;
  148. }
  149. }
  150. else
  151. {
  152. offset = ((rtemp8 >> 4) & 0x0f);
  153. wren = (rtemp8 & 0x0f);
  154. }
  155. if(offset < EFUSE_MAX_SECTION_JAGUAR)
  156. {
  157. // Get word enable value from PG header
  158. //RTPRINT(FEEPROM, EFUSE_READ_ALL, ("Offset-%d Worden=%x\n", offset, wren));
  159. for(i=0; i<EFUSE_MAX_WORD_UNIT; i++)
  160. {
  161. // Check word enable condition in the section
  162. if(!(wren & 0x01))
  163. {
  164. //RTPRINT(FEEPROM, EFUSE_READ_ALL, ("Addr=%d \n", eFuse_Addr));
  165. rtemp8 = *(phymap+eFuse_Addr);
  166. eFuse_Addr++;
  167. //RTPRINT(FEEPROM, EFUSE_READ_ALL, ("Data=0x%x\n", *rtemp8));
  168. efuse_utilized++;
  169. eFuseWord[offset][i] = (rtemp8 & 0xff);
  170. if(eFuse_Addr >= EFUSE_REAL_CONTENT_LEN_JAGUAR)
  171. break;
  172. //RTPRINT(FEEPROM, EFUSE_READ_ALL, ("Addr=%d", eFuse_Addr));
  173. rtemp8 = *(phymap+eFuse_Addr);
  174. eFuse_Addr++;
  175. //RTPRINT(FEEPROM, EFUSE_READ_ALL, ("Data=0x%x\n", *rtemp8));
  176. efuse_utilized++;
  177. eFuseWord[offset][i] |= (((u2Byte)rtemp8 << 8) & 0xff00);
  178. if(eFuse_Addr >= EFUSE_REAL_CONTENT_LEN_JAGUAR)
  179. break;
  180. }
  181. wren >>= 1;
  182. }
  183. }
  184. // Read next PG header
  185. rtemp8 = *(phymap+eFuse_Addr);
  186. //RTPRINT(FEEPROM, EFUSE_READ_ALL, ("Addr=%d rtemp 0x%x\n", eFuse_Addr, *rtemp8));
  187. if(rtemp8 != 0xFF && (eFuse_Addr < EFUSE_REAL_CONTENT_LEN_JAGUAR))
  188. {
  189. efuse_utilized++;
  190. eFuse_Addr++;
  191. }
  192. }
  193. //
  194. // 3. Collect 16 sections and 4 word unit into Efuse map.
  195. //
  196. for(i=0; i<EFUSE_MAX_SECTION_JAGUAR; i++)
  197. {
  198. for(j=0; j<EFUSE_MAX_WORD_UNIT; j++)
  199. {
  200. efuseTbl[(i*8)+(j*2)]=(eFuseWord[i][j] & 0xff);
  201. efuseTbl[(i*8)+((j*2)+1)]=((eFuseWord[i][j] >> 8) & 0xff);
  202. }
  203. }
  204. //
  205. // 4. Copy from Efuse map to output pointer memory!!!
  206. //
  207. for(i=0; i<_size_byte; i++)
  208. {
  209. pbuf[i] = efuseTbl[_offset+i];
  210. }
  211. //
  212. // 5. Calculate Efuse utilization.
  213. //
  214. efuse_usage = (u1Byte)((efuse_utilized*100)/EFUSE_REAL_CONTENT_LEN_JAGUAR);
  215. //Adapter->HalFunc.SetHwRegHandler(Adapter, HW_VAR_EFUSE_BYTES, (u8 *)&efuse_utilized);
  216. exit:
  217. if(efuseTbl)
  218. rtw_mfree(efuseTbl, EFUSE_MAP_LEN_JAGUAR);
  219. if(eFuseWord)
  220. rtw_mfree2d((void *)eFuseWord, EFUSE_MAX_SECTION_JAGUAR, EFUSE_MAX_WORD_UNIT, sizeof(u16));
  221. }
  222. void efuse_read_phymap_from_txpktbuf(
  223. ADAPTER *adapter,
  224. int bcnhead, //beacon head, where FW store len(2-byte) and efuse physical map.
  225. u8 *content, //buffer to store efuse physical map
  226. u16 *size //for efuse content: the max byte to read. will update to byte read
  227. )
  228. {
  229. u16 dbg_addr = 0;
  230. u32 start = 0, passing_time = 0;
  231. u8 reg_0x143 = 0;
  232. u8 reg_0x106 = 0;
  233. u32 lo32 = 0, hi32 = 0;
  234. u16 len = 0, count = 0;
  235. int i = 0;
  236. u16 limit = *size;
  237. u8 *pos = content;
  238. if(bcnhead<0) //if not valid
  239. bcnhead = rtw_read8(adapter, REG_TDECTRL+1);
  240. DBG_871X("%s bcnhead:%d\n", __FUNCTION__, bcnhead);
  241. //reg_0x106 = rtw_read8(adapter, REG_PKT_BUFF_ACCESS_CTRL);
  242. //DBG_871X("%s reg_0x106:0x%02x, write 0x%02x\n", __FUNCTION__, reg_0x106, 0x69);
  243. rtw_write8(adapter, REG_PKT_BUFF_ACCESS_CTRL, TXPKT_BUF_SELECT);
  244. //DBG_871X("%s reg_0x106:0x%02x\n", __FUNCTION__, rtw_read8(adapter, 0x106));
  245. dbg_addr = bcnhead*128/8; //8-bytes addressing
  246. while(1)
  247. {
  248. //DBG_871X("%s dbg_addr:0x%x\n", __FUNCTION__, dbg_addr+i);
  249. rtw_write16(adapter, REG_PKTBUF_DBG_ADDR, dbg_addr+i);
  250. //DBG_871X("%s write reg_0x143:0x00\n", __FUNCTION__);
  251. rtw_write8(adapter, REG_TXPKTBUF_DBG, 0);
  252. start = rtw_get_current_time();
  253. while(!(reg_0x143=rtw_read8(adapter, REG_TXPKTBUF_DBG))//dbg
  254. //while(rtw_read8(adapter, REG_TXPKTBUF_DBG) & BIT0
  255. && (passing_time=rtw_get_passing_time_ms(start))<1000
  256. ) {
  257. DBG_871X("%s polling reg_0x143:0x%02x, reg_0x106:0x%02x\n", __FUNCTION__, reg_0x143, rtw_read8(adapter, 0x106));
  258. rtw_usleep_os(100);
  259. }
  260. lo32 = rtw_read32(adapter, REG_PKTBUF_DBG_DATA_L);
  261. hi32 = rtw_read32(adapter, REG_PKTBUF_DBG_DATA_H);
  262. #if 0
  263. DBG_871X("%s lo32:0x%08x, %02x %02x %02x %02x\n", __FUNCTION__, lo32
  264. , rtw_read8(adapter, REG_PKTBUF_DBG_DATA_L)
  265. , rtw_read8(adapter, REG_PKTBUF_DBG_DATA_L+1)
  266. , rtw_read8(adapter, REG_PKTBUF_DBG_DATA_L+2)
  267. , rtw_read8(adapter, REG_PKTBUF_DBG_DATA_L+3)
  268. );
  269. DBG_871X("%s hi32:0x%08x, %02x %02x %02x %02x\n", __FUNCTION__, hi32
  270. , rtw_read8(adapter, REG_PKTBUF_DBG_DATA_H)
  271. , rtw_read8(adapter, REG_PKTBUF_DBG_DATA_H+1)
  272. , rtw_read8(adapter, REG_PKTBUF_DBG_DATA_H+2)
  273. , rtw_read8(adapter, REG_PKTBUF_DBG_DATA_H+3)
  274. );
  275. #endif
  276. if(i==0)
  277. {
  278. #if 1 //for debug
  279. u8 lenc[2];
  280. u16 lenbak, aaabak;
  281. u16 aaa;
  282. lenc[0] = rtw_read8(adapter, REG_PKTBUF_DBG_DATA_L);
  283. lenc[1] = rtw_read8(adapter, REG_PKTBUF_DBG_DATA_L+1);
  284. aaabak = le16_to_cpup((u16*)lenc);
  285. lenbak = le16_to_cpu(*((u16*)lenc));
  286. aaa = le16_to_cpup((u16*)&lo32);
  287. #endif
  288. len = le16_to_cpu(*((u16*)&lo32));
  289. limit = len-2<limit?len-2:limit;
  290. DBG_871X("%s len:%u, lenbak:%u, aaa:%u, aaabak:%u\n", __FUNCTION__, len, lenbak, aaa, aaabak);
  291. _rtw_memcpy(pos, ((u8*)&lo32)+2, limit>=count+2?2:limit-count);
  292. count+=limit>=count+2?2:limit-count;
  293. pos=content+count;
  294. }
  295. else
  296. {
  297. _rtw_memcpy(pos, ((u8*)&lo32), limit>=count+4?4:limit-count);
  298. count+=limit>=count+4?4:limit-count;
  299. pos=content+count;
  300. }
  301. if(limit>count && len-2>count) {
  302. _rtw_memcpy(pos, (u8*)&hi32, limit>=count+4?4:limit-count);
  303. count+=limit>=count+4?4:limit-count;
  304. pos=content+count;
  305. }
  306. if(limit<=count || len-2<=count)
  307. break;
  308. i++;
  309. }
  310. rtw_write8(adapter, REG_PKT_BUFF_ACCESS_CTRL, DISABLE_TRXPKT_BUF_ACCESS);
  311. DBG_871X("%s read count:%u\n", __FUNCTION__, count);
  312. *size = count;
  313. }
  314. static bool efuse_read_phymap(
  315. PADAPTER Adapter,
  316. u8 *pbuf, //buffer to store efuse physical map
  317. u16 *size //the max byte to read. will update to byte read
  318. )
  319. {
  320. u8 *pos = pbuf;
  321. u16 limit = *size;
  322. u16 addr = 0;
  323. bool reach_end = _FALSE;
  324. //
  325. // Refresh efuse init map as all 0xFF.
  326. //
  327. _rtw_memset(pbuf, 0xFF, limit);
  328. //
  329. // Read physical efuse content.
  330. //
  331. while(addr < limit)
  332. {
  333. ReadEFuseByte(Adapter, addr, pos, _FALSE);
  334. if(*pos != 0xFF)
  335. {
  336. pos++;
  337. addr++;
  338. }
  339. else
  340. {
  341. reach_end = _TRUE;
  342. break;
  343. }
  344. }
  345. *size = addr;
  346. return reach_end;
  347. }
  348. s32 iol_read_efuse(
  349. PADAPTER padapter,
  350. u8 txpktbuf_bndy,
  351. u16 offset,
  352. u16 size_byte,
  353. u8 *logical_map
  354. )
  355. {
  356. s32 status = _FAIL;
  357. u8 reg_0x106 = 0;
  358. u8 physical_map[512];
  359. u16 size = 512;
  360. int i;
  361. rtw_write8(padapter, REG_TDECTRL+1, txpktbuf_bndy);
  362. _rtw_memset(physical_map, 0xFF, 512);
  363. ///reg_0x106 = rtw_read8(padapter, REG_PKT_BUFF_ACCESS_CTRL);
  364. //DBG_871X("%s reg_0x106:0x%02x, write 0x%02x\n", __FUNCTION__, reg_0x106, 0x69);
  365. rtw_write8(padapter, REG_PKT_BUFF_ACCESS_CTRL, TXPKT_BUF_SELECT);
  366. //DBG_871X("%s reg_0x106:0x%02x\n", __FUNCTION__, rtw_read8(padapter, 0x106));
  367. status = iol_execute(padapter, IOL_READ_EFUSE_MAP);
  368. if(status == _SUCCESS)
  369. efuse_read_phymap_from_txpktbuf(padapter, txpktbuf_bndy, physical_map, &size);
  370. #if 0
  371. DBG_871X("%s physical map\n", __FUNCTION__);
  372. for(i=0;i<size;i++)
  373. {
  374. DBG_871X("%02x ", physical_map[i]);
  375. if(i%16==15)
  376. DBG_871X("\n");
  377. }
  378. DBG_871X("\n");
  379. #endif
  380. efuse_phymap_to_logical(physical_map, offset, size_byte, logical_map);
  381. return status;
  382. }
  383. #endif /* defined(CONFIG_IOL) */
  384. //-------------------------------------------------------------------------
  385. //
  386. // LLT R/W/Init function
  387. //
  388. //-------------------------------------------------------------------------
  389. static s32 _LLTWrite(PADAPTER padapter, u32 address, u32 data)
  390. {
  391. s32 status = _SUCCESS;
  392. s32 count = 0;
  393. u32 value = _LLT_INIT_ADDR(address) | _LLT_INIT_DATA(data) | _LLT_OP(_LLT_WRITE_ACCESS);
  394. u16 LLTReg = REG_LLT_INIT;
  395. rtw_write32(padapter, LLTReg, value);
  396. //polling
  397. do {
  398. value = rtw_read32(padapter, LLTReg);
  399. if (_LLT_NO_ACTIVE == _LLT_OP_VALUE(value)) {
  400. break;
  401. }
  402. if (count > POLLING_LLT_THRESHOLD) {
  403. RT_TRACE(_module_hal_init_c_, _drv_err_, ("Failed to polling write LLT done at address %d!\n", address));
  404. status = _FAIL;
  405. break;
  406. }
  407. } while (count++);
  408. return status;
  409. }
  410. u8 _LLTRead(PADAPTER padapter, u32 address)
  411. {
  412. s32 count = 0;
  413. u32 value = _LLT_INIT_ADDR(address) | _LLT_OP(_LLT_READ_ACCESS);
  414. u16 LLTReg = REG_LLT_INIT;
  415. rtw_write32(padapter, LLTReg, value);
  416. //polling and get value
  417. do {
  418. value = rtw_read32(padapter, LLTReg);
  419. if (_LLT_NO_ACTIVE == _LLT_OP_VALUE(value)) {
  420. return (u8)value;
  421. }
  422. if (count > POLLING_LLT_THRESHOLD) {
  423. RT_TRACE(_module_hal_init_c_, _drv_err_, ("Failed to polling read LLT done at address %d!\n", address));
  424. break;
  425. }
  426. } while (count++);
  427. return 0xFF;
  428. }
  429. s32 InitLLTTable8812(PADAPTER padapter, u8 txpktbuf_bndy)
  430. {
  431. s32 status = _FAIL;
  432. u32 i;
  433. u32 Last_Entry_Of_TxPktBuf = LAST_ENTRY_OF_TX_PKT_BUFFER_8812;
  434. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(padapter);
  435. #if defined(CONFIG_IOL_LLT)
  436. if(1 || rtw_IOL_applied(padapter))
  437. {
  438. iol_mode_enable(padapter, 1);
  439. status = iol_InitLLTTable(padapter, txpktbuf_bndy);
  440. iol_mode_enable(padapter, 0);
  441. }
  442. else
  443. #endif
  444. {
  445. for (i = 0; i < (txpktbuf_bndy - 1); i++) {
  446. status = _LLTWrite(padapter, i, i + 1);
  447. if (_SUCCESS != status) {
  448. return status;
  449. }
  450. }
  451. // end of list
  452. status = _LLTWrite(padapter, (txpktbuf_bndy - 1), 0xFF);
  453. if (_SUCCESS != status) {
  454. return status;
  455. }
  456. // Make the other pages as ring buffer
  457. // This ring buffer is used as beacon buffer if we config this MAC as two MAC transfer.
  458. // Otherwise used as local loopback buffer.
  459. for (i = txpktbuf_bndy; i < Last_Entry_Of_TxPktBuf; i++) {
  460. status = _LLTWrite(padapter, i, (i + 1));
  461. if (_SUCCESS != status) {
  462. return status;
  463. }
  464. }
  465. // Let last entry point to the start entry of ring buffer
  466. status = _LLTWrite(padapter, Last_Entry_Of_TxPktBuf, txpktbuf_bndy);
  467. if (_SUCCESS != status) {
  468. return status;
  469. }
  470. }
  471. return status;
  472. }
  473. BOOLEAN HalDetectPwrDownMode8812(PADAPTER Adapter)
  474. {
  475. u8 tmpvalue = 0;
  476. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  477. struct pwrctrl_priv *pwrctrlpriv = &Adapter->pwrctrlpriv;
  478. EFUSE_ShadowRead(Adapter, 1, EEPROM_RF_OPT3_92C, (u32 *)&tmpvalue);
  479. // 2010/08/25 MH INF priority > PDN Efuse value.
  480. if(tmpvalue & BIT(4) && pwrctrlpriv->reg_pdnmode)
  481. {
  482. pHalData->pwrdown = _TRUE;
  483. }
  484. else
  485. {
  486. pHalData->pwrdown = _FALSE;
  487. }
  488. DBG_8192C("HalDetectPwrDownMode(): PDN=%d\n", pHalData->pwrdown);
  489. return pHalData->pwrdown;
  490. } // HalDetectPwrDownMode
  491. #ifdef CONFIG_WOWLAN
  492. void Hal_DetectWoWMode(PADAPTER pAdapter)
  493. {
  494. pAdapter->pwrctrlpriv.bSupportRemoteWakeup = _TRUE;
  495. DBG_871X("%s\n", __func__);
  496. }
  497. #endif
  498. //====================================================================================
  499. //
  500. // 20100209 Joseph:
  501. // This function is used only for 92C to set REG_BCN_CTRL(0x550) register.
  502. // We just reserve the value of the register in variable pHalData->RegBcnCtrlVal and then operate
  503. // the value of the register via atomic operation.
  504. // This prevents from race condition when setting this register.
  505. // The value of pHalData->RegBcnCtrlVal is initialized in HwConfigureRTL8192CE() function.
  506. //
  507. void SetBcnCtrlReg(
  508. PADAPTER padapter,
  509. u8 SetBits,
  510. u8 ClearBits)
  511. {
  512. PHAL_DATA_TYPE pHalData;
  513. pHalData = GET_HAL_DATA(padapter);
  514. pHalData->RegBcnCtrlVal |= SetBits;
  515. pHalData->RegBcnCtrlVal &= ~ClearBits;
  516. #if 0
  517. //#ifdef CONFIG_SDIO_HCI
  518. if (pHalData->sdio_himr & (SDIO_HIMR_TXBCNOK_MSK | SDIO_HIMR_TXBCNERR_MSK))
  519. pHalData->RegBcnCtrlVal |= EN_TXBCN_RPT;
  520. #endif
  521. rtw_write8(padapter, REG_BCN_CTRL, (u8)pHalData->RegBcnCtrlVal);
  522. }
  523. static VOID
  524. _FWDownloadEnable_8812(
  525. IN PADAPTER padapter,
  526. IN BOOLEAN enable
  527. )
  528. {
  529. u8 tmp;
  530. if(enable)
  531. {
  532. // MCU firmware download enable.
  533. tmp = rtw_read8(padapter, REG_MCUFWDL);
  534. rtw_write8(padapter, REG_MCUFWDL, tmp|0x01);
  535. // 8051 reset
  536. tmp = rtw_read8(padapter, REG_MCUFWDL+2);
  537. rtw_write8(padapter, REG_MCUFWDL+2, tmp&0xf7);
  538. }
  539. else
  540. {
  541. // MCU firmware download disable.
  542. tmp = rtw_read8(padapter, REG_MCUFWDL);
  543. rtw_write8(padapter, REG_MCUFWDL, tmp&0xfe);
  544. }
  545. }
  546. #define MAX_REG_BOLCK_SIZE 196
  547. static int
  548. _BlockWrite_8812(
  549. IN PADAPTER padapter,
  550. IN PVOID buffer,
  551. IN u32 buffSize
  552. )
  553. {
  554. int ret = _SUCCESS;
  555. u32 blockSize_p1 = 4; // (Default) Phase #1 : PCI muse use 4-byte write to download FW
  556. u32 blockSize_p2 = 8; // Phase #2 : Use 8-byte, if Phase#1 use big size to write FW.
  557. u32 blockSize_p3 = 1; // Phase #3 : Use 1-byte, the remnant of FW image.
  558. u32 blockCount_p1 = 0, blockCount_p2 = 0, blockCount_p3 = 0;
  559. u32 remainSize_p1 = 0, remainSize_p2 = 0;
  560. u8 *bufferPtr = (u8*)buffer;
  561. u32 i=0, offset=0;
  562. #ifdef CONFIG_PCI_HCI
  563. u8 remainFW[4] = {0, 0, 0, 0};
  564. u8 *p = NULL;
  565. #endif
  566. #ifdef CONFIG_USB_HCI
  567. blockSize_p1 = MAX_REG_BOLCK_SIZE;
  568. #endif
  569. //3 Phase #1
  570. blockCount_p1 = buffSize / blockSize_p1;
  571. remainSize_p1 = buffSize % blockSize_p1;
  572. if (blockCount_p1) {
  573. RT_TRACE(_module_hal_init_c_, _drv_notice_,
  574. ("_BlockWrite: [P1] buffSize(%d) blockSize_p1(%d) blockCount_p1(%d) remainSize_p1(%d)\n",
  575. buffSize, blockSize_p1, blockCount_p1, remainSize_p1));
  576. }
  577. for (i = 0; i < blockCount_p1; i++)
  578. {
  579. #ifdef CONFIG_USB_HCI
  580. ret = rtw_writeN(padapter, (FW_START_ADDRESS + i * blockSize_p1), blockSize_p1, (bufferPtr + i * blockSize_p1));
  581. #else
  582. ret = rtw_write32(padapter, (FW_START_ADDRESS + i * blockSize_p1), le32_to_cpu(*((u32*)(bufferPtr + i * blockSize_p1))));
  583. #endif
  584. if(ret == _FAIL)
  585. goto exit;
  586. }
  587. #ifdef CONFIG_PCI_HCI
  588. p = (u8*)((u32*)(bufferPtr + blockCount_p1 * blockSize_p1));
  589. if (remainSize_p1) {
  590. switch (remainSize_p1) {
  591. case 0:
  592. break;
  593. case 3:
  594. remainFW[2]=*(p+2);
  595. case 2:
  596. remainFW[1]=*(p+1);
  597. case 1:
  598. remainFW[0]=*(p);
  599. ret = rtw_write32(padapter, (FW_START_ADDRESS + blockCount_p1 * blockSize_p1),
  600. le32_to_cpu(*(u32*)remainFW));
  601. }
  602. return ret;
  603. }
  604. #endif
  605. //3 Phase #2
  606. if (remainSize_p1)
  607. {
  608. offset = blockCount_p1 * blockSize_p1;
  609. blockCount_p2 = remainSize_p1/blockSize_p2;
  610. remainSize_p2 = remainSize_p1%blockSize_p2;
  611. if (blockCount_p2) {
  612. RT_TRACE(_module_hal_init_c_, _drv_notice_,
  613. ("_BlockWrite: [P2] buffSize_p2(%d) blockSize_p2(%d) blockCount_p2(%d) remainSize_p2(%d)\n",
  614. (buffSize-offset), blockSize_p2 ,blockCount_p2, remainSize_p2));
  615. }
  616. #ifdef CONFIG_USB_HCI
  617. for (i = 0; i < blockCount_p2; i++) {
  618. ret = rtw_writeN(padapter, (FW_START_ADDRESS + offset + i*blockSize_p2), blockSize_p2, (bufferPtr + offset + i*blockSize_p2));
  619. if(ret == _FAIL)
  620. goto exit;
  621. }
  622. #endif
  623. }
  624. //3 Phase #3
  625. if (remainSize_p2)
  626. {
  627. offset = (blockCount_p1 * blockSize_p1) + (blockCount_p2 * blockSize_p2);
  628. blockCount_p3 = remainSize_p2 / blockSize_p3;
  629. RT_TRACE(_module_hal_init_c_, _drv_notice_,
  630. ("_BlockWrite: [P3] buffSize_p3(%d) blockSize_p3(%d) blockCount_p3(%d)\n",
  631. (buffSize-offset), blockSize_p3, blockCount_p3));
  632. for(i = 0 ; i < blockCount_p3 ; i++){
  633. ret =rtw_write8(padapter, (FW_START_ADDRESS + offset + i), *(bufferPtr + offset + i));
  634. if(ret == _FAIL)
  635. goto exit;
  636. }
  637. }
  638. exit:
  639. return ret;
  640. }
  641. static int
  642. _PageWrite_8812(
  643. IN PADAPTER padapter,
  644. IN u32 page,
  645. IN PVOID buffer,
  646. IN u32 size
  647. )
  648. {
  649. u8 value8;
  650. u8 u8Page = (u8) (page & 0x07) ;
  651. value8 = (rtw_read8(padapter, REG_MCUFWDL+2) & 0xF8) | u8Page ;
  652. rtw_write8(padapter, REG_MCUFWDL+2,value8);
  653. return _BlockWrite_8812(padapter,buffer,size);
  654. }
  655. static VOID
  656. _FillDummy_8812(
  657. u8* pFwBuf,
  658. u32* pFwLen
  659. )
  660. {
  661. u32 FwLen = *pFwLen;
  662. u8 remain = (u8)(FwLen%4);
  663. remain = (remain==0)?0:(4-remain);
  664. while(remain>0)
  665. {
  666. pFwBuf[FwLen] = 0;
  667. FwLen++;
  668. remain--;
  669. }
  670. *pFwLen = FwLen;
  671. }
  672. static int
  673. _WriteFW_8812(
  674. IN PADAPTER padapter,
  675. IN PVOID buffer,
  676. IN u32 size
  677. )
  678. {
  679. // Since we need dynamic decide method of dwonload fw, so we call this function to get chip version.
  680. // We can remove _ReadChipVersion from ReadpadapterInfo8192C later.
  681. int ret = _SUCCESS;
  682. u32 pageNums,remainSize ;
  683. u32 page, offset;
  684. u8 *bufferPtr = (u8*)buffer;
  685. #ifdef CONFIG_PCI_HCI
  686. // 20100120 Joseph: Add for 88CE normal chip.
  687. // Fill in zero to make firmware image to dword alignment.
  688. // _FillDummy(bufferPtr, &size);
  689. #endif
  690. pageNums = size / MAX_DLFW_PAGE_SIZE ;
  691. //RT_ASSERT((pageNums <= 4), ("Page numbers should not greater then 4 \n"));
  692. remainSize = size % MAX_DLFW_PAGE_SIZE;
  693. for (page = 0; page < pageNums; page++) {
  694. offset = page * MAX_DLFW_PAGE_SIZE;
  695. ret = _PageWrite_8812(padapter, page, bufferPtr+offset, MAX_DLFW_PAGE_SIZE);
  696. if(ret == _FAIL)
  697. goto exit;
  698. }
  699. if (remainSize) {
  700. offset = pageNums * MAX_DLFW_PAGE_SIZE;
  701. page = pageNums;
  702. ret = _PageWrite_8812(padapter, page, bufferPtr+offset, remainSize);
  703. if(ret == _FAIL)
  704. goto exit;
  705. }
  706. RT_TRACE(_module_hal_init_c_, _drv_info_, ("_WriteFW Done- for Normal chip.\n"));
  707. exit:
  708. return ret;
  709. }
  710. void _8051Reset8812(PADAPTER padapter)
  711. {
  712. u8 u1bTmp, u1bTmp2;
  713. // Reset MCU IO Wrapper- sugggest by SD1-Gimmy
  714. if(IS_HARDWARE_TYPE_8812(padapter))
  715. {
  716. u1bTmp2 = rtw_read8(padapter, REG_RSV_CTRL+1);
  717. rtw_write8(padapter, REG_RSV_CTRL+1, u1bTmp2&(~BIT3));
  718. }
  719. else if(IS_HARDWARE_TYPE_8821(padapter))
  720. {
  721. u1bTmp2 = rtw_read8(padapter, REG_RSV_CTRL+1);
  722. rtw_write8(padapter, REG_RSV_CTRL+1, u1bTmp2&(~BIT0));
  723. }
  724. u1bTmp = rtw_read8(padapter, REG_SYS_FUNC_EN+1);
  725. rtw_write8(padapter, REG_SYS_FUNC_EN+1, u1bTmp&(~BIT2));
  726. // Enable MCU IO Wrapper
  727. if(IS_HARDWARE_TYPE_8812(padapter))
  728. {
  729. u1bTmp2 = rtw_read8(padapter, REG_RSV_CTRL+1);
  730. rtw_write8(padapter, REG_RSV_CTRL+1, u1bTmp2 |(BIT3));
  731. }
  732. else if(IS_HARDWARE_TYPE_8821(padapter))
  733. {
  734. u1bTmp2 = rtw_read8(padapter, REG_RSV_CTRL+1);
  735. rtw_write8(padapter, REG_RSV_CTRL+1, u1bTmp2|(BIT0));
  736. }
  737. rtw_write8(padapter, REG_SYS_FUNC_EN+1, u1bTmp|(BIT2));
  738. DBG_871X("=====> _8051Reset8812(): 8051 reset success .\n");
  739. }
  740. static s32 _FWFreeToGo8812(PADAPTER padapter)
  741. {
  742. u32 counter = 0;
  743. u32 value32;
  744. u8 value8;
  745. // polling CheckSum report
  746. do {
  747. value32 = rtw_read32(padapter, REG_MCUFWDL);
  748. if (value32 & FWDL_ChkSum_rpt) break;
  749. } while (counter++ < 6000);
  750. if (counter >= 6000) {
  751. DBG_871X("%s: chksum report fail! REG_MCUFWDL:0x%08x\n", __FUNCTION__, value32);
  752. return _FAIL;
  753. }
  754. DBG_871X("%s: Checksum report OK! REG_MCUFWDL:0x%08x\n", __FUNCTION__, value32);
  755. value32 = rtw_read32(padapter, REG_MCUFWDL);
  756. value32 |= MCUFWDL_RDY;
  757. value32 &= ~WINTINI_RDY;
  758. rtw_write32(padapter, REG_MCUFWDL, value32);
  759. _8051Reset8812(padapter);
  760. // polling for FW ready
  761. counter = 0;
  762. do {
  763. value32 = rtw_read32(padapter, REG_MCUFWDL);
  764. if (value32 & WINTINI_RDY) {
  765. DBG_871X("%s: Polling FW ready success!! REG_MCUFWDL:0x%08x\n", __FUNCTION__, value32);
  766. return _SUCCESS;
  767. }
  768. rtw_udelay_os(5);
  769. } while (counter++ < 6000);
  770. DBG_871X ("%s: Polling FW ready fail!! REG_MCUFWDL:0x%08x\n", __FUNCTION__, value32);
  771. return _FAIL;
  772. }
  773. #ifdef CONFIG_FILE_FWIMG
  774. extern char *rtw_fw_file_path;
  775. u8 FwBuffer8812[FW_SIZE_8812];
  776. #endif //CONFIG_FILE_FWIMG
  777. s32
  778. FirmwareDownload8812(
  779. IN PADAPTER Adapter,
  780. IN BOOLEAN bUsedWoWLANFw
  781. )
  782. {
  783. s32 rtStatus = _SUCCESS;
  784. u8 writeFW_retry = 0;
  785. u32 fwdl_start_time;
  786. PHAL_DATA_TYPE pHalData = GET_HAL_DATA(Adapter);
  787. u8 *pFwImageFileName;
  788. u8 *pucMappedFile = NULL;
  789. PRT_FIRMWARE_8812 pFirmware = NULL;
  790. u8 *pFwHdr = NULL;
  791. u8 *pFirmwareBuf;
  792. u32 FirmwareLen;
  793. RT_TRACE(_module_hal_init_c_, _drv_info_, ("+%s\n", __FUNCTION__));
  794. pFirmware = (PRT_FIRMWARE_8812)rtw_zmalloc(sizeof(RT_FIRMWARE_8812));
  795. if(!pFirmware)
  796. {
  797. rtStatus = _FAIL;
  798. goto Exit;
  799. }
  800. #ifdef CONFIG_FILE_FWIMG
  801. if(rtw_is_file_readable(rtw_fw_file_path) == _TRUE)
  802. {
  803. DBG_871X("%s accquire FW from file:%s\n", __FUNCTION__, rtw_fw_file_path);
  804. pFirmware->eFWSource = FW_SOURCE_IMG_FILE;
  805. }
  806. else
  807. #endif //CONFIG_FILE_FWIMG
  808. {
  809. pFirmware->eFWSource = FW_SOURCE_HEADER_FILE;
  810. }
  811. DBG_871X(" ===> FirmwareDownload8812() fw source from %s.\n", (pFirmware->eFWSource ? "Header": "File"));
  812. switch(pFirmware->eFWSource)
  813. {
  814. case FW_SOURCE_IMG_FILE:
  815. #ifdef CONFIG_FILE_FWIMG
  816. rtStatus = rtw_retrive_from_file(rtw_fw_file_path, FwBuffer8812, FW_SIZE_8812);
  817. pFirmware->ulFwLength = rtStatus>=0?rtStatus:0;
  818. pFirmware->szFwBuffer = FwBuffer8812;
  819. #endif //CONFIG_FILE_FWIMG
  820. break;
  821. case FW_SOURCE_HEADER_FILE:
  822. ODM_ConfigFWWithHeaderFile(&pHalData->odmpriv, CONFIG_FW_NIC, (u8 *)&(pFirmware->szFwBuffer), &(pFirmware->ulFwLength));
  823. DBG_871X(" ===> FirmwareDownload8812() fw:%s, size: %d\n", "Firmware for NIC", pFirmware->ulFwLength);
  824. #ifdef CONFIG_WOWLAN
  825. ODM_ConfigFWWithHeaderFile(&pHalData->odmpriv, CONFIG_FW_WoWLAN, (u8 *)&(pFirmware->szWoWLANFwBuffer), &(pFirmware->ulWoWLANFwLength));
  826. DBG_871X(" ===> FirmwareDownload88E() fw:%s, size: %d\n", "Firmware for WoWLAN", pFirmware->ulWoWLANFwLength);
  827. #endif //CONFIG_WOWLAN
  828. if (pFirmware->ulFwLength > FW_SIZE_8812) {
  829. rtStatus = _FAIL;
  830. RT_TRACE(_module_hal_init_c_, _drv_err_, ("Firmware size exceed 0x%X. Check it.\n", FW_SIZE_8812) );
  831. goto Exit;
  832. }
  833. break;
  834. }
  835. #ifdef CONFIG_WOWLAN
  836. if (bUsedWoWLANFw) {
  837. pFirmwareBuf = pFirmware->szWoWLANFwBuffer;
  838. FirmwareLen = pFirmware->ulWoWLANFwLength;
  839. pFwHdr = (u8 *)pFirmware->szWoWLANFwBuffer;
  840. } else
  841. #endif
  842. {
  843. pFirmwareBuf = pFirmware->szFwBuffer;
  844. FirmwareLen = pFirmware->ulFwLength;
  845. DBG_871X_LEVEL(_drv_info_, "+%s: !bUsedWoWLANFw, FmrmwareLen:%d+\n", __func__, FirmwareLen);
  846. // To Check Fw header. Added by tynli. 2009.12.04.
  847. pFwHdr = (u8 *)pFirmware->szFwBuffer;
  848. }
  849. pHalData->FirmwareVersion = (u16)GET_FIRMWARE_HDR_VERSION_8812(pFwHdr);
  850. pHalData->FirmwareSubVersion = (u16)GET_FIRMWARE_HDR_SUB_VER_8812(pFwHdr);
  851. pHalData->FirmwareSignature = (u16)GET_FIRMWARE_HDR_SIGNATURE_8812(pFwHdr);
  852. DBG_871X ("%s: fw_ver=%d fw_subver=%d sig=0x%x\n",
  853. __FUNCTION__, pHalData->FirmwareVersion, pHalData->FirmwareSubVersion, pHalData->FirmwareSignature);
  854. if (IS_FW_HEADER_EXIST_8812(pFwHdr) || IS_FW_HEADER_EXIST_8821(pFwHdr))
  855. {
  856. // Shift 32 bytes for FW header
  857. pFirmwareBuf = pFirmwareBuf + 32;
  858. FirmwareLen = FirmwareLen - 32;
  859. }
  860. // Suggested by Filen. If 8051 is running in RAM code, driver should inform Fw to reset by itself,
  861. // or it will cause download Fw fail. 2010.02.01. by tynli.
  862. if (rtw_read8(Adapter, REG_MCUFWDL) & BIT7) //8051 RAM code
  863. {
  864. rtw_write8(Adapter, REG_MCUFWDL, 0x00);
  865. _8051Reset8812(Adapter);
  866. }
  867. _FWDownloadEnable_8812(Adapter, _TRUE);
  868. fwdl_start_time = rtw_get_current_time();
  869. while(1) {
  870. //reset the FWDL chksum
  871. rtw_write8(Adapter, REG_MCUFWDL, rtw_read8(Adapter, REG_MCUFWDL)|FWDL_ChkSum_rpt);
  872. rtStatus = _WriteFW_8812(Adapter, pFirmwareBuf, FirmwareLen);
  873. if(rtStatus == _SUCCESS
  874. ||(rtw_get_passing_time_ms(fwdl_start_time) > 500 && writeFW_retry++ >= 3)
  875. )
  876. break;
  877. DBG_871X("%s writeFW_retry:%u, time after fwdl_start_time:%ums\n", __FUNCTION__
  878. , writeFW_retry
  879. , rtw_get_passing_time_ms(fwdl_start_time)
  880. );
  881. }
  882. _FWDownloadEnable_8812(Adapter, _FALSE);
  883. if(_SUCCESS != rtStatus){
  884. DBG_871X("DL Firmware failed!\n");
  885. goto Exit;
  886. }
  887. rtStatus = _FWFreeToGo8812(Adapter);
  888. if (_SUCCESS != rtStatus) {
  889. DBG_871X("DL Firmware failed!\n");
  890. goto Exit;
  891. }
  892. RT_TRACE(_module_hal_init_c_, _drv_info_, ("Firmware is ready to run!\n"));
  893. Exit:
  894. if (pFirmware)
  895. rtw_mfree((u8*)pFirmware, sizeof(RT_FIRMWARE_8812));
  896. //RT_TRACE(COMP_INIT, DBG_LOUD, (" <=== FirmwareDownload91C()\n"));
  897. #ifdef CONFIG_WOWLAN
  898. if (Adapter->pwrctrlpriv.wowlan_mode)
  899. InitializeFirmwareVars8812(Adapter);
  900. else
  901. DBG_871X_LEVEL(_drv_always_, "%s: wowland_mode:%d wowlan_wake_reason:%d\n",
  902. __func__, Adapter->pwrctrlpriv.wowlan_mode,
  903. Adapter->pwrctrlpriv.wowlan_wake_reason);
  904. #endif
  905. return rtStatus;
  906. }
  907. void InitializeFirmwareVars8812(PADAPTER padapter)
  908. {
  909. PHAL_DATA_TYPE pHalData = GET_HAL_DATA(padapter);
  910. struct pwrctrl_priv *pwrpriv;
  911. pwrpriv = &padapter->pwrctrlpriv;
  912. // Init Fw LPS related.
  913. padapter->pwrctrlpriv.bFwCurrentInPSMode = _FALSE;
  914. // Init H2C counter. by tynli. 2009.12.09.
  915. pHalData->LastHMEBoxNum = 0;
  916. }
  917. #ifdef CONFIG_WOWLAN
  918. //===========================================
  919. //
  920. // Description: Prepare some information to Fw for WoWLAN.
  921. // (1) Download wowlan Fw.
  922. // (2) Download RSVD page packets.
  923. // (3) Enable AP offload if needed.
  924. //
  925. // 2011.04.12 by tynli.
  926. //
  927. VOID
  928. SetFwRelatedForWoWLAN8812(
  929. IN PADAPTER padapter,
  930. IN u8 bHostIsGoingtoSleep
  931. )
  932. {
  933. int status=_FAIL;
  934. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(padapter);
  935. u8 bRecover = _FALSE;
  936. //
  937. // 1. Before WoWLAN we need to re-download WoWLAN Fw.
  938. //
  939. status = FirmwareDownload8812(padapter, bHostIsGoingtoSleep);
  940. if(status != _SUCCESS) {
  941. DBG_871X("SetFwRelatedForWoWLAN8812(): Re-Download Firmware failed!!\n");
  942. return;
  943. } else {
  944. DBG_871X("SetFwRelatedForWoWLAN8812(): Re-Download Firmware Success !!\n");
  945. }
  946. //
  947. // 2. Re-Init the variables about Fw related setting.
  948. //
  949. InitializeFirmwareVars8812(padapter);
  950. }
  951. #endif //CONFIG_WOWLAN
  952. static void rtl8812_free_hal_data(PADAPTER padapter)
  953. {
  954. _func_enter_;
  955. if (padapter->HalData) {
  956. #ifdef CONFIG_CONCURRENT_MODE
  957. if(padapter->isprimary)
  958. #endif //CONFIG_CONCURRENT_MODE
  959. rtw_mfree(padapter->HalData, sizeof(HAL_DATA_TYPE));
  960. padapter->HalData = NULL;
  961. }
  962. _func_exit_;
  963. }
  964. //===========================================================
  965. // Efuse related code
  966. //===========================================================
  967. BOOLEAN
  968. Hal_GetChnlGroup8812A(
  969. IN u8 Channel,
  970. OUT u8* pGroup
  971. )
  972. {
  973. BOOLEAN bIn24G=_TRUE;
  974. if(Channel <= 14)
  975. {
  976. bIn24G=_TRUE;
  977. if (1 <= Channel && Channel <= 2 ) *pGroup = 0;
  978. else if (3 <= Channel && Channel <= 5 ) *pGroup = 1;
  979. else if (6 <= Channel && Channel <= 8 ) *pGroup = 2;
  980. else if (9 <= Channel && Channel <= 11) *pGroup = 3;
  981. else if (12 <= Channel && Channel <= 14) *pGroup = 4;
  982. else
  983. {
  984. DBG_871X("==>mpt_GetChnlGroup8812A in 2.4 G, but Channel %d in Group not found \n", Channel);
  985. }
  986. }
  987. else
  988. {
  989. bIn24G=_FALSE;
  990. if (36 <= Channel && Channel <= 42) *pGroup = 0;
  991. else if (44 <= Channel && Channel <= 48) *pGroup = 1;
  992. else if (50 <= Channel && Channel <= 58) *pGroup = 2;
  993. else if (60 <= Channel && Channel <= 64) *pGroup = 3;
  994. else if (100 <= Channel && Channel <= 106) *pGroup = 4;
  995. else if (108 <= Channel && Channel <= 114) *pGroup = 5;
  996. else if (116 <= Channel && Channel <= 122) *pGroup = 6;
  997. else if (124 <= Channel && Channel <= 130) *pGroup = 7;
  998. else if (132 <= Channel && Channel <= 138) *pGroup = 8;
  999. else if (140 <= Channel && Channel <= 144) *pGroup = 9;
  1000. else if (149 <= Channel && Channel <= 155) *pGroup = 10;
  1001. else if (157 <= Channel && Channel <= 161) *pGroup = 11;
  1002. else if (165 <= Channel && Channel <= 171) *pGroup = 12;
  1003. else if (173 <= Channel && Channel <= 177) *pGroup = 13;
  1004. else
  1005. {
  1006. DBG_871X("==>mpt_GetChnlGroup8812A in 5G, but Channel %d in Group not found \n",Channel);
  1007. }
  1008. }
  1009. //DBG_871X("<==mpt_GetChnlGroup8812A, (%s) Channel = %d, Group =%d,\n", (bIn24G) ? "2.4G" : "5G", Channel, *pGroup);
  1010. return bIn24G;
  1011. }
  1012. static void
  1013. hal_ReadPowerValueFromPROM8812A(
  1014. IN PADAPTER Adapter,
  1015. IN PTxPowerInfo24G pwrInfo24G,
  1016. IN PTxPowerInfo5G pwrInfo5G,
  1017. IN u8* PROMContent,
  1018. IN BOOLEAN AutoLoadFail
  1019. )
  1020. {
  1021. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  1022. u32 rfPath, eeAddr=EEPROM_TX_PWR_INX_8812, group,TxCount=0;
  1023. _rtw_memset(pwrInfo24G, 0, sizeof(TxPowerInfo24G));
  1024. _rtw_memset(pwrInfo5G, 0, sizeof(TxPowerInfo5G));
  1025. //DBG_871X("hal_ReadPowerValueFromPROM8812A(): PROMContent[0x%x]=0x%x\n", (eeAddr+1), PROMContent[eeAddr+1]);
  1026. if(0xFF == PROMContent[eeAddr+1]) //YJ,add,120316
  1027. AutoLoadFail = _TRUE;
  1028. if(AutoLoadFail)
  1029. {
  1030. DBG_871X("hal_ReadPowerValueFromPROM8812A(): Use Default value!\n");
  1031. for(rfPath = 0 ; rfPath < MAX_RF_PATH ; rfPath++)
  1032. {
  1033. // 2.4G default value
  1034. for(group = 0 ; group < MAX_CHNL_GROUP_24G; group++)
  1035. {
  1036. pwrInfo24G->IndexCCK_Base[rfPath][group] = EEPROM_DEFAULT_24G_INDEX;
  1037. pwrInfo24G->IndexBW40_Base[rfPath][group] = EEPROM_DEFAULT_24G_INDEX;
  1038. }
  1039. for(TxCount=0;TxCount<MAX_TX_COUNT;TxCount++)
  1040. {
  1041. if(TxCount==0)
  1042. {
  1043. pwrInfo24G->BW20_Diff[rfPath][0] = EEPROM_DEFAULT_24G_HT20_DIFF;
  1044. pwrInfo24G->OFDM_Diff[rfPath][0] = EEPROM_DEFAULT_24G_OFDM_DIFF;
  1045. }
  1046. else
  1047. {
  1048. pwrInfo24G->BW20_Diff[rfPath][TxCount] = EEPROM_DEFAULT_DIFF;
  1049. pwrInfo24G->BW40_Diff[rfPath][TxCount] = EEPROM_DEFAULT_DIFF;
  1050. pwrInfo24G->CCK_Diff[rfPath][TxCount] = EEPROM_DEFAULT_DIFF;
  1051. pwrInfo24G->OFDM_Diff[rfPath][TxCount] = EEPROM_DEFAULT_DIFF;
  1052. }
  1053. }
  1054. // 5G default value
  1055. for(group = 0 ; group < MAX_CHNL_GROUP_5G; group++)
  1056. {
  1057. pwrInfo5G->IndexBW40_Base[rfPath][group] = EEPROM_DEFAULT_5G_INDEX;
  1058. }
  1059. for(TxCount=0;TxCount<MAX_TX_COUNT;TxCount++)
  1060. {
  1061. if(TxCount==0)
  1062. {
  1063. pwrInfo5G->OFDM_Diff[rfPath][0] = EEPROM_DEFAULT_5G_OFDM_DIFF;
  1064. pwrInfo5G->BW20_Diff[rfPath][0] = EEPROM_DEFAULT_5G_HT20_DIFF;
  1065. pwrInfo5G->BW80_Diff[rfPath][0] = EEPROM_DEFAULT_DIFF;
  1066. pwrInfo5G->BW160_Diff[rfPath][0] = EEPROM_DEFAULT_DIFF;
  1067. }
  1068. else
  1069. {
  1070. pwrInfo5G->OFDM_Diff[rfPath][TxCount] = EEPROM_DEFAULT_DIFF;
  1071. pwrInfo5G->BW20_Diff[rfPath][TxCount] = EEPROM_DEFAULT_DIFF;
  1072. pwrInfo5G->BW40_Diff[rfPath][TxCount]= EEPROM_DEFAULT_DIFF;
  1073. pwrInfo5G->BW80_Diff[rfPath][TxCount]= EEPROM_DEFAULT_DIFF;
  1074. pwrInfo5G->BW160_Diff[rfPath][TxCount] = EEPROM_DEFAULT_DIFF;
  1075. }
  1076. }
  1077. }
  1078. //pHalData->bNOPG = _TRUE;
  1079. return;
  1080. }
  1081. pHalData->bTXPowerDataReadFromEEPORM = _TRUE; //YJ,move,120316
  1082. for(rfPath = 0 ; rfPath < MAX_RF_PATH ; rfPath++)
  1083. {
  1084. // 2.4G default value
  1085. for(group = 0 ; group < MAX_CHNL_GROUP_24G; group++)
  1086. {
  1087. pwrInfo24G->IndexCCK_Base[rfPath][group] = PROMContent[eeAddr++];
  1088. if(pwrInfo24G->IndexCCK_Base[rfPath][group] == 0xFF)
  1089. {
  1090. pwrInfo24G->IndexCCK_Base[rfPath][group] = EEPROM_DEFAULT_24G_INDEX;
  1091. //pHalData->bNOPG = _TRUE;
  1092. }
  1093. //DBG_871X("8812-2G RF-%d-G-%d CCK-Addr-%x BASE=%x\n",
  1094. //rfPath, group, eeAddr-1, pwrInfo24G->IndexCCK_Base[rfPath][group]);
  1095. }
  1096. for(group = 0 ; group < MAX_CHNL_GROUP_24G-1; group++)
  1097. {
  1098. pwrInfo24G->IndexBW40_Base[rfPath][group] = PROMContent[eeAddr++];
  1099. if(pwrInfo24G->IndexBW40_Base[rfPath][group] == 0xFF)
  1100. pwrInfo24G->IndexBW40_Base[rfPath][group] = EEPROM_DEFAULT_24G_INDEX;
  1101. //DBG_871X("8812-2G RF-%d-G-%d BW40-Addr-%x BASE=%x\n",
  1102. //rfPath, group, eeAddr-1, pwrInfo24G->IndexBW40_Base[rfPath][group]);
  1103. }
  1104. for(TxCount=0;TxCount<MAX_TX_COUNT;TxCount++)
  1105. {
  1106. if(TxCount==0)
  1107. {
  1108. pwrInfo24G->BW40_Diff[rfPath][TxCount] = 0;
  1109. {
  1110. pwrInfo24G->BW20_Diff[rfPath][TxCount] = (PROMContent[eeAddr]&0xf0)>>4;
  1111. if(pwrInfo24G->BW20_Diff[rfPath][TxCount] & BIT3) //4bit sign number to 8 bit sign number
  1112. pwrInfo24G->BW20_Diff[rfPath][TxCount] |= 0xF0;
  1113. }
  1114. //DBG_871X("8812-2G RF-%d-SS-%d BW20-Addr-%x DIFF=%d\n",
  1115. //rfPath, TxCount, eeAddr, pwrInfo24G->BW20_Diff[rfPath][TxCount]);
  1116. {
  1117. pwrInfo24G->OFDM_Diff[rfPath][TxCount] = (PROMContent[eeAddr]&0x0f);
  1118. if(pwrInfo24G->OFDM_Diff[rfPath][TxCount] & BIT3) //4bit sign number to 8 bit sign number
  1119. pwrInfo24G->OFDM_Diff[rfPath][TxCount] |= 0xF0;
  1120. }
  1121. //DBG_871X("8812-2G RF-%d-SS-%d LGOD-Addr-%x DIFF=%d\n",
  1122. //rfPath, TxCount, eeAddr, pwrInfo24G->OFDM_Diff[rfPath][TxCount]);
  1123. pwrInfo24G->CCK_Diff[rfPath][TxCount] = 0;
  1124. eeAddr++;
  1125. }
  1126. else
  1127. {
  1128. {
  1129. pwrInfo24G->BW40_Diff[rfPath][TxCount] = (PROMContent[eeAddr]&0xf0)>>4;
  1130. if(pwrInfo24G->BW40_Diff[rfPath][TxCount] & BIT3) //4bit sign number to 8 bit sign number
  1131. pwrInfo24G->BW40_Diff[rfPath][TxCount] |= 0xF0;
  1132. }
  1133. //DBG_871X("8812-2G RF-%d-SS-%d BW40-Addr-%x DIFF=%d\n",
  1134. //rfPath, TxCount, eeAddr, pwrInfo24G->BW40_Diff[rfPath][TxCount]);
  1135. {
  1136. pwrInfo24G->BW20_Diff[rfPath][TxCount] = (PROMContent[eeAddr]&0x0f);
  1137. if(pwrInfo24G->BW20_Diff[rfPath][TxCount] & BIT3) //4bit sign number to 8 bit sign number
  1138. pwrInfo24G->BW20_Diff[rfPath][TxCount] |= 0xF0;
  1139. }
  1140. //DBG_871X("8812-2G RF-%d-SS-%d BW20-Addr-%x DIFF=%d\n",
  1141. //rfPath, TxCount, eeAddr, pwrInfo24G->BW20_Diff[rfPath][TxCount]);
  1142. eeAddr++;
  1143. {
  1144. pwrInfo24G->OFDM_Diff[rfPath][TxCount] = (PROMContent[eeAddr]&0xf0)>>4;
  1145. if(pwrInfo24G->OFDM_Diff[rfPath][TxCount] & BIT3) //4bit sign number to 8 bit sign number
  1146. pwrInfo24G->OFDM_Diff[rfPath][TxCount] |= 0xF0;
  1147. }
  1148. //DBG_871X("8812-2G RF-%d-SS-%d LGOD-Addr-%x DIFF=%d\n",
  1149. //rfPath, TxCount, eeAddr, pwrInfo24G->BW20_Diff[rfPath][TxCount]);
  1150. {
  1151. pwrInfo24G->CCK_Diff[rfPath][TxCount] = (PROMContent[eeAddr]&0x0f);
  1152. if(pwrInfo24G->CCK_Diff[rfPath][TxCount] & BIT3) //4bit sign number to 8 bit sign number
  1153. pwrInfo24G->CCK_Diff[rfPath][TxCount] |= 0xF0;
  1154. }
  1155. //DBG_871X("8812-2G RF-%d-SS-%d CCK-Addr-%x DIFF=%d\n",
  1156. //rfPath, TxCount, eeAddr, pwrInfo24G->CCK_Diff[rfPath][TxCount]);
  1157. eeAddr++;
  1158. }
  1159. }
  1160. //5G default value
  1161. for(group = 0 ; group < MAX_CHNL_GROUP_5G; group++)
  1162. {
  1163. pwrInfo5G->IndexBW40_Base[rfPath][group] = PROMContent[eeAddr++];
  1164. if(pwrInfo5G->IndexBW40_Base[rfPath][group] == 0xFF)
  1165. pwrInfo5G->IndexBW40_Base[rfPath][group] = EEPROM_DEFAULT_DIFF;
  1166. //DBG_871X("8812-5G RF-%d-G-%d BW40-Addr-%x BASE=%x\n",
  1167. // rfPath, TxCount, eeAddr-1, pwrInfo5G->IndexBW40_Base[rfPath][group]);
  1168. }
  1169. for(TxCount=0;TxCount<MAX_TX_COUNT;TxCount++)
  1170. {
  1171. if(TxCount==0)
  1172. {
  1173. pwrInfo5G->BW40_Diff[rfPath][TxCount]= 0;
  1174. {
  1175. pwrInfo5G->BW20_Diff[rfPath][0] = (PROMContent[eeAddr]&0xf0)>>4;
  1176. if(pwrInfo5G->BW20_Diff[rfPath][TxCount] & BIT3) //4bit sign number to 8 bit sign number
  1177. pwrInfo5G->BW20_Diff[rfPath][TxCount] |= 0xF0;
  1178. }
  1179. //DBG_871X("8812-5G RF-%d-SS-%d BW20-Addr-%x DIFF=%d\n",
  1180. //rfPath, TxCount, eeAddr, pwrInfo5G->BW20_Diff[rfPath][TxCount]);
  1181. {
  1182. pwrInfo5G->OFDM_Diff[rfPath][0] = (PROMContent[eeAddr]&0x0f);
  1183. if(pwrInfo5G->OFDM_Diff[rfPath][TxCount] & BIT3) //4bit sign number to 8 bit sign number
  1184. pwrInfo5G->OFDM_Diff[rfPath][TxCount] |= 0xF0;
  1185. }
  1186. //DBG_871X("8812-5G RF-%d-SS-%d LGOD-Addr-%x DIFF=%d\n",
  1187. //rfPath, TxCount, eeAddr, pwrInfo5G->OFDM_Diff[rfPath][TxCount]);
  1188. eeAddr++;
  1189. }
  1190. else
  1191. {
  1192. {
  1193. pwrInfo5G->BW40_Diff[rfPath][TxCount]= (PROMContent[eeAddr]&0xf0)>>4;
  1194. if(pwrInfo5G->BW40_Diff[rfPath][TxCount] & BIT3) //4bit sign number to 8 bit sign number
  1195. pwrInfo5G->BW40_Diff[rfPath][TxCount] |= 0xF0;
  1196. }
  1197. //DBG_871X("8812-5G RF-%d-SS-%d BW40-Addr-%x DIFF=%d\n",
  1198. //rfPath, TxCount, eeAddr, pwrInfo5G->BW40_Diff[rfPath][TxCount]);
  1199. {
  1200. pwrInfo5G->BW20_Diff[rfPath][TxCount] = (PROMContent[eeAddr]&0x0f);
  1201. if(pwrInfo5G->BW20_Diff[rfPath][TxCount] & BIT3) //4bit sign number to 8 bit sign number
  1202. pwrInfo5G->BW20_Diff[rfPath][TxCount] |= 0xF0;
  1203. }
  1204. //DBG_871X("8812-5G RF-%d-SS-%d BW20-Addr-%x DIFF=%d\n",
  1205. //rfPath, TxCount, eeAddr, pwrInfo5G->BW20_Diff[rfPath][TxCount]);
  1206. eeAddr++;
  1207. }
  1208. }
  1209. {
  1210. pwrInfo5G->OFDM_Diff[rfPath][1] = (PROMContent[eeAddr]&0xf0)>>4;
  1211. pwrInfo5G->OFDM_Diff[rfPath][2] = (PROMContent[eeAddr]&0x0f);
  1212. }
  1213. //DBG_871X("8812-5G RF-%d-SS-%d LGOD-Addr-%x DIFF=%d\n",
  1214. // rfPath, 2, eeAddr, pwrInfo5G->OFDM_Diff[rfPath][2]);
  1215. eeAddr++;
  1216. pwrInfo5G->OFDM_Diff[rfPath][3] = (PROMContent[eeAddr]&0x0f);
  1217. //DBG_871X("8812-5G RF-%d-SS-%d LGOD-Addr-%x DIFF=%d\n",
  1218. //rfPath, 3, eeAddr, pwrInfo5G->OFDM_Diff[rfPath][3]);
  1219. eeAddr++;
  1220. for(TxCount=1;TxCount<MAX_TX_COUNT;TxCount++)
  1221. {
  1222. if(pwrInfo5G->OFDM_Diff[rfPath][TxCount] & BIT3) //4bit sign number to 8 bit sign number
  1223. pwrInfo5G->OFDM_Diff[rfPath][TxCount] |= 0xF0;
  1224. //DBG_871X("8812-5G RF-%d-SS-%d LGOD-Addr-%x DIFF=%d\n",
  1225. //rfPath, TxCount, eeAddr, pwrInfo5G->OFDM_Diff[rfPath][TxCount]);
  1226. }
  1227. for(TxCount=0;TxCount<MAX_TX_COUNT;TxCount++)
  1228. {
  1229. {
  1230. pwrInfo5G->BW80_Diff[rfPath][TxCount] = (PROMContent[eeAddr]&0xf0)>>4;
  1231. if(pwrInfo5G->BW80_Diff[rfPath][TxCount] & BIT3) //4bit sign number to 8 bit sign number
  1232. pwrInfo5G->BW80_Diff[rfPath][TxCount] |= 0xF0;
  1233. }
  1234. //DBG_871X("8812-5G RF-%d-SS-%d BW80-Addr-%x DIFF=%d\n",
  1235. //rfPath, TxCount, eeAddr, pwrInfo5G->BW80_Diff[rfPath][TxCount]);
  1236. {
  1237. pwrInfo5G->BW160_Diff[rfPath][TxCount]= (PROMContent[eeAddr]&0x0f);
  1238. if(pwrInfo5G->BW160_Diff[rfPath][TxCount] & BIT3) //4bit sign number to 8 bit sign number
  1239. pwrInfo5G->BW160_Diff[rfPath][TxCount] |= 0xF0;
  1240. }
  1241. //DBG_871X("8812-5G RF-%d-SS-%d BW160-Addr-%x DIFF=%d\n",
  1242. //rfPath, TxCount, eeAddr, pwrInfo5G->BW160_Diff[rfPath][TxCount]);
  1243. eeAddr++;
  1244. }
  1245. }
  1246. }
  1247. VOID
  1248. Hal_EfuseParseBTCoexistInfo8812A(
  1249. IN PADAPTER Adapter,
  1250. IN pu1Byte hwinfo,
  1251. IN BOOLEAN AutoLoadFail
  1252. )
  1253. {
  1254. #ifdef CONFIG_BT_COEXIST
  1255. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  1256. pHalData->EEPROMBluetoothCoexist = 0;
  1257. pHalData->EEPROMBluetoothType = BT_CSR_BC8;
  1258. pHalData->EEPROMBluetoothAntNum = Ant_x2;
  1259. pHalData->EEPROMBluetoothAntIsolation = 1;
  1260. pHalData->EEPROMBluetoothRadioShared = BT_Radio_Shared;
  1261. BT_InitHalVars(Adapter);
  1262. #endif
  1263. }
  1264. void
  1265. Hal_EfuseParseIDCode8812A(
  1266. IN PADAPTER padapter,
  1267. IN u8 *hwinfo
  1268. )
  1269. {
  1270. EEPROM_EFUSE_PRIV *pEEPROM = GET_EEPROM_EFUSE_PRIV(padapter);
  1271. u16 EEPROMId;
  1272. // Checl 0x8129 again for making sure autoload status!!
  1273. EEPROMId = le16_to_cpu(*((u16*)hwinfo));
  1274. if (EEPROMId != RTL_EEPROM_ID)
  1275. {
  1276. DBG_8192C("EEPROM ID(%#x) is invalid!!\n", EEPROMId);
  1277. pEEPROM->bautoload_fail_flag = _TRUE;
  1278. }
  1279. else
  1280. {
  1281. pEEPROM->bautoload_fail_flag = _FALSE;
  1282. }
  1283. DBG_8192C("EEPROM ID=0x%04x\n", EEPROMId);
  1284. }
  1285. VOID
  1286. Hal_ReadPROMVersion8812A(
  1287. IN PADAPTER Adapter,
  1288. IN u8* PROMContent,
  1289. IN BOOLEAN AutoloadFail
  1290. )
  1291. {
  1292. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  1293. if(AutoloadFail){
  1294. pHalData->EEPROMVersion = EEPROM_Default_Version;
  1295. }
  1296. else{
  1297. pHalData->EEPROMVersion = *(u8 *)&PROMContent[EEPROM_VERSION_8812];
  1298. if(pHalData->EEPROMVersion == 0xFF)
  1299. pHalData->EEPROMVersion = EEPROM_Default_Version;
  1300. }
  1301. //DBG_871X("pHalData->EEPROMVersion is 0x%x\n", pHalData->EEPROMVersion);
  1302. }
  1303. void
  1304. Hal_ReadTxPowerInfo8812A(
  1305. IN PADAPTER Adapter,
  1306. IN u8* PROMContent,
  1307. IN BOOLEAN AutoLoadFail
  1308. )
  1309. {
  1310. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  1311. TxPowerInfo24G pwrInfo24G;
  1312. TxPowerInfo5G pwrInfo5G;
  1313. u8 rfPath, ch, group, TxCount;
  1314. u8 channel5G[CHANNEL_MAX_NUMBER_5G] =
  1315. {36,38,40,42,44,46,48,50,52,54,56,58,60,62,64,100,102,104,106,108,110,112,
  1316. 114,116,118,120,122,124,126,128,130,132,134,136,138,140,142,144,149,151,
  1317. 153,155,157,159,161,163,165,167,168,169,171,173,175,177};
  1318. u8 channel5G_80M[CHANNEL_MAX_NUMBER_5G_80M] = {42, 58, 106, 122, 138, 155, 171};
  1319. hal_ReadPowerValueFromPROM8812A(Adapter, &pwrInfo24G,&pwrInfo5G, PROMContent, AutoLoadFail);
  1320. //if(!AutoLoadFail)
  1321. // pHalData->bTXPowerDataReadFromEEPORM = _TRUE;
  1322. for(rfPath = 0 ; rfPath < MAX_RF_PATH ; rfPath++)
  1323. {
  1324. for(ch = 0 ; ch < CHANNEL_MAX_NUMBER_2G ; ch++)
  1325. {
  1326. Hal_GetChnlGroup8812A(ch+1, &group);
  1327. if(ch == 14-1)
  1328. {
  1329. pHalData->Index24G_CCK_Base[rfPath][ch] = pwrInfo24G.IndexCCK_Base[rfPath][5];
  1330. pHalData->Index24G_BW40_Base[rfPath][ch] = pwrInfo24G.IndexBW40_Base[rfPath][group];
  1331. }
  1332. else
  1333. {
  1334. pHalData->Index24G_CCK_Base[rfPath][ch] = pwrInfo24G.IndexCCK_Base[rfPath][group];
  1335. pHalData->Index24G_BW40_Base[rfPath][ch] = pwrInfo24G.IndexBW40_Base[rfPath][group];
  1336. }
  1337. //DBG_871X("======= Path %d, ChannelIndex %d, Group %d=======\n",rfPath,ch, group);
  1338. //DBG_871X("Index24G_CCK_Base[%d][%d] = 0x%x\n",rfPath,ch ,pHalData->Index24G_CCK_Base[rfPath][ch]);
  1339. //DBG_871X("Index24G_BW40_Base[%d][%d] = 0x%x\n",rfPath,ch,pHalData->Index24G_BW40_Base[rfPath][ch]);
  1340. }
  1341. for(ch = 0 ; ch < CHANNEL_MAX_NUMBER_5G; ch++)
  1342. {
  1343. Hal_GetChnlGroup8812A(channel5G[ch], &group);
  1344. pHalData->Index5G_BW40_Base[rfPath][ch] = pwrInfo5G.IndexBW40_Base[rfPath][group];
  1345. //DBG_871X("======= Path %d, ChannelIndex %d, Group %d=======\n",rfPath,ch, group);
  1346. //DBG_871X("Index5G_BW40_Base[%d][%d] = 0x%x\n",rfPath,ch,pHalData->Index5G_BW40_Base[rfPath][ch]);
  1347. }
  1348. for(ch = 0 ; ch < CHANNEL_MAX_NUMBER_5G_80M; ch++)
  1349. {
  1350. u8 upper, lower;
  1351. Hal_GetChnlGroup8812A(channel5G_80M[ch], &group);
  1352. upper = pwrInfo5G.IndexBW40_Base[rfPath][group];
  1353. lower = pwrInfo5G.IndexBW40_Base[rfPath][group+1];
  1354. pHalData->Index5G_BW80_Base[rfPath][ch] = (upper + lower) / 2;
  1355. //DBG_871X("======= Path %d, ChannelIndex %d, Group %d=======\n",rfPath,ch, group);
  1356. //DBG_871X("Index5G_BW80_Base[%d][%d] = 0x%x\n",rfPath,ch,pHalData->Index5G_BW80_Base[rfPath][ch]);
  1357. }
  1358. for(TxCount=0;TxCount<MAX_TX_COUNT;TxCount++)
  1359. {
  1360. pHalData->CCK_24G_Diff[rfPath][TxCount]=pwrInfo24G.CCK_Diff[rfPath][TxCount];
  1361. pHalData->OFDM_24G_Diff[rfPath][TxCount]=pwrInfo24G.OFDM_Diff[rfPath][TxCount];
  1362. pHalData->BW20_24G_Diff[rfPath][TxCount]=pwrInfo24G.BW20_Diff[rfPath][TxCount];
  1363. pHalData->BW40_24G_Diff[rfPath][TxCount]=pwrInfo24G.BW40_Diff[rfPath][TxCount];
  1364. pHalData->OFDM_5G_Diff[rfPath][TxCount]=pwrInfo5G.OFDM_Diff[rfPath][TxCount];
  1365. pHalData->BW20_5G_Diff[rfPath][TxCount]=pwrInfo5G.BW20_Diff[rfPath][TxCount];
  1366. pHalData->BW40_5G_Diff[rfPath][TxCount]=pwrInfo5G.BW40_Diff[rfPath][TxCount];
  1367. pHalData->BW80_5G_Diff[rfPath][TxCount]=pwrInfo5G.BW80_Diff[rfPath][TxCount];
  1368. //#if DBG
  1369. #if 0
  1370. DBG_871X("--------------------------------------- 2.4G ---------------------------------------\n");
  1371. DBG_871X("CCK_24G_Diff[%d][%d]= %d\n",rfPath,TxCount,pHalData->CCK_24G_Diff[rfPath][TxCount]);
  1372. DBG_871X("OFDM_24G_Diff[%d][%d]= %d\n",rfPath,TxCount,pHalData->OFDM_24G_Diff[rfPath][TxCount]);
  1373. DBG_871X("BW20_24G_Diff[%d][%d]= %d\n",rfPath,TxCount,pHalData->BW20_24G_Diff[rfPath][TxCount]);
  1374. DBG_871X("BW40_24G_Diff[%d][%d]= %d\n",rfPath,TxCount,pHalData->BW40_24G_Diff[rfPath][TxCount]);
  1375. DBG_871X("---------------------------------------- 5G ----------------------------------------\n");
  1376. DBG_871X("OFDM_5G_Diff[%d][%d]= %d\n",rfPath,TxCount,pHalData->OFDM_5G_Diff[rfPath][TxCount]);
  1377. DBG_871X("BW20_5G_Diff[%d][%d]= %d\n",rfPath,TxCount,pHalData->BW20_5G_Diff[rfPath][TxCount]);
  1378. DBG_871X("BW40_5G_Diff[%d][%d]= %d\n",rfPath,TxCount,pHalData->BW40_5G_Diff[rfPath][TxCount]);
  1379. DBG_871X("BW80_5G_Diff[%d][%d]= %d\n",rfPath,TxCount,pHalData->BW80_5G_Diff[rfPath][TxCount]);
  1380. #endif
  1381. }
  1382. }
  1383. // 2010/10/19 MH Add Regulator recognize for CU.
  1384. if(!AutoLoadFail)
  1385. {
  1386. struct registry_priv *registry_par = &Adapter->registrypriv;
  1387. if( registry_par->regulatory_tid == 0xff){
  1388. if(PROMContent[EEPROM_RF_BOARD_OPTION_8812] == 0xFF)
  1389. pHalData->EEPROMRegulatory = (EEPROM_DEFAULT_BOARD_OPTION&0x7); //bit0~2
  1390. else
  1391. pHalData->EEPROMRegulatory = (PROMContent[EEPROM_RF_BOARD_OPTION_8812]&0x7); //bit0~2
  1392. }
  1393. else{
  1394. pHalData->EEPROMRegulatory = registry_par->regulatory_tid;
  1395. }
  1396. // 2012/09/26 MH Add for TX power calibrate rate.
  1397. pHalData->TxPwrCalibrateRate = PROMContent[EEPROM_TX_PWR_CALIBRATE_RATE_8812];
  1398. }
  1399. else
  1400. {
  1401. pHalData->EEPROMRegulatory = 0;
  1402. // 2012/09/26 MH Add for TX power calibrate rate.
  1403. pHalData->TxPwrCalibrateRate = EEPROM_DEFAULT_TX_CALIBRATE_RATE;
  1404. }
  1405. DBG_871X("EEPROMRegulatory = 0x%x TxPwrCalibrateRate=0x%x\n", pHalData->EEPROMRegulatory, pHalData->TxPwrCalibrateRate);
  1406. }
  1407. VOID
  1408. Hal_ReadBoardType8812A(
  1409. IN PADAPTER Adapter,
  1410. IN u8* PROMContent,
  1411. IN BOOLEAN AutoloadFail
  1412. )
  1413. {
  1414. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  1415. if(!AutoloadFail)
  1416. {
  1417. pHalData->InterfaceSel = (PROMContent[EEPROM_RF_BOARD_OPTION_8812]&0xE0)>>5;
  1418. if(PROMContent[EEPROM_RF_BOARD_OPTION_8812] == 0xFF)
  1419. pHalData->InterfaceSel = (EEPROM_DEFAULT_BOARD_OPTION&0xE0)>>5;
  1420. }
  1421. else
  1422. {
  1423. pHalData->InterfaceSel = 0;
  1424. }
  1425. DBG_871X("Board Type: 0x%2x\n", pHalData->InterfaceSel);
  1426. }
  1427. VOID
  1428. Hal_ReadThermalMeter_8812A(
  1429. IN PADAPTER Adapter,
  1430. IN u8* PROMContent,
  1431. IN BOOLEAN AutoloadFail
  1432. )
  1433. {
  1434. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  1435. //u8 tempval;
  1436. //
  1437. // ThermalMeter from EEPROM
  1438. //
  1439. if(!AutoloadFail)
  1440. pHalData->EEPROMThermalMeter = PROMContent[EEPROM_THERMAL_METER_8812];
  1441. else
  1442. pHalData->EEPROMThermalMeter = EEPROM_Default_ThermalMeter_8812;
  1443. //pHalData->EEPROMThermalMeter = (tempval&0x1f); //[4:0]
  1444. if(pHalData->EEPROMThermalMeter == 0xff || AutoloadFail)
  1445. {
  1446. pHalData->bAPKThermalMeterIgnore = _TRUE;
  1447. pHalData->EEPROMThermalMeter = 0xFF;
  1448. }
  1449. //pHalData->ThermalMeter[0] = pHalData->EEPROMThermalMeter;
  1450. DBG_871X("ThermalMeter = 0x%x\n", pHalData->EEPROMThermalMeter);
  1451. }
  1452. VOID
  1453. Hal_ReadChannelPlan8812A(
  1454. IN PADAPTER padapter,
  1455. IN u8* hwinfo,
  1456. IN BOOLEAN AutoLoadFail
  1457. )
  1458. {
  1459. padapter->mlmepriv.ChannelPlan = hal_com_get_channel_plan(
  1460. padapter
  1461. , hwinfo?hwinfo[EEPROM_ChannelPlan_8812]:0xFF
  1462. , padapter->registrypriv.channel_plan
  1463. , RT_CHANNEL_DOMAIN_REALTEK_DEFINE
  1464. , AutoLoadFail
  1465. );
  1466. DBG_871X("mlmepriv.ChannelPlan = 0x%02x\n", padapter->mlmepriv.ChannelPlan);
  1467. }
  1468. VOID
  1469. Hal_EfuseParseXtal_8812A(
  1470. IN PADAPTER pAdapter,
  1471. IN u8* hwinfo,
  1472. IN BOOLEAN AutoLoadFail
  1473. )
  1474. {
  1475. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(pAdapter);
  1476. if(!AutoLoadFail)
  1477. {
  1478. pHalData->CrystalCap = hwinfo[EEPROM_XTAL_8812];
  1479. if(pHalData->CrystalCap == 0xFF)
  1480. pHalData->CrystalCap = EEPROM_Default_CrystalCap_8812; //what value should 8812 set?
  1481. }
  1482. else
  1483. {
  1484. pHalData->CrystalCap = EEPROM_Default_CrystalCap_8812;
  1485. }
  1486. DBG_871X("CrystalCap: 0x%2x\n", pHalData->CrystalCap);
  1487. }
  1488. VOID
  1489. Hal_ReadAntennaDiversity8812A(
  1490. IN PADAPTER pAdapter,
  1491. IN u8* PROMContent,
  1492. IN BOOLEAN AutoLoadFail
  1493. )
  1494. {
  1495. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(pAdapter);
  1496. struct registry_priv *registry_par = &pAdapter->registrypriv;
  1497. if(!AutoLoadFail)
  1498. {
  1499. // Antenna Diversity setting.
  1500. if(registry_par->antdiv_cfg == 2)
  1501. {
  1502. pHalData->AntDivCfg = (PROMContent[EEPROM_RF_BOARD_OPTION_8812]&0x18)>>3;
  1503. if(PROMContent[EEPROM_RF_BOARD_OPTION_8812] == 0xFF)
  1504. pHalData->AntDivCfg = (EEPROM_DEFAULT_BOARD_OPTION&0x18)>>3;;
  1505. }
  1506. else
  1507. {
  1508. pHalData->AntDivCfg = registry_par->antdiv_cfg;
  1509. }
  1510. if(pHalData->EEPROMBluetoothCoexist!=0 && pHalData->EEPROMBluetoothAntNum==Ant_x1)
  1511. pHalData->AntDivCfg = 0;
  1512. pHalData->TRxAntDivType = PROMContent[EEPROM_RF_ANTENNA_OPT_8812]; //todo by page
  1513. if (pHalData->TRxAntDivType == 0xFF)
  1514. pHalData->TRxAntDivType = FIXED_HW_ANTDIV; // For 88EE, 1Tx and 1RxCG are fixed.(1Ant, Tx and RxCG are both on aux port)
  1515. }
  1516. else
  1517. {
  1518. pHalData->AntDivCfg = 0;
  1519. //pHalData->TRxAntDivType = pHalData->TRxAntDivType; // ?????
  1520. }
  1521. DBG_871X("SWAS: bHwAntDiv = %x, TRxAntDivType = %x\n", pHalData->AntDivCfg, pHalData->TRxAntDivType);
  1522. }
  1523. VOID
  1524. Hal_ReadPAType_8812A(
  1525. IN PADAPTER Adapter,
  1526. IN u8* PROMContent,
  1527. IN BOOLEAN AutoloadFail
  1528. )
  1529. {
  1530. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  1531. if( ! AutoloadFail )
  1532. {
  1533. if (GetRegAmplifierType2G(Adapter) == 0) // AUTO
  1534. {
  1535. pHalData->PAType_2G = EF1Byte( *(u8 *)&PROMContent[EEPROM_PA_TYPE_8812AU] );
  1536. pHalData->LNAType_2G = EF1Byte( *(u8 *)&PROMContent[EEPROM_LNA_TYPE_2G_8812AU] );
  1537. if (pHalData->PAType_2G == 0xFF && pHalData->LNAType_2G == 0xFF) {
  1538. pHalData->PAType_2G = 0;
  1539. pHalData->LNAType_2G = 0;
  1540. }
  1541. pHalData->ExternalPA_2G = ((pHalData->PAType_2G & BIT5) && (pHalData->PAType_2G & BIT4)) ? 1 : 0;
  1542. pHalData->ExternalLNA_2G = ((pHalData->LNAType_2G & BIT7) && (pHalData->LNAType_2G & BIT3)) ? 1 : 0;
  1543. }
  1544. else
  1545. {
  1546. pHalData->ExternalPA_2G = (GetRegAmplifierType2G(Adapter)&ODM_BOARD_EXT_PA) ? 1 : 0;
  1547. pHalData->ExternalLNA_2G = (GetRegAmplifierType2G(Adapter)&ODM_BOARD_EXT_LNA) ? 1 : 0;
  1548. }
  1549. if (GetRegAmplifierType5G(Adapter) == 0) // AUTO
  1550. {
  1551. pHalData->PAType_5G = EF1Byte( *(u8 *)&PROMContent[EEPROM_PA_TYPE_8812AU] );
  1552. pHalData->LNAType_5G = EF1Byte( *(u8 *)&PROMContent[EEPROM_LNA_TYPE_5G_8812AU] );
  1553. if (pHalData->PAType_5G == 0xFF && pHalData->LNAType_5G == 0xFF) {
  1554. pHalData->PAType_5G = 0;
  1555. pHalData->LNAType_5G = 0;
  1556. }
  1557. pHalData->ExternalPA_5G = ((pHalData->PAType_5G & BIT1) && (pHalData->PAType_5G & BIT0)) ? 1 : 0;
  1558. pHalData->ExternalLNA_5G = ((pHalData->LNAType_5G & BIT7) && (pHalData->LNAType_5G & BIT3)) ? 1 : 0;
  1559. }
  1560. else
  1561. {
  1562. pHalData->ExternalPA_5G = (GetRegAmplifierType5G(Adapter)&ODM_BOARD_EXT_PA_5G) ? 1 : 0;
  1563. pHalData->ExternalLNA_5G = (GetRegAmplifierType5G(Adapter)&ODM_BOARD_EXT_LNA_5G) ? 1 : 0;
  1564. }
  1565. }
  1566. else
  1567. {
  1568. pHalData->ExternalPA_2G = EEPROM_Default_PAType;
  1569. pHalData->ExternalPA_5G = 0xFF;
  1570. pHalData->ExternalLNA_2G = EEPROM_Default_LNAType;
  1571. pHalData->ExternalLNA_5G = 0xFF;
  1572. if (GetRegAmplifierType2G(Adapter) == 0) // AUTO
  1573. {
  1574. pHalData->ExternalPA_2G = 0;
  1575. pHalData->ExternalLNA_2G = 0;
  1576. }
  1577. else
  1578. {
  1579. pHalData->ExternalPA_2G = (GetRegAmplifierType2G(Adapter)&ODM_BOARD_EXT_PA) ? 1 : 0;
  1580. pHalData->ExternalLNA_2G = (GetRegAmplifierType2G(Adapter)&ODM_BOARD_EXT_LNA) ? 1 : 0;
  1581. }
  1582. if (GetRegAmplifierType5G(Adapter) == 0) // AUTO
  1583. {
  1584. pHalData->ExternalPA_5G = 0;
  1585. pHalData->ExternalLNA_5G = 0;
  1586. }
  1587. else
  1588. {
  1589. pHalData->ExternalPA_5G = (GetRegAmplifierType5G(Adapter)&ODM_BOARD_EXT_PA_5G) ? 1 : 0;
  1590. pHalData->ExternalLNA_5G = (GetRegAmplifierType5G(Adapter)&ODM_BOARD_EXT_LNA_5G) ? 1 : 0;
  1591. }
  1592. }
  1593. DBG_871X("pHalData->PAType_2G is 0x%x, pHalData->ExternalPA_2G = %d\n", pHalData->PAType_2G, pHalData->ExternalPA_2G);
  1594. DBG_871X("pHalData->PAType_5G is 0x%x, pHalData->ExternalPA_5G = %d\n", pHalData->PAType_5G, pHalData->ExternalPA_5G);
  1595. DBG_871X("pHalData->LNAType_2G is 0x%x, pHalData->ExternalLNA_2G = %d\n", pHalData->LNAType_2G, pHalData->ExternalLNA_2G);
  1596. DBG_871X("pHalData->LNAType_5G is 0x%x, pHalData->ExternalLNA_5G = %d\n", pHalData->LNAType_5G, pHalData->ExternalLNA_5G);
  1597. }
  1598. VOID
  1599. Hal_ReadPAType_8821A(
  1600. IN PADAPTER Adapter,
  1601. IN u8* PROMContent,
  1602. IN BOOLEAN AutoloadFail
  1603. )
  1604. {
  1605. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  1606. if( ! AutoloadFail )
  1607. {
  1608. if (GetRegAmplifierType2G(Adapter) == 0) // AUTO
  1609. {
  1610. pHalData->PAType_2G = EF1Byte( *(u8 *)&PROMContent[EEPROM_PA_TYPE_8812AU] );
  1611. pHalData->LNAType_2G = EF1Byte( *(u8 *)&PROMContent[EEPROM_LNA_TYPE_2G_8812AU] );
  1612. if (pHalData->PAType_2G == 0xFF && pHalData->LNAType_2G == 0xFF) {
  1613. pHalData->PAType_2G = 0;
  1614. pHalData->LNAType_2G = 0;
  1615. }
  1616. pHalData->ExternalPA_2G = (pHalData->PAType_2G & BIT4) ? 1 : 0;
  1617. pHalData->ExternalLNA_2G = (pHalData->LNAType_2G & BIT3) ? 1 : 0;
  1618. }
  1619. else
  1620. {
  1621. pHalData->ExternalPA_2G = (GetRegAmplifierType2G(Adapter)&ODM_BOARD_EXT_PA) ? 1 : 0;
  1622. pHalData->ExternalLNA_2G = (GetRegAmplifierType2G(Adapter)&ODM_BOARD_EXT_LNA) ? 1 : 0;
  1623. }
  1624. if (GetRegAmplifierType5G(Adapter) == 0) // AUTO
  1625. {
  1626. pHalData->PAType_5G = EF1Byte( *(u8 *)&PROMContent[EEPROM_PA_TYPE_8812AU] );
  1627. pHalData->LNAType_5G = EF1Byte( *(u8 *)&PROMContent[EEPROM_LNA_TYPE_5G_8812AU] );
  1628. if (pHalData->PAType_5G == 0xFF && pHalData->LNAType_5G == 0xFF) {
  1629. pHalData->PAType_5G = 0;
  1630. pHalData->LNAType_5G = 0;
  1631. }
  1632. pHalData->ExternalPA_5G = (pHalData->PAType_5G & BIT0) ? 1 : 0;
  1633. pHalData->ExternalLNA_5G = (pHalData->LNAType_5G & BIT3) ? 1 : 0;
  1634. }
  1635. else
  1636. {
  1637. pHalData->ExternalPA_5G = (GetRegAmplifierType5G(Adapter)&ODM_BOARD_EXT_PA_5G) ? 1 : 0;
  1638. pHalData->ExternalLNA_5G = (GetRegAmplifierType5G(Adapter)&ODM_BOARD_EXT_LNA_5G) ? 1 : 0;
  1639. }
  1640. }
  1641. else
  1642. {
  1643. pHalData->ExternalPA_2G = EEPROM_Default_PAType;
  1644. pHalData->ExternalPA_5G = 0xFF;
  1645. pHalData->ExternalLNA_2G = EEPROM_Default_LNAType;
  1646. pHalData->ExternalLNA_5G = 0xFF;
  1647. if (GetRegAmplifierType2G(Adapter) == 0) // AUTO
  1648. {
  1649. pHalData->ExternalPA_2G = 0;
  1650. pHalData->ExternalLNA_2G = 0;
  1651. }
  1652. else
  1653. {
  1654. pHalData->ExternalPA_2G = (GetRegAmplifierType2G(Adapter)&ODM_BOARD_EXT_PA) ? 1 : 0;
  1655. pHalData->ExternalLNA_2G = (GetRegAmplifierType2G(Adapter)&ODM_BOARD_EXT_LNA) ? 1 : 0;
  1656. }
  1657. if (GetRegAmplifierType5G(Adapter) == 0) // AUTO
  1658. {
  1659. pHalData->ExternalPA_5G = 0;
  1660. pHalData->ExternalLNA_5G = 0;
  1661. }
  1662. else
  1663. {
  1664. pHalData->ExternalPA_5G = (GetRegAmplifierType5G(Adapter)&ODM_BOARD_EXT_PA_5G) ? 1 : 0;
  1665. pHalData->ExternalLNA_5G = (GetRegAmplifierType5G(Adapter)&ODM_BOARD_EXT_LNA_5G) ? 1 : 0;
  1666. }
  1667. }
  1668. DBG_871X("pHalData->PAType_2G is 0x%x, pHalData->ExternalPA_2G = %d\n", pHalData->PAType_2G, pHalData->ExternalPA_2G);
  1669. DBG_871X("pHalData->PAType_5G is 0x%x, pHalData->ExternalPA_5G = %d\n", pHalData->PAType_5G, pHalData->ExternalPA_5G);
  1670. DBG_871X("pHalData->LNAType_2G is 0x%x, pHalData->ExternalLNA_2G = %d\n", pHalData->LNAType_2G, pHalData->ExternalLNA_2G);
  1671. DBG_871X("pHalData->LNAType_5G is 0x%x, pHalData->ExternalLNA_5G = %d\n", pHalData->LNAType_5G, pHalData->ExternalLNA_5G);
  1672. }
  1673. VOID
  1674. Hal_ReadRFEType_8812A(
  1675. IN PADAPTER Adapter,
  1676. IN u8* PROMContent,
  1677. IN BOOLEAN AutoloadFail
  1678. )
  1679. {
  1680. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  1681. if(!AutoloadFail)
  1682. {
  1683. if(GetRegRFEType(Adapter) != 64)
  1684. pHalData->RFEType = GetRegRFEType(Adapter);
  1685. else if(PROMContent[EEPROM_RFE_OPTION_8812] & BIT7)
  1686. {
  1687. if(pHalData->ExternalLNA_5G)
  1688. {
  1689. if(pHalData->ExternalPA_5G)
  1690. {
  1691. if(pHalData->ExternalLNA_2G && pHalData->ExternalPA_2G )
  1692. pHalData->RFEType = 3;
  1693. else
  1694. pHalData->RFEType = 0;
  1695. }
  1696. else
  1697. pHalData->RFEType = 2;
  1698. }
  1699. else
  1700. pHalData->RFEType = 4;
  1701. }
  1702. else
  1703. {
  1704. pHalData->RFEType = PROMContent[EEPROM_RFE_OPTION_8812]&0x3F;
  1705. // 2013/03/19 MH Due to othe customer already use incorrect EFUSE map
  1706. // to for their product. We need to add workaround to prevent to modify
  1707. // spec and notify all customer to revise the IC 0xca content. After
  1708. // discussing with Willis an YN, revise driver code to prevent.
  1709. if (pHalData->RFEType == 4 &&
  1710. (pHalData->ExternalPA_5G == _TRUE || pHalData->ExternalPA_2G == _TRUE ||
  1711. pHalData->ExternalLNA_5G == _TRUE || pHalData->ExternalLNA_2G == _TRUE))
  1712. {
  1713. if (IS_HARDWARE_TYPE_8812AU(Adapter))
  1714. pHalData->RFEType = 0;
  1715. else if (IS_HARDWARE_TYPE_8812E(Adapter))
  1716. pHalData->RFEType = 2;
  1717. }
  1718. }
  1719. }
  1720. else
  1721. {
  1722. if(GetRegRFEType(Adapter) != 64)
  1723. pHalData->RFEType = GetRegRFEType(Adapter);
  1724. else
  1725. pHalData->RFEType = EEPROM_DEFAULT_RFE_OPTION;
  1726. }
  1727. DBG_871X("RFE Type: 0x%2x\n", pHalData->RFEType);
  1728. }
  1729. //
  1730. // 2013/04/15 MH Add 8812AU- VL/VS/VN for different board type.
  1731. //
  1732. VOID
  1733. hal_ReadUsbType_8812AU(
  1734. IN PADAPTER Adapter,
  1735. IN u8 *PROMContent,
  1736. IN BOOLEAN AutoloadFail
  1737. )
  1738. {
  1739. //if (IS_HARDWARE_TYPE_8812AU(Adapter) && Adapter->UsbModeMechanism.RegForcedUsbMode == 5)
  1740. {
  1741. PHAL_DATA_TYPE pHalData = GET_HAL_DATA(Adapter);
  1742. u8 reg_tmp, i, j, antenna = 0, wmode = 0;
  1743. // Read anenna type from EFUSE 1019/1018
  1744. for (i = 0; i < 2; i++)
  1745. {
  1746. // Check efuse address 1019
  1747. // Check efuse address 1018
  1748. efuse_OneByteRead(Adapter, 1019-i, &reg_tmp, _FALSE);
  1749. for (j = 0; j < 2; j++)
  1750. {
  1751. // CHeck bit 7-5
  1752. // Check bit 3-1
  1753. antenna = ((reg_tmp&0xee) >> (5-(j*4)));
  1754. if (antenna == 0)
  1755. continue;
  1756. else
  1757. {
  1758. break;
  1759. }
  1760. }
  1761. }
  1762. // Read anenna type from EFUSE 1021/1020
  1763. for (i = 0; i < 2; i++)
  1764. {
  1765. // Check efuse address 1019
  1766. // Check efuse address 1018
  1767. efuse_OneByteRead(Adapter, 1021-i, &reg_tmp, _FALSE);
  1768. for (j = 0; j < 2; j++)
  1769. {
  1770. // CHeck bit 3-2
  1771. // Check bit 1-0
  1772. wmode = ((reg_tmp&0x0f) >> (2-(j*2)));
  1773. if (wmode)
  1774. continue;
  1775. else
  1776. {
  1777. break;
  1778. }
  1779. }
  1780. }
  1781. // Antenna == 1 WMODE = 3 RTL8812AU-VL 11AC + USB2.0 Mode
  1782. if (antenna == 1)
  1783. {
  1784. // Config 8812AU as 1*1 mode AC mode.
  1785. pHalData->rf_type = RF_1T1R;
  1786. //UsbModeSwitch_SetUsbModeMechOn(Adapter, FALSE);
  1787. //pHalData->EFUSEHidden = EFUSE_HIDDEN_812AU_VL;
  1788. DBG_871X("%s(): EFUSE_HIDDEN_812AU_VL\n",__FUNCTION__);
  1789. }
  1790. else if (antenna == 2)
  1791. {
  1792. if (wmode == 3)
  1793. {
  1794. if (PROMContent[EEPROM_USB_MODE_8812] == 0x2)
  1795. {
  1796. // RTL8812AU Normal Mode. No further action.
  1797. //pHalData->EFUSEHidden = EFUSE_HIDDEN_812AU;
  1798. DBG_871X("%s(): EFUSE_HIDDEN_812AU\n",__FUNCTION__);
  1799. }
  1800. else
  1801. {
  1802. // Antenna == 2 WMODE = 3 RTL8812AU-VS 11AC + USB2.0 Mode
  1803. // Driver will not support USB automatic switch
  1804. //UsbModeSwitch_SetUsbModeMechOn(Adapter, FALSE);
  1805. //pHalData->EFUSEHidden = EFUSE_HIDDEN_812AU_VS;
  1806. DBG_871X("%s(): EFUSE_HIDDEN_812AU_VS\n",__FUNCTION__);
  1807. }
  1808. }
  1809. else if (wmode == 2)
  1810. {
  1811. // Antenna == 2 WMODE = 2 RTL8812AU-VN 11N only + USB2.0 Mode
  1812. //UsbModeSwitch_SetUsbModeMechOn(Adapter, FALSE);
  1813. //pHalData->EFUSEHidden = EFUSE_HIDDEN_812AU_VN;
  1814. DBG_871X("%s(): EFUSE_HIDDEN_812AU_VN\n",__FUNCTION__);
  1815. }
  1816. }
  1817. }
  1818. }
  1819. enum{
  1820. VOLTAGE_V25 = 0x03,
  1821. LDOE25_SHIFT = 28 ,
  1822. };
  1823. static VOID
  1824. Hal_EfusePowerSwitch8812A(
  1825. IN PADAPTER pAdapter,
  1826. IN u8 bWrite,
  1827. IN u8 PwrState)
  1828. {
  1829. u8 tempval;
  1830. u16 tmpV16;
  1831. #define EFUSE_ACCESS_ON_JAGUAR 0x69
  1832. #define EFUSE_ACCESS_OFF_JAGUAR 0x00
  1833. if (PwrState == _TRUE)
  1834. {
  1835. rtw_write8(pAdapter, REG_EFUSE_BURN_GNT_8812, EFUSE_ACCESS_ON_JAGUAR);
  1836. // 1.2V Power: From VDDON with Power Cut(0x0000h[15]), defualt valid
  1837. tmpV16 = rtw_read16(pAdapter,REG_SYS_ISO_CTRL);
  1838. if( ! (tmpV16 & PWC_EV12V ) ){
  1839. tmpV16 |= PWC_EV12V ;
  1840. //rtw_write16(pAdapter,REG_SYS_ISO_CTRL,tmpV16);
  1841. }
  1842. // Reset: 0x0000h[28], default valid
  1843. tmpV16 = rtw_read16(pAdapter,REG_SYS_FUNC_EN);
  1844. if( !(tmpV16 & FEN_ELDR) ){
  1845. tmpV16 |= FEN_ELDR ;
  1846. rtw_write16(pAdapter,REG_SYS_FUNC_EN,tmpV16);
  1847. }
  1848. // Clock: Gated(0x0008h[5]) 8M(0x0008h[1]) clock from ANA, default valid
  1849. tmpV16 = rtw_read16(pAdapter,REG_SYS_CLKR);
  1850. if( (!(tmpV16 & LOADER_CLK_EN) ) ||(!(tmpV16 & ANA8M) ) )
  1851. {
  1852. tmpV16 |= (LOADER_CLK_EN |ANA8M ) ;
  1853. rtw_write16(pAdapter,REG_SYS_CLKR,tmpV16);
  1854. }
  1855. if(bWrite == _TRUE)
  1856. {
  1857. // Enable LDO 2.5V before read/write action
  1858. tempval = rtw_read8(pAdapter, EFUSE_TEST+3);
  1859. tempval &= ~(BIT3|BIT4|BIT5|BIT6);
  1860. tempval |= (VOLTAGE_V25 << 3);
  1861. tempval |= BIT7;
  1862. rtw_write8(pAdapter, EFUSE_TEST+3, tempval);
  1863. }
  1864. }
  1865. else
  1866. {
  1867. rtw_write8(pAdapter, REG_EFUSE_BURN_GNT_8812, EFUSE_ACCESS_OFF_JAGUAR);
  1868. if(bWrite == _TRUE){
  1869. // Disable LDO 2.5V after read/write action
  1870. tempval = rtw_read8(pAdapter, EFUSE_TEST+3);
  1871. rtw_write8(pAdapter, EFUSE_TEST+3, (tempval & 0x7F));
  1872. }
  1873. }
  1874. }
  1875. static VOID
  1876. rtl8812_EfusePowerSwitch(
  1877. IN PADAPTER pAdapter,
  1878. IN u8 bWrite,
  1879. IN u8 PwrState)
  1880. {
  1881. Hal_EfusePowerSwitch8812A(pAdapter, bWrite, PwrState);
  1882. }
  1883. static BOOLEAN
  1884. Hal_EfuseSwitchToBank8812A(
  1885. IN PADAPTER pAdapter,
  1886. IN u1Byte bank,
  1887. IN BOOLEAN bPseudoTest
  1888. )
  1889. {
  1890. return _FALSE;
  1891. }
  1892. static VOID
  1893. Hal_EfuseReadEFuse8812A(
  1894. PADAPTER Adapter,
  1895. u16 _offset,
  1896. u16 _size_byte,
  1897. u8 *pbuf,
  1898. IN BOOLEAN bPseudoTest
  1899. )
  1900. {
  1901. u8 *efuseTbl = NULL;
  1902. u16 eFuse_Addr = 0;
  1903. u8 offset=0, wden=0;
  1904. u16 i, j;
  1905. u16 **eFuseWord = NULL;
  1906. u16 efuse_utilized = 0;
  1907. u8 efuse_usage = 0;
  1908. u8 offset_2_0=0;
  1909. u8 efuseHeader=0, efuseExtHdr=0, efuseData=0;
  1910. //
  1911. // Do NOT excess total size of EFuse table. Added by Roger, 2008.11.10.
  1912. //
  1913. if((_offset + _size_byte)>EFUSE_MAP_LEN_JAGUAR)
  1914. {// total E-Fuse table is 512bytes
  1915. DBG_8192C("Hal_EfuseReadEFuse8812A(): Invalid offset(%#x) with read bytes(%#x)!!\n",_offset, _size_byte);
  1916. goto exit;
  1917. }
  1918. efuseTbl = (u8*)rtw_zmalloc(EFUSE_MAP_LEN_JAGUAR);
  1919. if(efuseTbl == NULL)
  1920. {
  1921. DBG_871X("%s: alloc efuseTbl fail!\n", __FUNCTION__);
  1922. goto exit;
  1923. }
  1924. eFuseWord= (u16 **)rtw_malloc2d(EFUSE_MAX_SECTION_JAGUAR, EFUSE_MAX_WORD_UNIT, sizeof(u16));
  1925. if(eFuseWord == NULL)
  1926. {
  1927. DBG_871X("%s: alloc eFuseWord fail!\n", __FUNCTION__);
  1928. goto exit;
  1929. }
  1930. // 0. Refresh efuse init map as all oxFF.
  1931. for (i = 0; i < EFUSE_MAX_SECTION_JAGUAR; i++)
  1932. for (j = 0; j < EFUSE_MAX_WORD_UNIT; j++)
  1933. eFuseWord[i][j] = 0xFFFF;
  1934. //
  1935. // 1. Read the first byte to check if efuse is empty!!!
  1936. //
  1937. //
  1938. efuse_OneByteRead(Adapter, eFuse_Addr++, &efuseHeader, bPseudoTest);
  1939. if(efuseHeader != 0xFF)
  1940. {
  1941. efuse_utilized++;
  1942. }
  1943. else
  1944. {
  1945. DBG_871X("EFUSE is empty\n");
  1946. efuse_utilized = 0;
  1947. goto exit;
  1948. }
  1949. //RT_DISP(FEEPROM, EFUSE_READ_ALL, ("Hal_EfuseReadEFuse8812A(): efuse_utilized: %d\n", efuse_utilized));
  1950. //
  1951. // 2. Read real efuse content. Filter PG header and every section data.
  1952. //
  1953. while((efuseHeader != 0xFF) && AVAILABLE_EFUSE_ADDR_8812(eFuse_Addr))
  1954. {
  1955. //RTPRINT(FEEPROM, EFUSE_READ_ALL, ("efuse_Addr-%d efuse_data=%x\n", eFuse_Addr-1, *rtemp8));
  1956. // Check PG header for section num.
  1957. if(EXT_HEADER(efuseHeader)) //extended header
  1958. {
  1959. offset_2_0 = GET_HDR_OFFSET_2_0(efuseHeader);
  1960. //RT_DISP(FEEPROM, EFUSE_READ_ALL, ("extended header offset_2_0=%X\n", offset_2_0));
  1961. efuse_OneByteRead(Adapter, eFuse_Addr++, &efuseExtHdr, bPseudoTest);
  1962. //RT_DISP(FEEPROM, EFUSE_READ_ALL, ("efuse[%X]=%X\n", eFuse_Addr-1, efuseExtHdr));
  1963. if(efuseExtHdr != 0xff)
  1964. {
  1965. efuse_utilized++;
  1966. if(ALL_WORDS_DISABLED(efuseExtHdr))
  1967. {
  1968. efuse_OneByteRead(Adapter, eFuse_Addr++, &efuseHeader, bPseudoTest);
  1969. if(efuseHeader != 0xff)
  1970. {
  1971. efuse_utilized++;
  1972. }
  1973. break;
  1974. }
  1975. else
  1976. {
  1977. offset = ((efuseExtHdr & 0xF0) >> 1) | offset_2_0;
  1978. wden = (efuseExtHdr & 0x0F);
  1979. }
  1980. }
  1981. else
  1982. {
  1983. DBG_871X("Error condition, extended = 0xff\n");
  1984. // We should handle this condition.
  1985. break;
  1986. }
  1987. }
  1988. else
  1989. {
  1990. offset = ((efuseHeader >> 4) & 0x0f);
  1991. wden = (efuseHeader & 0x0f);
  1992. }
  1993. if(offset < EFUSE_MAX_SECTION_JAGUAR)
  1994. {
  1995. // Get word enable value from PG header
  1996. //RT_DISP(FEEPROM, EFUSE_READ_ALL, ("Offset-%X Worden=%X\n", offset, wden));
  1997. for(i=0; i<EFUSE_MAX_WORD_UNIT; i++)
  1998. {
  1999. // Check word enable condition in the section
  2000. if(!(wden & (0x01<<i)))
  2001. {
  2002. efuse_OneByteRead(Adapter, eFuse_Addr++, &efuseData, bPseudoTest);
  2003. //RT_DISP(FEEPROM, EFUSE_READ_ALL, ("efuse[%X]=%X\n", eFuse_Addr-1, efuseData));
  2004. efuse_utilized++;
  2005. eFuseWord[offset][i] = (efuseData & 0xff);
  2006. if(!AVAILABLE_EFUSE_ADDR_8812(eFuse_Addr))
  2007. break;
  2008. efuse_OneByteRead(Adapter, eFuse_Addr++, &efuseData, bPseudoTest);
  2009. //RT_DISP(FEEPROM, EFUSE_READ_ALL, ("efuse[%X]=%X\n", eFuse_Addr-1, efuseData));
  2010. efuse_utilized++;
  2011. eFuseWord[offset][i] |= (((u16)efuseData << 8) & 0xff00);
  2012. if(!AVAILABLE_EFUSE_ADDR_8812(eFuse_Addr))
  2013. break;
  2014. }
  2015. }
  2016. }
  2017. // Read next PG header
  2018. efuse_OneByteRead(Adapter, eFuse_Addr++, &efuseHeader, bPseudoTest);
  2019. //RTPRINT(FEEPROM, EFUSE_READ_ALL, ("Addr=%d rtemp 0x%x\n", eFuse_Addr, *rtemp8));
  2020. if(efuseHeader != 0xFF)
  2021. {
  2022. efuse_utilized++;
  2023. }
  2024. }
  2025. //
  2026. // 3. Collect 16 sections and 4 word unit into Efuse map.
  2027. //
  2028. for(i=0; i<EFUSE_MAX_SECTION_JAGUAR; i++)
  2029. {
  2030. for(j=0; j<EFUSE_MAX_WORD_UNIT; j++)
  2031. {
  2032. efuseTbl[(i*8)+(j*2)]=(eFuseWord[i][j] & 0xff);
  2033. efuseTbl[(i*8)+((j*2)+1)]=((eFuseWord[i][j] >> 8) & 0xff);
  2034. }
  2035. }
  2036. //RT_DISP(FEEPROM, EFUSE_READ_ALL, ("Hal_EfuseReadEFuse8812A(): efuse_utilized: %d\n", efuse_utilized));
  2037. //
  2038. // 4. Copy from Efuse map to output pointer memory!!!
  2039. //
  2040. for(i=0; i<_size_byte; i++)
  2041. {
  2042. pbuf[i] = efuseTbl[_offset+i];
  2043. }
  2044. //
  2045. // 5. Calculate Efuse utilization.
  2046. //
  2047. efuse_usage = (u1Byte)((eFuse_Addr*100)/EFUSE_REAL_CONTENT_LEN_JAGUAR);
  2048. rtw_hal_set_hwreg(Adapter, HW_VAR_EFUSE_BYTES, (u8 *)&eFuse_Addr);
  2049. exit:
  2050. if(efuseTbl)
  2051. rtw_mfree(efuseTbl, EFUSE_MAP_LEN_JAGUAR);
  2052. if(eFuseWord)
  2053. rtw_mfree2d((void *)eFuseWord, EFUSE_MAX_SECTION_JAGUAR, EFUSE_MAX_WORD_UNIT, sizeof(u16));
  2054. }
  2055. static VOID
  2056. rtl8812_ReadEFuse(
  2057. PADAPTER Adapter,
  2058. u8 efuseType,
  2059. u16 _offset,
  2060. u16 _size_byte,
  2061. u8 *pbuf,
  2062. IN BOOLEAN bPseudoTest
  2063. )
  2064. {
  2065. #ifdef DBG_IOL_READ_EFUSE_MAP
  2066. u8 logical_map[512];
  2067. #endif
  2068. #ifdef CONFIG_IOL_READ_EFUSE_MAP
  2069. if(!bPseudoTest )//&& rtw_IOL_applied(Adapter))
  2070. {
  2071. int ret = _FAIL;
  2072. rtw_hal_power_on(Adapter);
  2073. iol_mode_enable(Adapter, 1);
  2074. #ifdef DBG_IOL_READ_EFUSE_MAP
  2075. iol_read_efuse(Adapter, 0, _offset, _size_byte, logical_map);
  2076. #else
  2077. ret = iol_read_efuse(Adapter, 0, _offset, _size_byte, pbuf);
  2078. #endif
  2079. iol_mode_enable(Adapter, 0);
  2080. if(_SUCCESS == ret)
  2081. goto exit;
  2082. }
  2083. #endif
  2084. Hal_EfuseReadEFuse8812A(Adapter, _offset, _size_byte, pbuf, bPseudoTest);
  2085. #ifdef CONFIG_IOL_READ_EFUSE_MAP
  2086. exit:
  2087. #endif
  2088. #ifdef DBG_IOL_READ_EFUSE_MAP
  2089. if(_rtw_memcmp(logical_map, Adapter->eeprompriv.efuse_eeprom_data, 0x130) == _FALSE)
  2090. {
  2091. int i;
  2092. DBG_871X("%s compare first 0x130 byte fail\n", __FUNCTION__);
  2093. for(i=0;i<512;i++)
  2094. {
  2095. if(i%16==0)
  2096. DBG_871X("0x%03x: ", i);
  2097. DBG_871X("%02x ", logical_map[i]);
  2098. if(i%16==15)
  2099. DBG_871X("\n");
  2100. }
  2101. DBG_871X("\n");
  2102. }
  2103. #endif
  2104. }
  2105. //Do not support BT
  2106. VOID
  2107. Hal_EFUSEGetEfuseDefinition8812A(
  2108. IN PADAPTER pAdapter,
  2109. IN u1Byte efuseType,
  2110. IN u1Byte type,
  2111. OUT PVOID pOut
  2112. )
  2113. {
  2114. switch(type)
  2115. {
  2116. case TYPE_EFUSE_MAX_SECTION:
  2117. {
  2118. u8* pMax_section;
  2119. pMax_section = (u8*)pOut;
  2120. *pMax_section = EFUSE_MAX_SECTION_JAGUAR;
  2121. }
  2122. break;
  2123. case TYPE_EFUSE_REAL_CONTENT_LEN:
  2124. {
  2125. u16* pu2Tmp;
  2126. pu2Tmp = (u16*)pOut;
  2127. *pu2Tmp = EFUSE_REAL_CONTENT_LEN_JAGUAR;
  2128. }
  2129. break;
  2130. case TYPE_EFUSE_CONTENT_LEN_BANK:
  2131. {
  2132. u16* pu2Tmp;
  2133. pu2Tmp = (u16*)pOut;
  2134. *pu2Tmp = EFUSE_REAL_CONTENT_LEN_JAGUAR;
  2135. }
  2136. break;
  2137. case TYPE_AVAILABLE_EFUSE_BYTES_BANK:
  2138. {
  2139. u16* pu2Tmp;
  2140. pu2Tmp = (u16*)pOut;
  2141. *pu2Tmp = (u16)(EFUSE_REAL_CONTENT_LEN_JAGUAR-EFUSE_OOB_PROTECT_BYTES_JAGUAR);
  2142. }
  2143. break;
  2144. case TYPE_AVAILABLE_EFUSE_BYTES_TOTAL:
  2145. {
  2146. u16* pu2Tmp;
  2147. pu2Tmp = (u16*)pOut;
  2148. *pu2Tmp = (u16)(EFUSE_REAL_CONTENT_LEN_JAGUAR-EFUSE_OOB_PROTECT_BYTES_JAGUAR);
  2149. }
  2150. break;
  2151. case TYPE_EFUSE_MAP_LEN:
  2152. {
  2153. u16* pu2Tmp;
  2154. pu2Tmp = (u16*)pOut;
  2155. *pu2Tmp = (u16)EFUSE_MAP_LEN_JAGUAR;
  2156. }
  2157. break;
  2158. case TYPE_EFUSE_PROTECT_BYTES_BANK:
  2159. {
  2160. u8* pu1Tmp;
  2161. pu1Tmp = (u8*)pOut;
  2162. *pu1Tmp = (u8)(EFUSE_OOB_PROTECT_BYTES_JAGUAR);
  2163. }
  2164. break;
  2165. default:
  2166. {
  2167. u8* pu1Tmp;
  2168. pu1Tmp = (u8*)pOut;
  2169. *pu1Tmp = 0;
  2170. }
  2171. break;
  2172. }
  2173. }
  2174. VOID
  2175. Hal_EFUSEGetEfuseDefinition_Pseudo8812A(
  2176. IN PADAPTER pAdapter,
  2177. IN u8 efuseType,
  2178. IN u8 type,
  2179. OUT PVOID pOut
  2180. )
  2181. {
  2182. switch(type)
  2183. {
  2184. case TYPE_EFUSE_MAX_SECTION:
  2185. {
  2186. u8* pMax_section;
  2187. pMax_section = (pu1Byte)pOut;
  2188. *pMax_section = EFUSE_MAX_SECTION_JAGUAR;
  2189. }
  2190. break;
  2191. case TYPE_EFUSE_REAL_CONTENT_LEN:
  2192. {
  2193. u16* pu2Tmp;
  2194. pu2Tmp = (pu2Byte)pOut;
  2195. *pu2Tmp = EFUSE_REAL_CONTENT_LEN_JAGUAR;
  2196. }
  2197. break;
  2198. case TYPE_EFUSE_CONTENT_LEN_BANK:
  2199. {
  2200. u16* pu2Tmp;
  2201. pu2Tmp = (pu2Byte)pOut;
  2202. *pu2Tmp = EFUSE_REAL_CONTENT_LEN_JAGUAR;
  2203. }
  2204. break;
  2205. case TYPE_AVAILABLE_EFUSE_BYTES_BANK:
  2206. {
  2207. u16* pu2Tmp;
  2208. pu2Tmp = (pu2Byte)pOut;
  2209. *pu2Tmp = (u2Byte)(EFUSE_REAL_CONTENT_LEN_JAGUAR-EFUSE_OOB_PROTECT_BYTES_JAGUAR);
  2210. }
  2211. break;
  2212. case TYPE_AVAILABLE_EFUSE_BYTES_TOTAL:
  2213. {
  2214. u16* pu2Tmp;
  2215. pu2Tmp = (pu2Byte)pOut;
  2216. *pu2Tmp = (u2Byte)(EFUSE_REAL_CONTENT_LEN_JAGUAR-EFUSE_OOB_PROTECT_BYTES_JAGUAR);
  2217. }
  2218. break;
  2219. case TYPE_EFUSE_MAP_LEN:
  2220. {
  2221. u16* pu2Tmp;
  2222. pu2Tmp = (pu2Byte)pOut;
  2223. *pu2Tmp = (u2Byte)EFUSE_MAP_LEN_JAGUAR;
  2224. }
  2225. break;
  2226. case TYPE_EFUSE_PROTECT_BYTES_BANK:
  2227. {
  2228. u8* pu1Tmp;
  2229. pu1Tmp = (u8*)pOut;
  2230. *pu1Tmp = (u8)(EFUSE_OOB_PROTECT_BYTES_JAGUAR);
  2231. }
  2232. break;
  2233. default:
  2234. {
  2235. u8* pu1Tmp;
  2236. pu1Tmp = (u8*)pOut;
  2237. *pu1Tmp = 0;
  2238. }
  2239. break;
  2240. }
  2241. }
  2242. static VOID
  2243. rtl8812_EFUSE_GetEfuseDefinition(
  2244. IN PADAPTER pAdapter,
  2245. IN u8 efuseType,
  2246. IN u8 type,
  2247. OUT void *pOut,
  2248. IN BOOLEAN bPseudoTest
  2249. )
  2250. {
  2251. if(bPseudoTest)
  2252. {
  2253. Hal_EFUSEGetEfuseDefinition_Pseudo8812A(pAdapter, efuseType, type, pOut);
  2254. }
  2255. else
  2256. {
  2257. Hal_EFUSEGetEfuseDefinition8812A(pAdapter, efuseType, type, pOut);
  2258. }
  2259. }
  2260. static u8
  2261. Hal_EfuseWordEnableDataWrite8812A( IN PADAPTER pAdapter,
  2262. IN u16 efuse_addr,
  2263. IN u8 word_en,
  2264. IN u8 *data,
  2265. IN BOOLEAN bPseudoTest)
  2266. {
  2267. u16 tmpaddr = 0;
  2268. u16 start_addr = efuse_addr;
  2269. u8 badworden = 0x0F;
  2270. u8 tmpdata[8];
  2271. _rtw_memset((PVOID)tmpdata, 0xff, PGPKT_DATA_SIZE);
  2272. //RT_TRACE(COMP_EFUSE, DBG_LOUD, ("word_en = %x efuse_addr=%x\n", word_en, efuse_addr));
  2273. if(!(word_en&BIT0))
  2274. {
  2275. tmpaddr = start_addr;
  2276. efuse_OneByteWrite(pAdapter,start_addr++, data[0], bPseudoTest);
  2277. efuse_OneByteWrite(pAdapter,start_addr++, data[1], bPseudoTest);
  2278. efuse_OneByteRead(pAdapter,tmpaddr, &tmpdata[0], bPseudoTest);
  2279. efuse_OneByteRead(pAdapter,tmpaddr+1, &tmpdata[1], bPseudoTest);
  2280. if((data[0]!=tmpdata[0])||(data[1]!=tmpdata[1])){
  2281. badworden &= (~BIT0);
  2282. }
  2283. }
  2284. if(!(word_en&BIT1))
  2285. {
  2286. tmpaddr = start_addr;
  2287. efuse_OneByteWrite(pAdapter,start_addr++, data[2], bPseudoTest);
  2288. efuse_OneByteWrite(pAdapter,start_addr++, data[3], bPseudoTest);
  2289. efuse_OneByteRead(pAdapter,tmpaddr , &tmpdata[2], bPseudoTest);
  2290. efuse_OneByteRead(pAdapter,tmpaddr+1, &tmpdata[3], bPseudoTest);
  2291. if((data[2]!=tmpdata[2])||(data[3]!=tmpdata[3])){
  2292. badworden &=( ~BIT1);
  2293. }
  2294. }
  2295. if(!(word_en&BIT2))
  2296. {
  2297. tmpaddr = start_addr;
  2298. efuse_OneByteWrite(pAdapter,start_addr++, data[4], bPseudoTest);
  2299. efuse_OneByteWrite(pAdapter,start_addr++, data[5], bPseudoTest);
  2300. efuse_OneByteRead(pAdapter,tmpaddr, &tmpdata[4], bPseudoTest);
  2301. efuse_OneByteRead(pAdapter,tmpaddr+1, &tmpdata[5], bPseudoTest);
  2302. if((data[4]!=tmpdata[4])||(data[5]!=tmpdata[5])){
  2303. badworden &=( ~BIT2);
  2304. }
  2305. }
  2306. if(!(word_en&BIT3))
  2307. {
  2308. tmpaddr = start_addr;
  2309. efuse_OneByteWrite(pAdapter,start_addr++, data[6], bPseudoTest);
  2310. efuse_OneByteWrite(pAdapter,start_addr++, data[7], bPseudoTest);
  2311. efuse_OneByteRead(pAdapter,tmpaddr, &tmpdata[6], bPseudoTest);
  2312. efuse_OneByteRead(pAdapter,tmpaddr+1, &tmpdata[7], bPseudoTest);
  2313. if((data[6]!=tmpdata[6])||(data[7]!=tmpdata[7])){
  2314. badworden &=( ~BIT3);
  2315. }
  2316. }
  2317. return badworden;
  2318. }
  2319. static u8
  2320. rtl8812_Efuse_WordEnableDataWrite( IN PADAPTER pAdapter,
  2321. IN u16 efuse_addr,
  2322. IN u8 word_en,
  2323. IN u8 *data,
  2324. IN BOOLEAN bPseudoTest)
  2325. {
  2326. u8 ret=0;
  2327. ret = Hal_EfuseWordEnableDataWrite8812A(pAdapter, efuse_addr, word_en, data, bPseudoTest);
  2328. return ret;
  2329. }
  2330. static u16
  2331. hal_EfuseGetCurrentSize_8812A(IN PADAPTER pAdapter,
  2332. IN BOOLEAN bPseudoTest)
  2333. {
  2334. int bContinual = _TRUE;
  2335. u16 efuse_addr = 0;
  2336. u8 hoffset=0,hworden=0;
  2337. u8 efuse_data,word_cnts=0;
  2338. if(bPseudoTest)
  2339. {
  2340. efuse_addr = (u16)(fakeEfuseUsedBytes);
  2341. }
  2342. else
  2343. {
  2344. rtw_hal_get_hwreg(pAdapter, HW_VAR_EFUSE_BYTES, (u8 *)&efuse_addr);
  2345. }
  2346. //RTPRINT(FEEPROM, EFUSE_PG, ("hal_EfuseGetCurrentSize_8723A(), start_efuse_addr = %d\n", efuse_addr));
  2347. while ( bContinual &&
  2348. efuse_OneByteRead(pAdapter, efuse_addr ,&efuse_data, bPseudoTest) &&
  2349. (efuse_addr < EFUSE_REAL_CONTENT_LEN_JAGUAR))
  2350. {
  2351. if(efuse_data!=0xFF)
  2352. {
  2353. if((efuse_data&0x1F) == 0x0F) //extended header
  2354. {
  2355. hoffset = efuse_data;
  2356. efuse_addr++;
  2357. efuse_OneByteRead(pAdapter, efuse_addr ,&efuse_data, bPseudoTest);
  2358. if((efuse_data & 0x0F) == 0x0F)
  2359. {
  2360. efuse_addr++;
  2361. continue;
  2362. }
  2363. else
  2364. {
  2365. hoffset = ((hoffset & 0xE0) >> 5) | ((efuse_data & 0xF0) >> 1);
  2366. hworden = efuse_data & 0x0F;
  2367. }
  2368. }
  2369. else
  2370. {
  2371. hoffset = (efuse_data>>4) & 0x0F;
  2372. hworden = efuse_data & 0x0F;
  2373. }
  2374. word_cnts = Efuse_CalculateWordCnts(hworden);
  2375. //read next header
  2376. efuse_addr = efuse_addr + (word_cnts*2)+1;
  2377. }
  2378. else
  2379. {
  2380. bContinual = _FALSE ;
  2381. }
  2382. }
  2383. if(bPseudoTest)
  2384. {
  2385. fakeEfuseUsedBytes = efuse_addr;
  2386. //RTPRINT(FEEPROM, EFUSE_PG, ("hal_EfuseGetCurrentSize_8723A(), return %d\n", fakeEfuseUsedBytes));
  2387. }
  2388. else
  2389. {
  2390. rtw_hal_set_hwreg(pAdapter, HW_VAR_EFUSE_BYTES, (u8 *)&efuse_addr);
  2391. //RTPRINT(FEEPROM, EFUSE_PG, ("hal_EfuseGetCurrentSize_8723A(), return %d\n", efuse_addr));
  2392. }
  2393. return efuse_addr;
  2394. }
  2395. static u16
  2396. rtl8812_EfuseGetCurrentSize(
  2397. IN PADAPTER pAdapter,
  2398. IN u8 efuseType,
  2399. IN BOOLEAN bPseudoTest)
  2400. {
  2401. u16 ret=0;
  2402. ret = hal_EfuseGetCurrentSize_8812A(pAdapter, bPseudoTest);
  2403. return ret;
  2404. }
  2405. static int
  2406. hal_EfusePgPacketRead_8812A(
  2407. IN PADAPTER pAdapter,
  2408. IN u8 offset,
  2409. IN u8 *data,
  2410. IN BOOLEAN bPseudoTest)
  2411. {
  2412. u8 ReadState = PG_STATE_HEADER;
  2413. int bContinual = _TRUE;
  2414. int bDataEmpty = _TRUE ;
  2415. u8 efuse_data,word_cnts = 0;
  2416. u16 efuse_addr = 0;
  2417. u8 hoffset = 0,hworden = 0;
  2418. u8 tmpidx = 0;
  2419. u8 tmpdata[8];
  2420. u8 max_section = 0;
  2421. u8 tmp_header = 0;
  2422. if(data==NULL)
  2423. return _FALSE;
  2424. if(offset>EFUSE_MAX_SECTION_JAGUAR)
  2425. return _FALSE;
  2426. _rtw_memset((PVOID)data, 0xff, sizeof(u8)*PGPKT_DATA_SIZE);
  2427. _rtw_memset((PVOID)tmpdata, 0xff, sizeof(u8)*PGPKT_DATA_SIZE);
  2428. //
  2429. // <Roger_TODO> Efuse has been pre-programmed dummy 5Bytes at the end of Efuse by CP.
  2430. // Skip dummy parts to prevent unexpected data read from Efuse.
  2431. // By pass right now. 2009.02.19.
  2432. //
  2433. while(bContinual && (efuse_addr < EFUSE_REAL_CONTENT_LEN_JAGUAR) )
  2434. {
  2435. //------- Header Read -------------
  2436. if(ReadState & PG_STATE_HEADER)
  2437. {
  2438. if(efuse_OneByteRead(pAdapter, efuse_addr ,&efuse_data, bPseudoTest)&&(efuse_data!=0xFF))
  2439. {
  2440. if(EXT_HEADER(efuse_data))
  2441. {
  2442. tmp_header = efuse_data;
  2443. efuse_addr++;
  2444. efuse_OneByteRead(pAdapter, efuse_addr ,&efuse_data, bPseudoTest);
  2445. if(!ALL_WORDS_DISABLED(efuse_data))
  2446. {
  2447. hoffset = ((tmp_header & 0xE0) >> 5) | ((efuse_data & 0xF0) >> 1);
  2448. hworden = efuse_data & 0x0F;
  2449. }
  2450. else
  2451. {
  2452. DBG_8192C("Error, All words disabled\n");
  2453. efuse_addr++;
  2454. break;
  2455. }
  2456. }
  2457. else
  2458. {
  2459. hoffset = (efuse_data>>4) & 0x0F;
  2460. hworden = efuse_data & 0x0F;
  2461. }
  2462. word_cnts = Efuse_CalculateWordCnts(hworden);
  2463. bDataEmpty = _TRUE ;
  2464. if(hoffset==offset)
  2465. {
  2466. for(tmpidx = 0;tmpidx< word_cnts*2 ;tmpidx++)
  2467. {
  2468. if(efuse_OneByteRead(pAdapter, efuse_addr+1+tmpidx ,&efuse_data, bPseudoTest) )
  2469. {
  2470. tmpdata[tmpidx] = efuse_data;
  2471. if(efuse_data!=0xff)
  2472. {
  2473. bDataEmpty = _FALSE;
  2474. }
  2475. }
  2476. }
  2477. if(bDataEmpty==_FALSE){
  2478. ReadState = PG_STATE_DATA;
  2479. }else{//read next header
  2480. efuse_addr = efuse_addr + (word_cnts*2)+1;
  2481. ReadState = PG_STATE_HEADER;
  2482. }
  2483. }
  2484. else{//read next header
  2485. efuse_addr = efuse_addr + (word_cnts*2)+1;
  2486. ReadState = PG_STATE_HEADER;
  2487. }
  2488. }
  2489. else{
  2490. bContinual = _FALSE ;
  2491. }
  2492. }
  2493. //------- Data section Read -------------
  2494. else if(ReadState & PG_STATE_DATA)
  2495. {
  2496. efuse_WordEnableDataRead(hworden,tmpdata,data);
  2497. efuse_addr = efuse_addr + (word_cnts*2)+1;
  2498. ReadState = PG_STATE_HEADER;
  2499. }
  2500. }
  2501. if( (data[0]==0xff) &&(data[1]==0xff) && (data[2]==0xff) && (data[3]==0xff) &&
  2502. (data[4]==0xff) &&(data[5]==0xff) && (data[6]==0xff) && (data[7]==0xff))
  2503. return _FALSE;
  2504. else
  2505. return _TRUE;
  2506. }
  2507. static int
  2508. rtl8812_Efuse_PgPacketRead( IN PADAPTER pAdapter,
  2509. IN u8 offset,
  2510. IN u8 *data,
  2511. IN BOOLEAN bPseudoTest)
  2512. {
  2513. int ret=0;
  2514. ret = hal_EfusePgPacketRead_8812A(pAdapter, offset, data, bPseudoTest);
  2515. return ret;
  2516. }
  2517. int
  2518. hal_EfusePgPacketWrite_8812A(IN PADAPTER pAdapter,
  2519. IN u8 offset,
  2520. IN u8 word_en,
  2521. IN u8 *data,
  2522. IN BOOLEAN bPseudoTest)
  2523. {
  2524. u8 WriteState = PG_STATE_HEADER;
  2525. int bContinual = _TRUE,bDataEmpty=_TRUE;
  2526. //int bResult = _TRUE;
  2527. u16 efuse_addr = 0;
  2528. u8 efuse_data;
  2529. u8 pg_header = 0, pg_header_temp = 0;
  2530. u8 tmp_word_cnts=0,target_word_cnts=0;
  2531. u8 tmp_header,match_word_en,tmp_word_en;
  2532. PGPKT_STRUCT target_pkt;
  2533. PGPKT_STRUCT tmp_pkt;
  2534. u8 originaldata[sizeof(u8)*8];
  2535. u8 tmpindex = 0,badworden = 0x0F;
  2536. static int repeat_times = 0;
  2537. BOOLEAN bExtendedHeader = _FALSE;
  2538. u8 efuseType=EFUSE_WIFI;
  2539. //
  2540. // <Roger_Notes> Efuse has been pre-programmed dummy 5Bytes at the end of Efuse by CP.
  2541. // So we have to prevent unexpected data string connection, which will cause
  2542. // incorrect data auto-load from HW. The total size is equal or smaller than 498bytes
  2543. // (i.e., offset 0~497, and dummy 1bytes) expected after CP test.
  2544. // 2009.02.19.
  2545. //
  2546. if( Efuse_GetCurrentSize(pAdapter, efuseType, bPseudoTest) >= (EFUSE_REAL_CONTENT_LEN_JAGUAR-EFUSE_OOB_PROTECT_BYTES_JAGUAR))
  2547. {
  2548. DBG_871X("hal_EfusePgPacketWrite_8812A() error: %x >= %x\n", Efuse_GetCurrentSize(pAdapter, efuseType, bPseudoTest), (EFUSE_REAL_CONTENT_LEN_JAGUAR-EFUSE_OOB_PROTECT_BYTES_JAGUAR));
  2549. return _FALSE;
  2550. }
  2551. // Init the 8 bytes content as 0xff
  2552. target_pkt.offset = offset;
  2553. target_pkt.word_en= word_en;
  2554. // Initial the value to avoid compile warning
  2555. tmp_pkt.offset = 0;
  2556. tmp_pkt.word_en= 0;
  2557. //DBG_871X("hal_EfusePgPacketWrite_8812A target offset 0x%x word_en 0x%x \n", target_pkt.offset, target_pkt.word_en);
  2558. _rtw_memset((PVOID)target_pkt.data, 0xFF, sizeof(u8)*8);
  2559. efuse_WordEnableDataRead(word_en, data, target_pkt.data);
  2560. target_word_cnts = Efuse_CalculateWordCnts(target_pkt.word_en);
  2561. //efuse_reg_ctrl(pAdapter,_TRUE);//power on
  2562. //DBG_871X("EFUSE Power ON\n");
  2563. //
  2564. // <Roger_Notes> Efuse has been pre-programmed dummy 5Bytes at the end of Efuse by CP.
  2565. // So we have to prevent unexpected data string connection, which will cause
  2566. // incorrect data auto-load from HW. Dummy 1bytes is additional.
  2567. // 2009.02.19.
  2568. //
  2569. while( bContinual && (efuse_addr < (EFUSE_REAL_CONTENT_LEN_JAGUAR-EFUSE_OOB_PROTECT_BYTES_JAGUAR)) )
  2570. {
  2571. if(WriteState==PG_STATE_HEADER)
  2572. {
  2573. bDataEmpty=_TRUE;
  2574. badworden = 0x0F;
  2575. //************ so *******************
  2576. //DBG_871X("EFUSE PG_STATE_HEADER\n");
  2577. if ( efuse_OneByteRead(pAdapter, efuse_addr ,&efuse_data, bPseudoTest) &&
  2578. (efuse_data!=0xFF))
  2579. {
  2580. if((efuse_data&0x1F) == 0x0F) //extended header
  2581. {
  2582. tmp_header = efuse_data;
  2583. efuse_addr++;
  2584. efuse_OneByteRead(pAdapter, efuse_addr ,&efuse_data, bPseudoTest);
  2585. if((efuse_data & 0x0F) == 0x0F) //wren fail
  2586. {
  2587. u8 next = 0, next_next = 0, data = 0, i = 0;
  2588. u8 s = ((tmp_header & 0xF0) >> 4);
  2589. efuse_OneByteRead(pAdapter, efuse_addr+1, &next, bPseudoTest);
  2590. efuse_OneByteRead(pAdapter, efuse_addr+2, &next_next, bPseudoTest);
  2591. if (next == 0xFF && next_next == 0xFF) { // Have enough space to make fake data to recover bad header.
  2592. switch (s) {
  2593. case 0x0:
  2594. case 0x2:
  2595. case 0x4:
  2596. case 0x6:
  2597. case 0x8:
  2598. case 0xA:
  2599. case 0xC:
  2600. for (i = 0; i < 3; ++i) {
  2601. efuse_OneByteWrite(pAdapter, efuse_addr, 0x27, bPseudoTest);
  2602. efuse_OneByteRead(pAdapter, efuse_addr, &data, bPseudoTest);
  2603. if (data == 0x27)
  2604. break;
  2605. }
  2606. break;
  2607. case 0xE:
  2608. for (i = 0; i < 3; ++i) {
  2609. efuse_OneByteWrite(pAdapter, efuse_addr, 0x17, bPseudoTest);
  2610. efuse_OneByteRead(pAdapter, efuse_addr, &data, bPseudoTest);
  2611. if (data == 0x17)
  2612. break;
  2613. }
  2614. break;
  2615. default:
  2616. break;
  2617. }
  2618. efuse_OneByteWrite(pAdapter, efuse_addr+1, 0xFF, bPseudoTest);
  2619. efuse_OneByteWrite(pAdapter, efuse_addr+2, 0xFF, bPseudoTest);
  2620. efuse_addr += 3;
  2621. } else {
  2622. efuse_addr++;
  2623. }
  2624. continue;
  2625. }
  2626. else
  2627. {
  2628. tmp_pkt.offset = ((tmp_header & 0xE0) >> 5) | ((efuse_data & 0xF0) >> 1);
  2629. tmp_pkt.word_en = efuse_data & 0x0F;
  2630. }
  2631. }
  2632. else
  2633. {
  2634. u8 i = 0, data = 0;
  2635. tmp_header = efuse_data;
  2636. tmp_pkt.offset = (tmp_header>>4) & 0x0F;
  2637. tmp_pkt.word_en = tmp_header & 0x0F;
  2638. if (tmp_pkt.word_en == 0xF) {
  2639. u8 next = 0;
  2640. efuse_OneByteRead(pAdapter, efuse_addr+1, &next, bPseudoTest);
  2641. if (next == 0xFF) { // Have enough space to make fake data to recover bad header.
  2642. tmp_header = (tmp_header & 0xF0) | 0x7;
  2643. for (i = 0; i < 3; ++i) {
  2644. efuse_OneByteWrite(pAdapter, efuse_addr, tmp_header, bPseudoTest);
  2645. efuse_OneByteRead(pAdapter, efuse_addr, &data, bPseudoTest);
  2646. if (data == tmp_header)
  2647. break;
  2648. }
  2649. efuse_OneByteWrite(pAdapter, efuse_addr+1, 0xFF, bPseudoTest);
  2650. efuse_OneByteWrite(pAdapter, efuse_addr+2, 0xFF, bPseudoTest);
  2651. efuse_addr += 2;
  2652. }
  2653. }
  2654. }
  2655. tmp_word_cnts = Efuse_CalculateWordCnts(tmp_pkt.word_en);
  2656. //DBG_871X("section offset 0x%x worden 0x%x\n", tmp_pkt.offset, tmp_pkt.word_en);
  2657. //************ so-1 *******************
  2658. if(tmp_pkt.offset != target_pkt.offset)
  2659. {
  2660. efuse_addr = efuse_addr + (tmp_word_cnts*2) +1; //Next pg_packet
  2661. #if (EFUSE_ERROE_HANDLE == 1)
  2662. WriteState = PG_STATE_HEADER;
  2663. #endif
  2664. }
  2665. else //write the same offset
  2666. {
  2667. //DBG_871X("hal_EfusePgPacketWrite_8812A section offset the same\n");
  2668. //************ so-2 *******************
  2669. for(tmpindex=0 ; tmpindex<(tmp_word_cnts*2) ; tmpindex++)
  2670. {
  2671. if(efuse_OneByteRead(pAdapter, (efuse_addr+1+tmpindex) ,&efuse_data, bPseudoTest)&&(efuse_data != 0xFF)){
  2672. bDataEmpty = _FALSE;
  2673. }
  2674. }
  2675. //************ so-2-1 *******************
  2676. if(bDataEmpty == _FALSE)
  2677. {
  2678. //DBG_871X("hal_EfusePgPacketWrite_8812A section offset the same and data is NOT empty\n");
  2679. efuse_addr = efuse_addr + (tmp_word_cnts*2) +1; //Next pg_packet
  2680. #if (EFUSE_ERROE_HANDLE == 1)
  2681. WriteState=PG_STATE_HEADER;
  2682. #endif
  2683. }
  2684. else
  2685. {//************ so-2-2 *******************
  2686. //DBG_871X("hal_EfusePgPacketWrite_8812A section data empty\n");
  2687. match_word_en = 0x0F; //same bit as original wren
  2688. if( !( (target_pkt.word_en&BIT0)|(tmp_pkt.word_en&BIT0) ))
  2689. {
  2690. match_word_en &= (~BIT0);
  2691. }
  2692. if( !( (target_pkt.word_en&BIT1)|(tmp_pkt.word_en&BIT1) ))
  2693. {
  2694. match_word_en &= (~BIT1);
  2695. }
  2696. if( !( (target_pkt.word_en&BIT2)|(tmp_pkt.word_en&BIT2) ))
  2697. {
  2698. match_word_en &= (~BIT2);
  2699. }
  2700. if( !( (target_pkt.word_en&BIT3)|(tmp_pkt.word_en&BIT3) ))
  2701. {
  2702. match_word_en &= (~BIT3);
  2703. }
  2704. //************ so-2-2-A *******************
  2705. if((match_word_en&0x0F)!=0x0F)
  2706. {
  2707. badworden = Efuse_WordEnableDataWrite(pAdapter,efuse_addr+1, tmp_pkt.word_en ,target_pkt.data, bPseudoTest);
  2708. //************ so-2-2-A-1 *******************
  2709. //############################
  2710. if(0x0F != (badworden&0x0F))
  2711. {
  2712. u8 reorg_offset = offset;
  2713. u8 reorg_worden=badworden;
  2714. Efuse_PgPacketWrite(pAdapter, reorg_offset, reorg_worden, target_pkt.data, bPseudoTest);
  2715. }
  2716. //############################
  2717. tmp_word_en = 0x0F; //not the same bit as original wren
  2718. if( (target_pkt.word_en&BIT0)^(match_word_en&BIT0) )
  2719. {
  2720. tmp_word_en &= (~BIT0);
  2721. }
  2722. if( (target_pkt.word_en&BIT1)^(match_word_en&BIT1) )
  2723. {
  2724. tmp_word_en &= (~BIT1);
  2725. }
  2726. if( (target_pkt.word_en&BIT2)^(match_word_en&BIT2) )
  2727. {
  2728. tmp_word_en &= (~BIT2);
  2729. }
  2730. if( (target_pkt.word_en&BIT3)^(match_word_en&BIT3) )
  2731. {
  2732. tmp_word_en &=(~BIT3);
  2733. }
  2734. //************ so-2-2-A-2 *******************
  2735. if((tmp_word_en&0x0F)!=0x0F){
  2736. //reorganize other pg packet
  2737. // efuse_addr = efuse_addr + (2*tmp_word_cnts) +1;//next pg packet addr
  2738. efuse_addr = Efuse_GetCurrentSize(pAdapter, efuseType, bPseudoTest);
  2739. //===========================
  2740. target_pkt.offset = offset;
  2741. target_pkt.word_en= tmp_word_en;
  2742. //===========================
  2743. }else{
  2744. bContinual = _FALSE;
  2745. }
  2746. #if (EFUSE_ERROE_HANDLE == 1)
  2747. WriteState=PG_STATE_HEADER;
  2748. repeat_times++;
  2749. if(repeat_times>EFUSE_REPEAT_THRESHOLD_){
  2750. bContinual = _FALSE;
  2751. //bResult = _FALSE;
  2752. }
  2753. #endif
  2754. }
  2755. else{//************ so-2-2-B *******************
  2756. //reorganize other pg packet
  2757. efuse_addr = efuse_addr + (2*tmp_word_cnts) +1;//next pg packet addr
  2758. //===========================
  2759. target_pkt.offset = offset;
  2760. target_pkt.word_en= target_pkt.word_en;
  2761. //===========================
  2762. #if (EFUSE_ERROE_HANDLE == 1)
  2763. WriteState=PG_STATE_HEADER;
  2764. #endif
  2765. }
  2766. }
  2767. }
  2768. DBG_871X("EFUSE PG_STATE_HEADER-1\n");
  2769. }
  2770. else //************ s1: header == oxff *******************
  2771. {
  2772. bExtendedHeader = _FALSE;
  2773. if(target_pkt.offset >= EFUSE_MAX_SECTION_BASE)
  2774. {
  2775. pg_header = ((target_pkt.offset &0x07) << 5) | 0x0F;
  2776. //DBG_871X("hal_EfusePgPacketWrite_8812A extended pg_header[2:0] |0x0F 0x%x \n", pg_header);
  2777. efuse_OneByteWrite(pAdapter,efuse_addr, pg_header, bPseudoTest);
  2778. efuse_OneByteRead(pAdapter,efuse_addr, &tmp_header, bPseudoTest);
  2779. while(tmp_header == 0xFF)
  2780. {
  2781. //DBG_871X("hal_EfusePgPacketWrite_8812A extended pg_header[2:0] wirte fail \n");
  2782. repeat_times++;
  2783. if(repeat_times>EFUSE_REPEAT_THRESHOLD_){
  2784. bContinual = _FALSE;
  2785. //bResult = _FALSE;
  2786. efuse_addr++;
  2787. break;
  2788. }
  2789. efuse_OneByteWrite(pAdapter,efuse_addr, pg_header, bPseudoTest);
  2790. efuse_OneByteRead(pAdapter,efuse_addr, &tmp_header, bPseudoTest);
  2791. }
  2792. if(!bContinual)
  2793. break;
  2794. if(tmp_header == pg_header)
  2795. {
  2796. efuse_addr++;
  2797. pg_header_temp = pg_header;
  2798. pg_header = ((target_pkt.offset & 0x78) << 1 ) | target_pkt.word_en;
  2799. //DBG_871X("hal_EfusePgPacketWrite_8812A extended pg_header[6:3] | worden 0x%x word_en 0x%x \n", pg_header, target_pkt.word_en);
  2800. efuse_OneByteWrite(pAdapter,efuse_addr, pg_header, bPseudoTest);
  2801. efuse_OneByteRead(pAdapter,efuse_addr, &tmp_header, bPseudoTest);
  2802. while(tmp_header == 0xFF)
  2803. {
  2804. repeat_times++;
  2805. if(repeat_times>EFUSE_REPEAT_THRESHOLD_){
  2806. bContinual = _FALSE;
  2807. //bResult = _FALSE;
  2808. break;
  2809. }
  2810. efuse_OneByteWrite(pAdapter,efuse_addr, pg_header, bPseudoTest);
  2811. efuse_OneByteRead(pAdapter,efuse_addr, &tmp_header, bPseudoTest);
  2812. }
  2813. if(!bContinual)
  2814. break;
  2815. if((tmp_header & 0x0F) == 0x0F) //wren PG fail
  2816. {
  2817. repeat_times++;
  2818. if(repeat_times>EFUSE_REPEAT_THRESHOLD_){
  2819. bContinual = _FALSE;
  2820. //bResult = _FALSE;
  2821. break;
  2822. }
  2823. else
  2824. {
  2825. efuse_addr++;
  2826. continue;
  2827. }
  2828. }
  2829. else if(pg_header != tmp_header) //offset PG fail
  2830. {
  2831. bExtendedHeader = _TRUE;
  2832. tmp_pkt.offset = ((pg_header_temp & 0xE0) >> 5) | ((tmp_header & 0xF0) >> 1);
  2833. tmp_pkt.word_en= tmp_header & 0x0F;
  2834. tmp_word_cnts = Efuse_CalculateWordCnts(tmp_pkt.word_en);
  2835. }
  2836. }
  2837. else if ((tmp_header & 0x1F) == 0x0F) //wrong extended header
  2838. {
  2839. efuse_addr+=2;
  2840. continue;
  2841. }
  2842. }
  2843. else
  2844. {
  2845. pg_header = ((target_pkt.offset << 4)&0xf0) |target_pkt.word_en;
  2846. efuse_OneByteWrite(pAdapter,efuse_addr, pg_header, bPseudoTest);
  2847. efuse_OneByteRead(pAdapter,efuse_addr, &tmp_header, bPseudoTest);
  2848. }
  2849. if(tmp_header == pg_header)
  2850. { //************ s1-1*******************
  2851. WriteState = PG_STATE_DATA;
  2852. }
  2853. #if (EFUSE_ERROE_HANDLE == 1)
  2854. else if(tmp_header == 0xFF){//************ s1-3: if Write or read func doesn't work *******************
  2855. //efuse_addr doesn't change
  2856. WriteState = PG_STATE_HEADER;
  2857. repeat_times++;
  2858. if(repeat_times>EFUSE_REPEAT_THRESHOLD_){
  2859. bContinual = _FALSE;
  2860. //bResult = _FALSE;
  2861. }
  2862. }
  2863. #endif
  2864. else
  2865. {//************ s1-2 : fixed the header procedure *******************
  2866. if(!bExtendedHeader)
  2867. {
  2868. tmp_pkt.offset = (tmp_header>>4) & 0x0F;
  2869. tmp_pkt.word_en= tmp_header & 0x0F;
  2870. tmp_word_cnts = Efuse_CalculateWordCnts(tmp_pkt.word_en);
  2871. }
  2872. //************ s1-2-A :cover the exist data *******************
  2873. _rtw_memset(originaldata, 0xff, sizeof(u8)*8);
  2874. if(Efuse_PgPacketRead( pAdapter, tmp_pkt.offset,originaldata, bPseudoTest))
  2875. { //check if data exist
  2876. //efuse_reg_ctrl(pAdapter,_TRUE);//power on
  2877. badworden = Efuse_WordEnableDataWrite(pAdapter,efuse_addr+1,tmp_pkt.word_en,originaldata, bPseudoTest);
  2878. //############################
  2879. if(0x0F != (badworden&0x0F))
  2880. {
  2881. u8 reorg_offset = tmp_pkt.offset;
  2882. u8 reorg_worden=badworden;
  2883. Efuse_PgPacketWrite(pAdapter,reorg_offset,reorg_worden,originaldata, bPseudoTest);
  2884. efuse_addr = Efuse_GetCurrentSize(pAdapter, efuseType, bPseudoTest);
  2885. }
  2886. //############################
  2887. else{
  2888. efuse_addr = efuse_addr + (tmp_word_cnts*2) +1; //Next pg_packet
  2889. }
  2890. }
  2891. //************ s1-2-B: wrong address*******************
  2892. else
  2893. {
  2894. efuse_addr = efuse_addr + (tmp_word_cnts*2) +1; //Next pg_packet
  2895. }
  2896. #if (EFUSE_ERROE_HANDLE == 1)
  2897. WriteState=PG_STATE_HEADER;
  2898. repeat_times++;
  2899. if(repeat_times>EFUSE_REPEAT_THRESHOLD_){
  2900. bContinual = _FALSE;
  2901. //bResult = _FALSE;
  2902. }
  2903. #endif
  2904. //DBG_871X("EFUSE PG_STATE_HEADER-2\n");
  2905. }
  2906. }
  2907. }
  2908. //write data state
  2909. else if(WriteState==PG_STATE_DATA)
  2910. { //************ s1-1 *******************
  2911. //DBG_871X("EFUSE PG_STATE_DATA\n");
  2912. badworden = 0x0f;
  2913. badworden = Efuse_WordEnableDataWrite(pAdapter,efuse_addr+1,target_pkt.word_en,target_pkt.data, bPseudoTest);
  2914. if((badworden&0x0F)==0x0F)
  2915. { //************ s1-1-A *******************
  2916. bContinual = _FALSE;
  2917. }
  2918. else
  2919. {//reorganize other pg packet //************ s1-1-B *******************
  2920. efuse_addr = efuse_addr + (2*target_word_cnts) +1;//next pg packet addr
  2921. //===========================
  2922. target_pkt.offset = offset;
  2923. target_pkt.word_en= badworden;
  2924. target_word_cnts = Efuse_CalculateWordCnts(target_pkt.word_en);
  2925. //===========================
  2926. #if (EFUSE_ERROE_HANDLE == 1)
  2927. WriteState=PG_STATE_HEADER;
  2928. repeat_times++;
  2929. if(repeat_times>EFUSE_REPEAT_THRESHOLD_){
  2930. bContinual = _FALSE;
  2931. //bResult = _FALSE;
  2932. }
  2933. #endif
  2934. //DBG_871X("EFUSE PG_STATE_HEADER-3\n");
  2935. }
  2936. }
  2937. }
  2938. if(efuse_addr >= (EFUSE_REAL_CONTENT_LEN_JAGUAR-EFUSE_OOB_PROTECT_BYTES_JAGUAR))
  2939. {
  2940. DBG_871X("hal_EfusePgPacketWrite_8812A(): efuse_addr(%#x) Out of size!!\n", efuse_addr);
  2941. }
  2942. //efuse_reg_ctrl(pAdapter,_FALSE);//power off
  2943. return _TRUE;
  2944. }
  2945. static int
  2946. rtl8812_Efuse_PgPacketWrite(IN PADAPTER pAdapter,
  2947. IN u8 offset,
  2948. IN u8 word_en,
  2949. IN u8 *data,
  2950. IN BOOLEAN bPseudoTest)
  2951. {
  2952. int ret;
  2953. ret = hal_EfusePgPacketWrite_8812A(pAdapter, offset, word_en, data, bPseudoTest);
  2954. return ret;
  2955. }
  2956. #ifdef CONFIG_EFUSE_CONFIG_FILE
  2957. static s32 _halReadPGDataFromFile(PADAPTER padapter, u8 *pbuf)
  2958. {
  2959. u32 i;
  2960. struct file *fp;
  2961. mm_segment_t fs;
  2962. u8 temp[3];
  2963. loff_t pos = 0;
  2964. temp[2] = 0; // add end of string '\0'
  2965. DBG_8192C("%s: Read Efuse from file [%s]\n", __FUNCTION__, EFUSE_FILE_PATH);
  2966. fp = filp_open(EFUSE_FILE_PATH, O_RDONLY, 0);
  2967. if (IS_ERR(fp)) {
  2968. DBG_8192C("%s: Error, Read Efuse configure file FAIL!\n", __FUNCTION__);
  2969. pEEPROM->bloadfile_fail_flag = _TRUE;
  2970. return _FAIL;
  2971. }
  2972. fs = get_fs();
  2973. set_fs(KERNEL_DS);
  2974. for (i=0; i<HWSET_MAX_SIZE_JAGUAR; i++)
  2975. {
  2976. vfs_read(fp, temp, 2, &pos);
  2977. pbuf[i] = simple_strtoul(temp, NULL, 16);
  2978. pos += 1; // Filter the space character
  2979. }
  2980. set_fs(fs);
  2981. filp_close(fp, NULL);
  2982. #ifdef CONFIG_DEBUG
  2983. DBG_8192C("Efuse configure file:\n");
  2984. for (i=0; i<HWSET_MAX_SIZE_JAGUAR; i++)
  2985. {
  2986. if (i % 16 == 0)
  2987. printk("\n");
  2988. printk("%02X ", pbuf[i]);
  2989. }
  2990. printk("\n");
  2991. DBG_8192C("\n");
  2992. #endif
  2993. pEEPROM->bloadfile_fail_flag = _FALSE;
  2994. return _SUCCESS;
  2995. }
  2996. static s32 _halReadMACAddrFromFile(PADAPTER padapter, u8 *pbuf)
  2997. {
  2998. struct file *fp;
  2999. mm_segment_t fs;
  3000. loff_t pos = 0;
  3001. u8 source_addr[18];
  3002. u8 *head, *end;
  3003. u32 curtime;
  3004. u32 i;
  3005. s32 ret = _SUCCESS;
  3006. u8 null_mac_addr[ETH_ALEN] = {0, 0, 0, 0, 0, 0};
  3007. u8 multi_mac_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  3008. curtime = rtw_get_current_time();
  3009. _rtw_memset(source_addr, 0, 18);
  3010. _rtw_memset(pbuf, 0, ETH_ALEN);
  3011. fp = filp_open(MAC_ADDRESS_FILE_PATH, O_RDONLY, 0);
  3012. if (IS_ERR(fp))
  3013. {
  3014. ret = _FAIL;
  3015. DBG_8192C("%s: Error, Read MAC address file FAIL!\n", __FUNCTION__);
  3016. }
  3017. else
  3018. {
  3019. fs = get_fs();
  3020. set_fs(KERNEL_DS);
  3021. vfs_read(fp, source_addr, 18, &pos);
  3022. source_addr[17] = ':';
  3023. head = end = source_addr;
  3024. for (i=0; i<ETH_ALEN; i++)
  3025. {
  3026. while (end && (*end != ':') )
  3027. end++;
  3028. if (end && (*end == ':') )
  3029. *end = '\0';
  3030. pbuf[i] = simple_strtoul(head, NULL, 16 );
  3031. if (end) {
  3032. end++;
  3033. head = end;
  3034. }
  3035. }
  3036. set_fs(fs);
  3037. filp_close(fp, NULL);
  3038. DBG_8192C("%s: Read MAC address from file [%s]\n", __FUNCTION__, MAC_ADDRESS_FILE_PATH);
  3039. DBG_8192C("WiFi MAC address: " MAC_FMT "\n", MAC_ARG(pbuf));
  3040. }
  3041. if (_rtw_memcmp(pbuf, null_mac_addr, ETH_ALEN) ||
  3042. _rtw_memcmp(pbuf, multi_mac_addr, ETH_ALEN))
  3043. {
  3044. pbuf[0] = 0x00;
  3045. pbuf[1] = 0xe0;
  3046. pbuf[2] = 0x4c;
  3047. pbuf[3] = (u8)(curtime & 0xff) ;
  3048. pbuf[4] = (u8)((curtime>>8) & 0xff) ;
  3049. pbuf[5] = (u8)((curtime>>16) & 0xff) ;
  3050. }
  3051. DBG_8192C("%s: Permanent Address = " MAC_FMT "\n", __FUNCTION__, MAC_ARG(pbuf));
  3052. return ret;
  3053. }
  3054. #endif // CONFIG_EFUSE_CONFIG_FILE
  3055. void InitRDGSetting8812A(PADAPTER padapter)
  3056. {
  3057. rtw_write8(padapter, REG_RD_CTRL, 0xFF);
  3058. rtw_write16(padapter, REG_RD_NAV_NXT, 0x200);
  3059. rtw_write8(padapter, REG_RD_RESP_PKT_TH, 0x05);
  3060. }
  3061. void ReadRFType8812A(PADAPTER padapter)
  3062. {
  3063. PHAL_DATA_TYPE pHalData = GET_HAL_DATA(padapter);
  3064. #if DISABLE_BB_RF
  3065. pHalData->rf_chip = RF_PSEUDO_11N;
  3066. #else
  3067. pHalData->rf_chip = RF_6052;
  3068. #endif
  3069. //if (pHalData->rf_type == RF_1T1R){
  3070. // pHalData->bRFPathRxEnable[0] = _TRUE;
  3071. //}
  3072. //else { // Default unknow type is 2T2r
  3073. // pHalData->bRFPathRxEnable[0] = pHalData->bRFPathRxEnable[1] = _TRUE;
  3074. //}
  3075. if (IsSupported24G(padapter->registrypriv.wireless_mode) &&
  3076. IsSupported5G(padapter->registrypriv.wireless_mode))
  3077. pHalData->BandSet = BAND_ON_BOTH;
  3078. else if (IsSupported5G(padapter->registrypriv.wireless_mode))
  3079. pHalData->BandSet = BAND_ON_5G;
  3080. else
  3081. pHalData->BandSet = BAND_ON_2_4G;
  3082. //if(padapter->bInHctTest)
  3083. // pHalData->BandSet = BAND_ON_2_4G;
  3084. }
  3085. void rtl8812_GetHalODMVar(
  3086. PADAPTER Adapter,
  3087. HAL_ODM_VARIABLE eVariable,
  3088. PVOID pValue1,
  3089. BOOLEAN bSet)
  3090. {
  3091. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  3092. PDM_ODM_T podmpriv = &pHalData->odmpriv;
  3093. switch(eVariable){
  3094. case HAL_ODM_STA_INFO:
  3095. break;
  3096. default:
  3097. break;
  3098. }
  3099. }
  3100. void rtl8812_SetHalODMVar(
  3101. PADAPTER Adapter,
  3102. HAL_ODM_VARIABLE eVariable,
  3103. PVOID pValue1,
  3104. BOOLEAN bSet)
  3105. {
  3106. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  3107. PDM_ODM_T podmpriv = &pHalData->odmpriv;
  3108. //_irqL irqL;
  3109. switch(eVariable){
  3110. case HAL_ODM_STA_INFO:
  3111. {
  3112. struct sta_info *psta = (struct sta_info *)pValue1;
  3113. if(bSet){
  3114. DBG_8192C("### Set STA_(%d) info\n",psta->mac_id);
  3115. ODM_CmnInfoPtrArrayHook(podmpriv, ODM_CMNINFO_STA_STATUS,psta->mac_id,psta);
  3116. #if(RATE_ADAPTIVE_SUPPORT==1)
  3117. ODM_RAInfo_Init(podmpriv,psta->mac_id);
  3118. #endif
  3119. }
  3120. else{
  3121. DBG_8192C("### Clean STA_(%d) info\n",psta->mac_id);
  3122. //_enter_critical_bh(&pHalData->odm_stainfo_lock, &irqL);
  3123. ODM_CmnInfoPtrArrayHook(podmpriv, ODM_CMNINFO_STA_STATUS,psta->mac_id,NULL);
  3124. //_exit_critical_bh(&pHalData->odm_stainfo_lock, &irqL);
  3125. }
  3126. }
  3127. break;
  3128. case HAL_ODM_P2P_STATE:
  3129. ODM_CmnInfoUpdate(podmpriv,ODM_CMNINFO_WIFI_DIRECT,bSet);
  3130. break;
  3131. case HAL_ODM_WIFI_DISPLAY_STATE:
  3132. ODM_CmnInfoUpdate(podmpriv,ODM_CMNINFO_WIFI_DISPLAY,bSet);
  3133. break;
  3134. default:
  3135. break;
  3136. }
  3137. }
  3138. void rtl8812_clone_haldata(_adapter* dst_adapter, _adapter* src_adapter)
  3139. {
  3140. #ifdef CONFIG_SDIO_HCI
  3141. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(dst_adapter);
  3142. //_thread_hdl_ SdioXmitThread;
  3143. #ifndef CONFIG_SDIO_TX_TASKLET
  3144. _sema temp_SdioXmitSema;
  3145. _sema temp_SdioXmitTerminateSema;
  3146. #endif
  3147. //u8 SdioTxFIFOFreePage[SDIO_TX_FREE_PG_QUEUE];
  3148. _lock temp_SdioTxFIFOFreePageLock;
  3149. #ifndef CONFIG_SDIO_TX_TASKLET
  3150. _rtw_memcpy(&temp_SdioXmitSema, &(pHalData->SdioXmitSema), sizeof(_sema));
  3151. _rtw_memcpy(&temp_SdioXmitTerminateSema, &(pHalData->SdioXmitTerminateSema), sizeof(_sema));
  3152. #endif
  3153. _rtw_memcpy(&temp_SdioTxFIFOFreePageLock, &(pHalData->SdioTxFIFOFreePageLock), sizeof(_lock));
  3154. _rtw_memcpy(dst_adapter->HalData, src_adapter->HalData, dst_adapter->hal_data_sz);
  3155. #ifndef CONFIG_SDIO_TX_TASKLET
  3156. _rtw_memcpy(&(pHalData->SdioXmitSema), &temp_SdioXmitSema, sizeof(_sema));
  3157. _rtw_memcpy(&(pHalData->SdioXmitTerminateSema), &temp_SdioXmitTerminateSema, sizeof(_sema));
  3158. #endif
  3159. _rtw_memcpy(&(pHalData->SdioTxFIFOFreePageLock), &temp_SdioTxFIFOFreePageLock, sizeof(_lock));
  3160. #else
  3161. _rtw_memcpy(dst_adapter->HalData, src_adapter->HalData, dst_adapter->hal_data_sz);
  3162. #endif
  3163. }
  3164. void rtl8812_start_thread(PADAPTER padapter)
  3165. {
  3166. }
  3167. void rtl8812_stop_thread(PADAPTER padapter)
  3168. {
  3169. }
  3170. void hal_notch_filter_8812(_adapter *adapter, bool enable)
  3171. {
  3172. if (enable) {
  3173. DBG_871X("Enable notch filter\n");
  3174. //rtw_write8(adapter, rOFDM0_RxDSP+1, rtw_read8(adapter, rOFDM0_RxDSP+1) | BIT1);
  3175. } else {
  3176. DBG_871X("Disable notch filter\n");
  3177. //rtw_write8(adapter, rOFDM0_RxDSP+1, rtw_read8(adapter, rOFDM0_RxDSP+1) & ~BIT1);
  3178. }
  3179. }
  3180. u8
  3181. GetEEPROMSize8812A(
  3182. IN PADAPTER Adapter
  3183. )
  3184. {
  3185. u8 size = 0;
  3186. u32 curRCR;
  3187. curRCR = rtw_read16(Adapter, REG_SYS_EEPROM_CTRL);
  3188. size = (curRCR & EEPROMSEL) ? 6 : 4; // 6: EEPROM used is 93C46, 4: boot from E-Fuse.
  3189. DBG_871X("EEPROM type is %s\n", size==4 ? "E-FUSE" : "93C46");
  3190. //return size;
  3191. return 4; // <20120713, Kordan> The default value of HW is 6 ?!!
  3192. }
  3193. void CheckAutoloadState8812A(PADAPTER padapter)
  3194. {
  3195. PEEPROM_EFUSE_PRIV pEEPROM;
  3196. u8 val8;
  3197. pEEPROM = GET_EEPROM_EFUSE_PRIV(padapter);
  3198. /* check system boot selection */
  3199. val8 = rtw_read8(padapter, REG_9346CR);
  3200. pEEPROM->EepromOrEfuse = (val8 & BOOT_FROM_EEPROM) ? _TRUE : _FALSE;
  3201. pEEPROM->bautoload_fail_flag = (val8 & EEPROM_EN) ? _FALSE : _TRUE;
  3202. DBG_8192C("%s: 9346CR(%#x)=0x%02x, Boot from %s, Autoload %s!\n",
  3203. __FUNCTION__, REG_9346CR, val8,
  3204. (pEEPROM->EepromOrEfuse ? "EEPROM" : "EFUSE"),
  3205. (pEEPROM->bautoload_fail_flag ? "Fail" : "OK"));
  3206. }
  3207. void InitPGData8812A(PADAPTER padapter)
  3208. {
  3209. PEEPROM_EFUSE_PRIV pEEPROM;
  3210. u32 i;
  3211. u16 val16;
  3212. pEEPROM = GET_EEPROM_EFUSE_PRIV(padapter);
  3213. #ifdef CONFIG_EFUSE_CONFIG_FILE
  3214. {
  3215. s32 tmp;
  3216. u32 addr;
  3217. tmp = _halReadPGDataFromFile(padapter, pEEPROM->efuse_eeprom_data);
  3218. pEEPROM->bloadfile_fail_flag = ((tmp==_FAIL) ? _TRUE : _FALSE);
  3219. tmp = _halReadMACAddrFromFile(padapter, pEEPROM->mac_addr);
  3220. pEEPROM->bloadmac_fail_flag = ((tmp==_FAIL) ? _TRUE : _FALSE);
  3221. #ifdef CONFIG_SDIO_HCI
  3222. addr = EEPROM_MAC_ADDR_8821AS;
  3223. #elif defined(CONFIG_USB_HCI)
  3224. if (IS_HARDWARE_TYPE_8812AU(padapter))
  3225. addr = EEPROM_MAC_ADDR_8812AE;
  3226. else
  3227. addr = EEPROM_MAC_ADDR_8821AE;
  3228. #elif defined(CONFIG_PCI_HCI)
  3229. if (IS_HARDWARE_TYPE_8812E(padapter))
  3230. addr = EEPROM_MAC_ADDR_8812AE;
  3231. else
  3232. addr = EEPROM_MAC_ADDR_8821AE;
  3233. #endif // CONFIG_PCI_HCI
  3234. _rtw_memcpy(&pEEPROM->efuse_eeprom_data[addr], pEEPROM->mac_addr, ETH_ALEN);
  3235. }
  3236. #else // !CONFIG_EFUSE_CONFIG_FILE
  3237. if (_FALSE == pEEPROM->bautoload_fail_flag)
  3238. {
  3239. // autoload OK.
  3240. if (is_boot_from_eeprom(padapter))
  3241. {
  3242. // Read all Content from EEPROM or EFUSE.
  3243. for (i = 0; i < HWSET_MAX_SIZE_JAGUAR; i += 2)
  3244. {
  3245. //val16 = EF2Byte(ReadEEprom(pAdapter, (u2Byte) (i>>1)));
  3246. //*((u16*)(&PROMContent[i])) = val16;
  3247. }
  3248. }
  3249. else
  3250. {
  3251. // Read EFUSE real map to shadow.
  3252. EFUSE_ShadowMapUpdate(padapter, EFUSE_WIFI, _FALSE);
  3253. }
  3254. }
  3255. else
  3256. {
  3257. // update to default value 0xFF
  3258. if (!is_boot_from_eeprom(padapter))
  3259. EFUSE_ShadowMapUpdate(padapter, EFUSE_WIFI, _FALSE);
  3260. }
  3261. #endif // !CONFIG_EFUSE_CONFIG_FILE
  3262. }
  3263. void
  3264. ReadChipVersion8812A(
  3265. IN PADAPTER Adapter
  3266. )
  3267. {
  3268. u32 value32;
  3269. HAL_VERSION ChipVersion;
  3270. PHAL_DATA_TYPE pHalData;
  3271. pHalData = GET_HAL_DATA(Adapter);
  3272. value32 = rtw_read32(Adapter, REG_SYS_CFG);
  3273. DBG_8192C("%s SYS_CFG(0x%X)=0x%08x \n", __FUNCTION__, REG_SYS_CFG, value32);
  3274. if(IS_HARDWARE_TYPE_8812(Adapter))
  3275. ChipVersion.ICType = CHIP_8812;
  3276. else
  3277. ChipVersion.ICType = CHIP_8821;
  3278. ChipVersion.ChipType = ((value32 & RTL_ID) ? TEST_CHIP : NORMAL_CHIP);
  3279. if (Adapter->registrypriv.rf_config == RF_MAX_TYPE) {
  3280. if(IS_HARDWARE_TYPE_8812(Adapter))
  3281. ChipVersion.RFType = RF_TYPE_2T2R;//RF_2T2R;
  3282. else
  3283. ChipVersion.RFType = RF_TYPE_1T1R;//RF_1T1R;
  3284. }
  3285. if (IS_HARDWARE_TYPE_8812(Adapter))
  3286. ChipVersion.VendorType = ((value32 & VENDOR_ID) ? CHIP_VENDOR_UMC : CHIP_VENDOR_TSMC);
  3287. else
  3288. {
  3289. u32 vendor;
  3290. vendor = (value32 & EXT_VENDOR_ID) >> EXT_VENDOR_ID_SHIFT;
  3291. switch (vendor)
  3292. {
  3293. case 0:
  3294. vendor = CHIP_VENDOR_TSMC;
  3295. break;
  3296. case 1:
  3297. vendor = CHIP_VENDOR_SMIC;
  3298. break;
  3299. case 2:
  3300. vendor = CHIP_VENDOR_UMC;
  3301. break;
  3302. }
  3303. ChipVersion.VendorType = vendor;
  3304. }
  3305. ChipVersion.CUTVersion = (value32 & CHIP_VER_RTL_MASK)>>CHIP_VER_RTL_SHIFT; // IC version (CUT)
  3306. if(IS_HARDWARE_TYPE_8812(Adapter))
  3307. ChipVersion.CUTVersion += 1;
  3308. //value32 = rtw_read32(Adapter, REG_GPIO_OUTSTS);
  3309. ChipVersion.ROMVer = 0; // ROM code version.
  3310. // For multi-function consideration. Added by Roger, 2010.10.06.
  3311. pHalData->MultiFunc = RT_MULTI_FUNC_NONE;
  3312. value32 = rtw_read32(Adapter, REG_MULTI_FUNC_CTRL);
  3313. pHalData->MultiFunc |= ((value32 & WL_FUNC_EN) ? RT_MULTI_FUNC_WIFI : 0);
  3314. pHalData->MultiFunc |= ((value32 & BT_FUNC_EN) ? RT_MULTI_FUNC_BT : 0);
  3315. pHalData->PolarityCtl = ((value32 & WL_HWPDN_SL) ? RT_POLARITY_HIGH_ACT : RT_POLARITY_LOW_ACT);
  3316. #if 1
  3317. dump_chip_info(ChipVersion);
  3318. #endif
  3319. _rtw_memcpy(&pHalData->VersionID, &ChipVersion, sizeof(HAL_VERSION));
  3320. if (IS_1T2R(ChipVersion)){
  3321. pHalData->rf_type = RF_1T2R;
  3322. pHalData->NumTotalRFPath = 2;
  3323. }
  3324. else if (IS_2T2R(ChipVersion)){
  3325. pHalData->rf_type = RF_2T2R;
  3326. pHalData->NumTotalRFPath = 2;
  3327. }
  3328. else{
  3329. pHalData->rf_type = RF_1T1R;
  3330. pHalData->NumTotalRFPath = 1;
  3331. }
  3332. DBG_8192C("RF_Type is %x!!\n", pHalData->rf_type);
  3333. }
  3334. VOID
  3335. Hal_PatchwithJaguar_8812(
  3336. IN PADAPTER Adapter,
  3337. IN RT_MEDIA_STATUS MediaStatus
  3338. )
  3339. {
  3340. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  3341. struct mlme_ext_priv *pmlmeext = &(Adapter->mlmeextpriv);
  3342. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  3343. if( (MediaStatus == RT_MEDIA_CONNECT) &&
  3344. (pmlmeinfo->assoc_AP_vendor == HT_IOT_PEER_REALTEK_JAGUAR_BCUTAP ))
  3345. {
  3346. rtw_write8(Adapter, rVhtlen_Use_Lsig_Jaguar, 0x1);
  3347. rtw_write8(Adapter, REG_TCR+3, BIT2);
  3348. }
  3349. else
  3350. {
  3351. rtw_write8(Adapter, rVhtlen_Use_Lsig_Jaguar, 0x3F);
  3352. rtw_write8(Adapter, REG_TCR+3, BIT0|BIT1|BIT2);
  3353. }
  3354. if( (MediaStatus == RT_MEDIA_CONNECT) &&
  3355. ((pmlmeinfo->assoc_AP_vendor == HT_IOT_PEER_REALTEK_JAGUAR_BCUTAP) ||
  3356. (pmlmeinfo->assoc_AP_vendor == HT_IOT_PEER_REALTEK_JAGUAR_CCUTAP)))
  3357. {
  3358. pHalData->Reg837 |= BIT2;
  3359. rtw_write8(Adapter, rBWIndication_Jaguar+3, pHalData->Reg837);
  3360. }
  3361. else
  3362. {
  3363. pHalData->Reg837 &= (~BIT2);
  3364. rtw_write8(Adapter, rBWIndication_Jaguar+3, pHalData->Reg837);
  3365. }
  3366. }
  3367. void UpdateHalRAMask8812A(PADAPTER padapter, u32 mac_id, u8 rssi_level)
  3368. {
  3369. //volatile unsigned int result;
  3370. u8 init_rate=0;
  3371. u8 networkType, raid;
  3372. u32 mask,rate_bitmap;
  3373. u8 shortGIrate = _FALSE;
  3374. int supportRateNum = 0;
  3375. u8 arg[4] = {0};
  3376. struct sta_info *psta;
  3377. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(padapter);
  3378. //struct dm_priv *pdmpriv = &pHalData->dmpriv;
  3379. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  3380. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  3381. WLAN_BSSID_EX *cur_network = &(pmlmeinfo->network);
  3382. if (mac_id >= NUM_STA) //CAM_SIZE
  3383. {
  3384. return;
  3385. }
  3386. psta = pmlmeinfo->FW_sta_info[mac_id].psta;
  3387. if(psta == NULL)
  3388. {
  3389. return;
  3390. }
  3391. switch (mac_id)
  3392. {
  3393. case 0:// for infra mode
  3394. #ifdef CONFIG_CONCURRENT_MODE
  3395. case 2:// first station uses macid=0, second station uses macid=2
  3396. #endif
  3397. supportRateNum = rtw_get_rateset_len(cur_network->SupportedRates);
  3398. networkType = judge_network_type(padapter, cur_network->SupportedRates, supportRateNum);
  3399. //pmlmeext->cur_wireless_mode = networkType;
  3400. //raid = networktype_to_raid(networkType);
  3401. raid = rtw_hal_networktype_to_raid(padapter, networkType);
  3402. mask = update_supported_rate(cur_network->SupportedRates, supportRateNum);
  3403. #ifdef CONFIG_80211AC_VHT
  3404. if (pmlmeinfo->VHT_enable) {
  3405. mask |= (rtw_vht_rate_to_bitmap(psta->vhtpriv.vht_mcs_map) << 12);
  3406. shortGIrate = psta->vhtpriv.sgi;
  3407. }
  3408. else
  3409. #endif
  3410. {
  3411. mask |= (pmlmeinfo->HT_enable)? update_MCS_rate(&(pmlmeinfo->HT_caps)): 0;
  3412. if (support_short_GI(padapter, &(pmlmeinfo->HT_caps)))
  3413. shortGIrate = _TRUE;
  3414. }
  3415. break;
  3416. case 1://for broadcast/multicast
  3417. supportRateNum = rtw_get_rateset_len(pmlmeinfo->FW_sta_info[mac_id].SupportedRates);
  3418. if(pmlmeext->cur_wireless_mode & WIRELESS_11B)
  3419. networkType = WIRELESS_11B;
  3420. else
  3421. networkType = WIRELESS_11G;
  3422. //raid = networktype_to_raid(networkType);
  3423. raid = rtw_hal_networktype_to_raid(padapter, networkType);
  3424. mask = update_basic_rate(cur_network->SupportedRates, supportRateNum);
  3425. break;
  3426. default: //for each sta in IBSS
  3427. supportRateNum = rtw_get_rateset_len(pmlmeinfo->FW_sta_info[mac_id].SupportedRates);
  3428. networkType = judge_network_type(padapter, pmlmeinfo->FW_sta_info[mac_id].SupportedRates, supportRateNum) & 0xf;
  3429. //pmlmeext->cur_wireless_mode = networkType;
  3430. //raid = networktype_to_raid(networkType);
  3431. raid = rtw_hal_networktype_to_raid(padapter, networkType);
  3432. mask = update_supported_rate(cur_network->SupportedRates, supportRateNum);
  3433. //todo: support HT in IBSS
  3434. break;
  3435. }
  3436. //mask &=0x0fffffff;
  3437. rate_bitmap = 0xffffffff;
  3438. #ifdef CONFIG_ODM_REFRESH_RAMASK
  3439. {
  3440. rate_bitmap = ODM_Get_Rate_Bitmap(&pHalData->odmpriv,mac_id,mask,rssi_level);
  3441. printk("%s => mac_id:%d, networkType:0x%02x, mask:0x%08x\n\t ==> rssi_level:%d, rate_bitmap:0x%08x\n",
  3442. __FUNCTION__,mac_id,networkType,mask,rssi_level,rate_bitmap);
  3443. }
  3444. #endif
  3445. mask &= rate_bitmap;
  3446. init_rate = get_highest_rate_idx(mask)&0x3f;
  3447. //arg[0] = macid
  3448. //arg[1] = raid
  3449. //arg[2] = shortGIrate
  3450. //arg[3] = init_rate
  3451. arg[0] = mac_id;
  3452. arg[1] = raid;
  3453. arg[2] = shortGIrate;
  3454. arg[3] = init_rate;
  3455. rtl8812_set_raid_cmd(padapter, mask, arg);
  3456. //set ra_id
  3457. psta->raid = raid;
  3458. psta->init_rate = init_rate;
  3459. }
  3460. void InitDefaultValue8821A(PADAPTER padapter)
  3461. {
  3462. PHAL_DATA_TYPE pHalData;
  3463. struct pwrctrl_priv *pwrctrlpriv;
  3464. struct dm_priv *pdmpriv;
  3465. u8 i;
  3466. pHalData = GET_HAL_DATA(padapter);
  3467. pwrctrlpriv = &padapter->pwrctrlpriv;
  3468. pdmpriv = &pHalData->dmpriv;
  3469. // init default value
  3470. pHalData->fw_ractrl = _FALSE;
  3471. if (!pwrctrlpriv->bkeepfwalive)
  3472. pHalData->LastHMEBoxNum = 0;
  3473. // init dm default value
  3474. pHalData->bChnlBWInitialzed = _FALSE;
  3475. pHalData->odmpriv.RFCalibrateInfo.bIQKInitialized = _FALSE;
  3476. pHalData->odmpriv.RFCalibrateInfo.TM_Trigger = 0;//for IQK
  3477. pHalData->pwrGroupCnt = 0;
  3478. pHalData->PGMaxGroup = MAX_PG_GROUP;
  3479. pHalData->odmpriv.RFCalibrateInfo.ThermalValue_HP_index = 0;
  3480. for (i = 0; i < HP_THERMAL_NUM; i++)
  3481. pHalData->odmpriv.RFCalibrateInfo.ThermalValue_HP[i] = 0;
  3482. }
  3483. VOID
  3484. _InitBeaconParameters_8812A(
  3485. IN PADAPTER Adapter
  3486. )
  3487. {
  3488. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  3489. rtw_write16(Adapter, REG_BCN_CTRL, 0x1010);
  3490. // TODO: Remove these magic number
  3491. rtw_write16(Adapter, REG_TBTT_PROHIBIT,0x6404);// ms
  3492. rtw_write8(Adapter, REG_DRVERLYINT, DRIVER_EARLY_INT_TIME_8812);// 5ms
  3493. rtw_write8(Adapter, REG_BCNDMATIM, BCN_DMA_ATIME_INT_TIME_8812); // 2ms
  3494. // Suggested by designer timchen. Change beacon AIFS to the largest number
  3495. // beacause test chip does not contension before sending beacon. by tynli. 2009.11.03
  3496. rtw_write16(Adapter, REG_BCNTCFG, 0x660F);
  3497. pHalData->RegBcnCtrlVal = rtw_read8(Adapter, REG_BCN_CTRL);
  3498. pHalData->RegTxPause = rtw_read8(Adapter, REG_TXPAUSE);
  3499. pHalData->RegFwHwTxQCtrl = rtw_read8(Adapter, REG_FWHW_TXQ_CTRL+2);
  3500. pHalData->RegReg542 = rtw_read8(Adapter, REG_TBTT_PROHIBIT+2);
  3501. pHalData->RegCR_1 = rtw_read8(Adapter, REG_CR+1);
  3502. }
  3503. static VOID
  3504. _BeaconFunctionEnable(
  3505. IN PADAPTER Adapter,
  3506. IN BOOLEAN Enable,
  3507. IN BOOLEAN Linked
  3508. )
  3509. {
  3510. rtw_write8(Adapter, REG_BCN_CTRL, (BIT4 | BIT3 | BIT1));
  3511. //SetBcnCtrlReg(Adapter, (BIT4 | BIT3 | BIT1), 0x00);
  3512. //RT_TRACE(COMP_BEACON, DBG_LOUD, ("_BeaconFunctionEnable 0x550 0x%x\n", PlatformEFIORead1Byte(Adapter, 0x550)));
  3513. rtw_write8(Adapter, REG_RD_CTRL+1, 0x6F);
  3514. }
  3515. static void ResumeTxBeacon(_adapter *padapter)
  3516. {
  3517. HAL_DATA_TYPE* pHalData = GET_HAL_DATA(padapter);
  3518. // 2010.03.01. Marked by tynli. No need to call workitem beacause we record the value
  3519. // which should be read from register to a global variable.
  3520. rtw_write8(padapter, REG_FWHW_TXQ_CTRL+2, (pHalData->RegFwHwTxQCtrl) | BIT6);
  3521. pHalData->RegFwHwTxQCtrl |= BIT6;
  3522. rtw_write8(padapter, REG_TBTT_PROHIBIT+1, 0xff);
  3523. pHalData->RegReg542 |= BIT0;
  3524. rtw_write8(padapter, REG_TBTT_PROHIBIT+2, pHalData->RegReg542);
  3525. }
  3526. static void StopTxBeacon(_adapter *padapter)
  3527. {
  3528. HAL_DATA_TYPE* pHalData = GET_HAL_DATA(padapter);
  3529. rtw_write8(padapter, REG_FWHW_TXQ_CTRL+2, (pHalData->RegFwHwTxQCtrl) & (~BIT6));
  3530. pHalData->RegFwHwTxQCtrl &= (~BIT6);
  3531. rtw_write8(padapter, REG_TBTT_PROHIBIT+1, 0x64);
  3532. pHalData->RegReg542 &= ~(BIT0);
  3533. rtw_write8(padapter, REG_TBTT_PROHIBIT+2, pHalData->RegReg542);
  3534. //todo: CheckFwRsvdPageContent(Adapter); // 2010.06.23. Added by tynli.
  3535. }
  3536. void SetBeaconRelatedRegisters8812A(PADAPTER padapter)
  3537. {
  3538. u32 value32;
  3539. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(padapter);
  3540. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  3541. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  3542. u32 bcn_ctrl_reg = REG_BCN_CTRL;
  3543. //reset TSF, enable update TSF, correcting TSF On Beacon
  3544. //REG_BCN_INTERVAL
  3545. //REG_BCNDMATIM
  3546. //REG_ATIMWND
  3547. //REG_TBTT_PROHIBIT
  3548. //REG_DRVERLYINT
  3549. //REG_BCN_MAX_ERR
  3550. //REG_BCNTCFG //(0x510)
  3551. //REG_DUAL_TSF_RST
  3552. //REG_BCN_CTRL //(0x550)
  3553. //BCN interval
  3554. #ifdef CONFIG_CONCURRENT_MODE
  3555. if (padapter->iface_type == IFACE_PORT1){
  3556. bcn_ctrl_reg = REG_BCN_CTRL_1;
  3557. }
  3558. #endif
  3559. rtw_write16(padapter, REG_BCN_INTERVAL, pmlmeinfo->bcn_interval);
  3560. rtw_write8(padapter, REG_ATIMWND, 0x02);// 2ms
  3561. _InitBeaconParameters_8812A(padapter);
  3562. rtw_write8(padapter, REG_SLOT, 0x09);
  3563. value32 =rtw_read32(padapter, REG_TCR);
  3564. value32 &= ~TSFRST;
  3565. rtw_write32(padapter, REG_TCR, value32);
  3566. value32 |= TSFRST;
  3567. rtw_write32(padapter, REG_TCR, value32);
  3568. // NOTE: Fix test chip's bug (about contention windows's randomness)
  3569. rtw_write8(padapter, REG_RXTSF_OFFSET_CCK, 0x50);
  3570. rtw_write8(padapter, REG_RXTSF_OFFSET_OFDM, 0x50);
  3571. _BeaconFunctionEnable(padapter, _TRUE, _TRUE);
  3572. ResumeTxBeacon(padapter);
  3573. //rtw_write8(padapter, 0x422, rtw_read8(padapter, 0x422)|BIT(6));
  3574. //rtw_write8(padapter, 0x541, 0xff);
  3575. //rtw_write8(padapter, 0x542, rtw_read8(padapter, 0x541)|BIT(0));
  3576. rtw_write8(padapter, bcn_ctrl_reg, rtw_read8(padapter, bcn_ctrl_reg)|BIT(1));
  3577. }
  3578. static void hw_var_set_opmode(PADAPTER Adapter, u8 variable, u8* val)
  3579. {
  3580. u8 val8;
  3581. u8 mode = *((u8 *)val);
  3582. #ifdef CONFIG_CONCURRENT_MODE
  3583. if(Adapter->iface_type == IFACE_PORT1)
  3584. {
  3585. // disable Port1 TSF update
  3586. rtw_write8(Adapter, REG_BCN_CTRL_1, rtw_read8(Adapter, REG_BCN_CTRL_1)|DIS_TSF_UDT);
  3587. // set net_type
  3588. val8 = rtw_read8(Adapter, MSR)&0x03;
  3589. val8 |= (mode<<2);
  3590. rtw_write8(Adapter, MSR, val8);
  3591. DBG_871X("%s()-%d mode = %d\n", __FUNCTION__, __LINE__, mode);
  3592. if((mode == _HW_STATE_STATION_) || (mode == _HW_STATE_NOLINK_))
  3593. {
  3594. if(!check_buddy_mlmeinfo_state(Adapter, WIFI_FW_AP_STATE))
  3595. {
  3596. #ifdef CONFIG_INTERRUPT_BASED_TXBCN
  3597. #ifdef CONFIG_INTERRUPT_BASED_TXBCN_EARLY_INT
  3598. rtw_write8(Adapter, REG_DRVERLYINT, 0x05);//restore early int time to 5ms
  3599. UpdateInterruptMask8812AU(Adapter,_TRUE, 0, IMR_BCNDMAINT1_8812);
  3600. #endif // CONFIG_INTERRUPT_BASED_TXBCN_EARLY_INT
  3601. #ifdef CONFIG_INTERRUPT_BASED_TXBCN_BCN_OK_ERR
  3602. UpdateInterruptMask8812AU(Adapter,_TRUE ,0, (IMR_TXBCN0ERR_8812|IMR_TXBCN0OK_8812));
  3603. #endif// CONFIG_INTERRUPT_BASED_TXBCN_BCN_OK_ERR
  3604. #endif //CONFIG_INTERRUPT_BASED_TXBCN
  3605. StopTxBeacon(Adapter);
  3606. }
  3607. rtw_write8(Adapter,REG_BCN_CTRL_1, 0x19);//disable atim wnd
  3608. //rtw_write8(Adapter,REG_BCN_CTRL_1, 0x18);
  3609. }
  3610. else if((mode == _HW_STATE_ADHOC_) /*|| (mode == _HW_STATE_AP_)*/)
  3611. {
  3612. ResumeTxBeacon(Adapter);
  3613. rtw_write8(Adapter,REG_BCN_CTRL_1, 0x1a);
  3614. }
  3615. else if(mode == _HW_STATE_AP_)
  3616. {
  3617. #ifdef CONFIG_INTERRUPT_BASED_TXBCN
  3618. #ifdef CONFIG_INTERRUPT_BASED_TXBCN_EARLY_INT
  3619. UpdateInterruptMask8812AU(Adapter,_TRUE ,IMR_BCNDMAINT1_8812, 0);
  3620. #endif//CONFIG_INTERRUPT_BASED_TXBCN_EARLY_INT
  3621. #ifdef CONFIG_INTERRUPT_BASED_TXBCN_BCN_OK_ERR
  3622. UpdateInterruptMask8812AU(Adapter,_TRUE ,(IMR_TXBCN0ERR_8812|IMR_TXBCN0OK_8812), 0);
  3623. #endif//CONFIG_INTERRUPT_BASED_TXBCN_BCN_OK_ERR
  3624. #endif //CONFIG_INTERRUPT_BASED_TXBCN
  3625. ResumeTxBeacon(Adapter);
  3626. rtw_write8(Adapter, REG_BCN_CTRL_1, 0x12);
  3627. //Set RCR
  3628. //rtw_write32(padapter, REG_RCR, 0x70002a8e);//CBSSID_DATA must set to 0
  3629. //rtw_write32(Adapter, REG_RCR, 0x7000228e);//CBSSID_DATA must set to 0
  3630. rtw_write32(Adapter, REG_RCR, 0x7000208e);//CBSSID_DATA must set to 0,reject ICV_ERR packet
  3631. //enable to rx data frame
  3632. rtw_write16(Adapter, REG_RXFLTMAP2, 0xFFFF);
  3633. //enable to rx ps-poll
  3634. rtw_write16(Adapter, REG_RXFLTMAP1, 0x0400);
  3635. //Beacon Control related register for first time
  3636. rtw_write8(Adapter, REG_BCNDMATIM, 0x02); // 2ms
  3637. //rtw_write8(Adapter, REG_BCN_MAX_ERR, 0xFF);
  3638. rtw_write8(Adapter, REG_ATIMWND_1, 0x0a); // 10ms for port1
  3639. rtw_write16(Adapter, REG_BCNTCFG, 0x00);
  3640. rtw_write16(Adapter, REG_TBTT_PROHIBIT, 0xff04);
  3641. rtw_write16(Adapter, REG_TSFTR_SYN_OFFSET, 0x7fff);// +32767 (~32ms)
  3642. //reset TSF2
  3643. rtw_write8(Adapter, REG_DUAL_TSF_RST, BIT(1));
  3644. //enable BCN1 Function for if2
  3645. //don't enable update TSF1 for if2 (due to TSF update when beacon/probe rsp are received)
  3646. rtw_write8(Adapter, REG_BCN_CTRL_1, (DIS_TSF_UDT|EN_BCN_FUNCTION | EN_TXBCN_RPT|DIS_BCNQ_SUB));
  3647. if(IS_HARDWARE_TYPE_8821(Adapter))
  3648. {
  3649. // select BCN on port 1
  3650. rtw_write8(Adapter, REG_CCK_CHECK_8812, rtw_read8(Adapter, REG_CCK_CHECK_8812)|BIT(5));
  3651. }
  3652. #ifdef CONFIG_CONCURRENT_MODE
  3653. if(check_buddy_fwstate(Adapter, WIFI_FW_NULL_STATE))
  3654. rtw_write8(Adapter, REG_BCN_CTRL,
  3655. rtw_read8(Adapter, REG_BCN_CTRL) & ~EN_BCN_FUNCTION);
  3656. #endif
  3657. //BCN1 TSF will sync to BCN0 TSF with offset(0x518) if if1_sta linked
  3658. //rtw_write8(Adapter, REG_BCN_CTRL_1, rtw_read8(Adapter, REG_BCN_CTRL_1)|BIT(5));
  3659. //rtw_write8(Adapter, REG_DUAL_TSF_RST, BIT(3));
  3660. //dis BCN0 ATIM WND if if1 is station
  3661. rtw_write8(Adapter, REG_BCN_CTRL, rtw_read8(Adapter, REG_BCN_CTRL)|DIS_ATIM);
  3662. #ifdef CONFIG_TSF_RESET_OFFLOAD
  3663. // Reset TSF for STA+AP concurrent mode
  3664. if ( check_buddy_fwstate(Adapter, (WIFI_STATION_STATE|WIFI_ASOC_STATE)) ) {
  3665. if (reset_tsf(Adapter, IFACE_PORT1) == _FALSE)
  3666. DBG_871X("ERROR! %s()-%d: Reset port1 TSF fail\n",
  3667. __FUNCTION__, __LINE__);
  3668. }
  3669. #endif // CONFIG_TSF_RESET_OFFLOAD
  3670. }
  3671. }
  3672. else //else for port0
  3673. #endif // CONFIG_CONCURRENT_MODE
  3674. {
  3675. // disable Port0 TSF update
  3676. rtw_write8(Adapter, REG_BCN_CTRL, rtw_read8(Adapter, REG_BCN_CTRL)|DIS_TSF_UDT);
  3677. // set net_type
  3678. val8 = rtw_read8(Adapter, MSR)&0x0c;
  3679. val8 |= mode;
  3680. rtw_write8(Adapter, MSR, val8);
  3681. DBG_871X("%s()-%d mode = %d\n", __FUNCTION__, __LINE__, mode);
  3682. if((mode == _HW_STATE_STATION_) || (mode == _HW_STATE_NOLINK_))
  3683. {
  3684. #ifdef CONFIG_CONCURRENT_MODE
  3685. if(!check_buddy_mlmeinfo_state(Adapter, WIFI_FW_AP_STATE))
  3686. #endif // CONFIG_CONCURRENT_MODE
  3687. {
  3688. #ifdef CONFIG_INTERRUPT_BASED_TXBCN
  3689. #ifdef CONFIG_INTERRUPT_BASED_TXBCN_EARLY_INT
  3690. rtw_write8(Adapter, REG_DRVERLYINT, 0x05);//restore early int time to 5ms
  3691. UpdateInterruptMask8812AU(Adapter,_TRUE, 0, IMR_BCNDMAINT0_8812);
  3692. #endif//CONFIG_INTERRUPT_BASED_TXBCN_EARLY_INT
  3693. #ifdef CONFIG_INTERRUPT_BASED_TXBCN_BCN_OK_ERR
  3694. UpdateInterruptMask8812AU(Adapter,_TRUE ,0, (IMR_TXBCN0ERR_8812|IMR_TXBCN0OK_8812));
  3695. #endif //CONFIG_INTERRUPT_BASED_TXBCN_BCN_OK_ERR
  3696. #endif //CONFIG_INTERRUPT_BASED_TXBCN
  3697. StopTxBeacon(Adapter);
  3698. }
  3699. rtw_write8(Adapter,REG_BCN_CTRL, 0x19);//disable atim wnd
  3700. //rtw_write8(Adapter,REG_BCN_CTRL, 0x18);
  3701. }
  3702. else if((mode == _HW_STATE_ADHOC_) /*|| (mode == _HW_STATE_AP_)*/)
  3703. {
  3704. ResumeTxBeacon(Adapter);
  3705. rtw_write8(Adapter,REG_BCN_CTRL, 0x1a);
  3706. }
  3707. else if(mode == _HW_STATE_AP_)
  3708. {
  3709. #ifdef CONFIG_INTERRUPT_BASED_TXBCN
  3710. #ifdef CONFIG_INTERRUPT_BASED_TXBCN_EARLY_INT
  3711. UpdateInterruptMask8812AU(Adapter,_TRUE ,IMR_BCNDMAINT0_8812, 0);
  3712. #endif//CONFIG_INTERRUPT_BASED_TXBCN_EARLY_INT
  3713. #ifdef CONFIG_INTERRUPT_BASED_TXBCN_BCN_OK_ERR
  3714. UpdateInterruptMask8812AU(Adapter,_TRUE ,(IMR_TXBCN0ERR_8812|IMR_TXBCN0OK_8812), 0);
  3715. #endif//CONFIG_INTERRUPT_BASED_TXBCN_BCN_OK_ERR
  3716. #endif //CONFIG_INTERRUPT_BASED_TXBCN
  3717. ResumeTxBeacon(Adapter);
  3718. rtw_write8(Adapter, REG_BCN_CTRL, 0x12);
  3719. //Set RCR
  3720. //rtw_write32(padapter, REG_RCR, 0x70002a8e);//CBSSID_DATA must set to 0
  3721. //rtw_write32(Adapter, REG_RCR, 0x7000228e);//CBSSID_DATA must set to 0
  3722. rtw_write32(Adapter, REG_RCR, 0x7000208e);//CBSSID_DATA must set to 0,reject ICV_ERR packet
  3723. //enable to rx data frame
  3724. rtw_write16(Adapter, REG_RXFLTMAP2, 0xFFFF);
  3725. //enable to rx ps-poll
  3726. rtw_write16(Adapter, REG_RXFLTMAP1, 0x0400);
  3727. //Beacon Control related register for first time
  3728. rtw_write8(Adapter, REG_BCNDMATIM, 0x02); // 2ms
  3729. //rtw_write8(Adapter, REG_BCN_MAX_ERR, 0xFF);
  3730. rtw_write8(Adapter, REG_ATIMWND, 0x0a); // 10ms
  3731. rtw_write16(Adapter, REG_BCNTCFG, 0x00);
  3732. rtw_write16(Adapter, REG_TBTT_PROHIBIT, 0xff04);
  3733. rtw_write16(Adapter, REG_TSFTR_SYN_OFFSET, 0x7fff);// +32767 (~32ms)
  3734. //reset TSF
  3735. rtw_write8(Adapter, REG_DUAL_TSF_RST, BIT(0));
  3736. //enable BCN0 Function for if1
  3737. //don't enable update TSF0 for if1 (due to TSF update when beacon/probe rsp are received)
  3738. rtw_write8(Adapter, REG_BCN_CTRL, (DIS_TSF_UDT|EN_BCN_FUNCTION | EN_TXBCN_RPT|DIS_BCNQ_SUB));
  3739. if(IS_HARDWARE_TYPE_8821(Adapter))
  3740. {
  3741. // select BCN on port 0
  3742. rtw_write8(Adapter, REG_CCK_CHECK_8812, rtw_read8(Adapter, REG_CCK_CHECK_8812)&(~BIT(5)));
  3743. }
  3744. #ifdef CONFIG_CONCURRENT_MODE
  3745. if(check_buddy_fwstate(Adapter, WIFI_FW_NULL_STATE))
  3746. rtw_write8(Adapter, REG_BCN_CTRL_1,
  3747. rtw_read8(Adapter, REG_BCN_CTRL_1) & ~EN_BCN_FUNCTION);
  3748. #endif
  3749. //dis BCN1 ATIM WND if if2 is station
  3750. rtw_write8(Adapter, REG_BCN_CTRL_1, rtw_read8(Adapter, REG_BCN_CTRL_1)|DIS_ATIM);
  3751. #ifdef CONFIG_TSF_RESET_OFFLOAD
  3752. // Reset TSF for STA+AP concurrent mode
  3753. if ( check_buddy_fwstate(Adapter, (WIFI_STATION_STATE|WIFI_ASOC_STATE)) ) {
  3754. if (reset_tsf(Adapter, IFACE_PORT0) == _FALSE)
  3755. DBG_871X("ERROR! %s()-%d: Reset port0 TSF fail\n",
  3756. __FUNCTION__, __LINE__);
  3757. }
  3758. #endif // CONFIG_TSF_RESET_OFFLOAD
  3759. }
  3760. }
  3761. }
  3762. static void hw_var_set_macaddr(PADAPTER Adapter, u8 variable, u8* val)
  3763. {
  3764. u8 idx = 0;
  3765. u32 reg_macid;
  3766. #ifdef CONFIG_CONCURRENT_MODE
  3767. if(Adapter->iface_type == IFACE_PORT1)
  3768. {
  3769. reg_macid = REG_MACID1;
  3770. }
  3771. else
  3772. #endif
  3773. {
  3774. reg_macid = REG_MACID;
  3775. }
  3776. for(idx = 0 ; idx < 6; idx++)
  3777. {
  3778. rtw_write8(Adapter, (reg_macid+idx), val[idx]);
  3779. }
  3780. }
  3781. static void hw_var_set_bssid(PADAPTER Adapter, u8 variable, u8* val)
  3782. {
  3783. u8 idx = 0;
  3784. u32 reg_bssid;
  3785. #ifdef CONFIG_CONCURRENT_MODE
  3786. if(Adapter->iface_type == IFACE_PORT1)
  3787. {
  3788. reg_bssid = REG_BSSID1;
  3789. }
  3790. else
  3791. #endif
  3792. {
  3793. reg_bssid = REG_BSSID;
  3794. }
  3795. for(idx = 0 ; idx < 6; idx++)
  3796. {
  3797. rtw_write8(Adapter, (reg_bssid+idx), val[idx]);
  3798. }
  3799. }
  3800. static void hw_var_set_bcn_func(PADAPTER Adapter, u8 variable, u8* val)
  3801. {
  3802. u32 bcn_ctrl_reg;
  3803. #ifdef CONFIG_CONCURRENT_MODE
  3804. if(Adapter->iface_type == IFACE_PORT1)
  3805. {
  3806. bcn_ctrl_reg = REG_BCN_CTRL_1;
  3807. }
  3808. else
  3809. #endif
  3810. {
  3811. bcn_ctrl_reg = REG_BCN_CTRL;
  3812. }
  3813. if(*((u8 *)val))
  3814. {
  3815. rtw_write8(Adapter, bcn_ctrl_reg, (EN_BCN_FUNCTION | EN_TXBCN_RPT));
  3816. }
  3817. else
  3818. {
  3819. rtw_write8(Adapter, bcn_ctrl_reg, rtw_read8(Adapter, bcn_ctrl_reg)&(~(EN_BCN_FUNCTION | EN_TXBCN_RPT)));
  3820. }
  3821. }
  3822. static void hw_var_set_correct_tsf(PADAPTER Adapter, u8 variable, u8* val)
  3823. {
  3824. #ifdef CONFIG_CONCURRENT_MODE
  3825. u64 tsf;
  3826. struct mlme_ext_priv *pmlmeext = &Adapter->mlmeextpriv;
  3827. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  3828. //tsf = pmlmeext->TSFValue - ((u32)pmlmeext->TSFValue % (pmlmeinfo->bcn_interval*1024)) -1024; //us
  3829. tsf = pmlmeext->TSFValue - rtw_modular64(pmlmeext->TSFValue, (pmlmeinfo->bcn_interval*1024)) -1024; //us
  3830. if(((pmlmeinfo->state&0x03) == WIFI_FW_ADHOC_STATE) || ((pmlmeinfo->state&0x03) == WIFI_FW_AP_STATE))
  3831. {
  3832. //pHalData->RegTxPause |= STOP_BCNQ;BIT(6)
  3833. //rtw_write8(Adapter, REG_TXPAUSE, (rtw_read8(Adapter, REG_TXPAUSE)|BIT(6)));
  3834. StopTxBeacon(Adapter);
  3835. }
  3836. if(Adapter->iface_type == IFACE_PORT1)
  3837. {
  3838. //disable related TSF function
  3839. rtw_write8(Adapter, REG_BCN_CTRL_1, rtw_read8(Adapter, REG_BCN_CTRL_1)&(~BIT(3)));
  3840. rtw_write32(Adapter, REG_TSFTR1, tsf);
  3841. rtw_write32(Adapter, REG_TSFTR1+4, tsf>>32);
  3842. //enable related TSF function
  3843. rtw_write8(Adapter, REG_BCN_CTRL_1, rtw_read8(Adapter, REG_BCN_CTRL_1)|BIT(3));
  3844. // Update buddy port's TSF if it is SoftAP for beacon TX issue!
  3845. if ( (pmlmeinfo->state&0x03) == WIFI_FW_STATION_STATE
  3846. && check_buddy_fwstate(Adapter, WIFI_AP_STATE)
  3847. ) {
  3848. //disable related TSF function
  3849. rtw_write8(Adapter, REG_BCN_CTRL, rtw_read8(Adapter, REG_BCN_CTRL)&(~BIT(3)));
  3850. rtw_write32(Adapter, REG_TSFTR, tsf);
  3851. rtw_write32(Adapter, REG_TSFTR+4, tsf>>32);
  3852. //enable related TSF function
  3853. rtw_write8(Adapter, REG_BCN_CTRL, rtw_read8(Adapter, REG_BCN_CTRL)|BIT(3));
  3854. #ifdef CONFIG_TSF_RESET_OFFLOAD
  3855. // Update buddy port's TSF(TBTT) if it is SoftAP for beacon TX issue!
  3856. if (reset_tsf(Adapter, IFACE_PORT0) == _FALSE)
  3857. DBG_871X("ERROR! %s()-%d: Reset port0 TSF fail\n",
  3858. __FUNCTION__, __LINE__);
  3859. #endif // CONFIG_TSF_RESET_OFFLOAD
  3860. }
  3861. }
  3862. else
  3863. {
  3864. //disable related TSF function
  3865. rtw_write8(Adapter, REG_BCN_CTRL, rtw_read8(Adapter, REG_BCN_CTRL)&(~BIT(3)));
  3866. rtw_write32(Adapter, REG_TSFTR, tsf);
  3867. rtw_write32(Adapter, REG_TSFTR+4, tsf>>32);
  3868. //enable related TSF function
  3869. rtw_write8(Adapter, REG_BCN_CTRL, rtw_read8(Adapter, REG_BCN_CTRL)|BIT(3));
  3870. // Update buddy port's TSF if it is SoftAP for beacon TX issue!
  3871. if ( (pmlmeinfo->state&0x03) == WIFI_FW_STATION_STATE
  3872. && check_buddy_fwstate(Adapter, WIFI_AP_STATE)
  3873. ) {
  3874. //disable related TSF function
  3875. rtw_write8(Adapter, REG_BCN_CTRL_1, rtw_read8(Adapter, REG_BCN_CTRL_1)&(~BIT(3)));
  3876. rtw_write32(Adapter, REG_TSFTR1, tsf);
  3877. rtw_write32(Adapter, REG_TSFTR1+4, tsf>>32);
  3878. //enable related TSF function
  3879. rtw_write8(Adapter, REG_BCN_CTRL_1, rtw_read8(Adapter, REG_BCN_CTRL_1)|BIT(3));
  3880. #ifdef CONFIG_TSF_RESET_OFFLOAD
  3881. // Update buddy port's TSF if it is SoftAP for beacon TX issue!
  3882. if (reset_tsf(Adapter, IFACE_PORT1) == _FALSE)
  3883. DBG_871X("ERROR! %s()-%d: Reset port1 TSF fail\n",
  3884. __FUNCTION__, __LINE__);
  3885. #endif // CONFIG_TSF_RESET_OFFLOAD
  3886. }
  3887. }
  3888. if(((pmlmeinfo->state&0x03) == WIFI_FW_ADHOC_STATE) || ((pmlmeinfo->state&0x03) == WIFI_FW_AP_STATE))
  3889. {
  3890. //pHalData->RegTxPause &= (~STOP_BCNQ);
  3891. //rtw_write8(Adapter, REG_TXPAUSE, (rtw_read8(Adapter, REG_TXPAUSE)&(~BIT(6))));
  3892. ResumeTxBeacon(Adapter);
  3893. }
  3894. #endif
  3895. }
  3896. static void hw_var_set_mlme_disconnect(PADAPTER Adapter, u8 variable, u8* val)
  3897. {
  3898. #ifdef CONFIG_CONCURRENT_MODE
  3899. if(check_buddy_mlmeinfo_state(Adapter, _HW_STATE_NOLINK_))
  3900. rtw_write16(Adapter, REG_RXFLTMAP2, 0x00);
  3901. if(Adapter->iface_type == IFACE_PORT1)
  3902. {
  3903. //reset TSF1
  3904. rtw_write8(Adapter, REG_DUAL_TSF_RST, BIT(1));
  3905. //disable update TSF1
  3906. rtw_write8(Adapter, REG_BCN_CTRL_1, rtw_read8(Adapter, REG_BCN_CTRL_1)|BIT(4));
  3907. }
  3908. else
  3909. {
  3910. //reset TSF
  3911. rtw_write8(Adapter, REG_DUAL_TSF_RST, BIT(0));
  3912. //disable update TSF
  3913. rtw_write8(Adapter, REG_BCN_CTRL, rtw_read8(Adapter, REG_BCN_CTRL)|BIT(4));
  3914. }
  3915. #endif
  3916. }
  3917. static void hw_var_set_mlme_sitesurvey(PADAPTER Adapter, u8 variable, u8* val)
  3918. {
  3919. u32 value_rcr, rcr_clear_bit, reg_bcn_ctl;
  3920. u16 value_rxfltmap2;
  3921. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  3922. struct mlme_priv *pmlmepriv=&(Adapter->mlmepriv);
  3923. #ifdef CONFIG_CONCURRENT_MODE
  3924. if(Adapter->iface_type == IFACE_PORT1)
  3925. reg_bcn_ctl = REG_BCN_CTRL_1;
  3926. else
  3927. #endif
  3928. reg_bcn_ctl = REG_BCN_CTRL;
  3929. #ifdef CONFIG_FIND_BEST_CHANNEL
  3930. rcr_clear_bit = (RCR_CBSSID_BCN | RCR_CBSSID_DATA);
  3931. // Recieve all data frames
  3932. value_rxfltmap2 = 0xFFFF;
  3933. #else /* CONFIG_FIND_BEST_CHANNEL */
  3934. rcr_clear_bit = RCR_CBSSID_BCN;
  3935. //config RCR to receive different BSSID & not to receive data frame
  3936. value_rxfltmap2 = 0;
  3937. #endif /* CONFIG_FIND_BEST_CHANNEL */
  3938. if( (check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE)
  3939. #ifdef CONFIG_CONCURRENT_MODE
  3940. || (check_buddy_fwstate(Adapter, WIFI_AP_STATE) == _TRUE)
  3941. #endif
  3942. )
  3943. {
  3944. rcr_clear_bit = RCR_CBSSID_BCN;
  3945. }
  3946. #ifdef CONFIG_TDLS
  3947. // TDLS will clear RCR_CBSSID_DATA bit for connection.
  3948. else if (Adapter->tdlsinfo.setup_state & TDLS_LINKED_STATE)
  3949. {
  3950. rcr_clear_bit = RCR_CBSSID_BCN;
  3951. }
  3952. #endif // CONFIG_TDLS
  3953. value_rcr = rtw_read32(Adapter, REG_RCR);
  3954. if(*((u8 *)val))//under sitesurvey
  3955. {
  3956. value_rcr &= ~(rcr_clear_bit);
  3957. rtw_write32(Adapter, REG_RCR, value_rcr);
  3958. rtw_write16(Adapter, REG_RXFLTMAP2, value_rxfltmap2);
  3959. if (check_fwstate(pmlmepriv, WIFI_STATION_STATE | WIFI_ADHOC_STATE |WIFI_ADHOC_MASTER_STATE)) {
  3960. //disable update TSF
  3961. rtw_write8(Adapter, reg_bcn_ctl, rtw_read8(Adapter, reg_bcn_ctl)|DIS_TSF_UDT);
  3962. }
  3963. // Save orignal RRSR setting.
  3964. pHalData->RegRRSR = rtw_read16(Adapter, REG_RRSR);
  3965. #ifdef CONFIG_CONCURRENT_MODE
  3966. if(check_buddy_mlmeinfo_state(Adapter, WIFI_FW_AP_STATE) &&
  3967. check_buddy_fwstate(Adapter, _FW_LINKED))
  3968. {
  3969. StopTxBeacon(Adapter);
  3970. }
  3971. #endif
  3972. }
  3973. else//sitesurvey done
  3974. {
  3975. if(check_fwstate(pmlmepriv, (_FW_LINKED|WIFI_AP_STATE))
  3976. #ifdef CONFIG_CONCURRENT_MODE
  3977. || check_buddy_fwstate(Adapter, (_FW_LINKED|WIFI_AP_STATE))
  3978. #endif
  3979. )
  3980. {
  3981. //enable to rx data frame
  3982. rtw_write16(Adapter, REG_RXFLTMAP2,0xFFFF);
  3983. }
  3984. if (check_fwstate(pmlmepriv, WIFI_STATION_STATE | WIFI_ADHOC_STATE |WIFI_ADHOC_MASTER_STATE)) {
  3985. //enable update TSF
  3986. rtw_write8(Adapter, reg_bcn_ctl, rtw_read8(Adapter, reg_bcn_ctl)&(~(DIS_TSF_UDT)));
  3987. }
  3988. value_rcr |= rcr_clear_bit;
  3989. rtw_write32(Adapter, REG_RCR, value_rcr);
  3990. // Restore orignal RRSR setting.
  3991. rtw_write16(Adapter, REG_RRSR, pHalData->RegRRSR);
  3992. #ifdef CONFIG_CONCURRENT_MODE
  3993. if(check_buddy_mlmeinfo_state(Adapter, WIFI_FW_AP_STATE) &&
  3994. check_buddy_fwstate(Adapter, _FW_LINKED))
  3995. {
  3996. ResumeTxBeacon(Adapter);
  3997. }
  3998. #endif
  3999. }
  4000. }
  4001. static void hw_var_set_mlme_join(PADAPTER Adapter, u8 variable, u8* val)
  4002. {
  4003. #ifdef CONFIG_CONCURRENT_MODE
  4004. u8 RetryLimit = 0x30;
  4005. u8 type = *((u8 *)val);
  4006. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  4007. struct mlme_priv *pmlmepriv = &Adapter->mlmepriv;
  4008. EEPROM_EFUSE_PRIV *pEEPROM = GET_EEPROM_EFUSE_PRIV(Adapter);
  4009. if(type == 0) // prepare to join
  4010. {
  4011. if(check_buddy_mlmeinfo_state(Adapter, WIFI_FW_AP_STATE) &&
  4012. check_buddy_fwstate(Adapter, _FW_LINKED))
  4013. {
  4014. StopTxBeacon(Adapter);
  4015. }
  4016. //enable to rx data frame.Accept all data frame
  4017. //rtw_write32(padapter, REG_RCR, rtw_read32(padapter, REG_RCR)|RCR_ADF);
  4018. rtw_write16(Adapter, REG_RXFLTMAP2,0xFFFF);
  4019. if(check_buddy_mlmeinfo_state(Adapter, WIFI_FW_AP_STATE))
  4020. {
  4021. rtw_write32(Adapter, REG_RCR, rtw_read32(Adapter, REG_RCR)|RCR_CBSSID_BCN);
  4022. }
  4023. else
  4024. {
  4025. rtw_write32(Adapter, REG_RCR, rtw_read32(Adapter, REG_RCR)|RCR_CBSSID_DATA|RCR_CBSSID_BCN);
  4026. }
  4027. if(check_fwstate(pmlmepriv, WIFI_STATION_STATE) == _TRUE)
  4028. {
  4029. RetryLimit = (pEEPROM->CustomerID == RT_CID_CCX) ? 7 : 48;
  4030. }
  4031. else // Ad-hoc Mode
  4032. {
  4033. RetryLimit = 0x7;
  4034. }
  4035. }
  4036. else if(type == 1) //joinbss_event call back when join res < 0
  4037. {
  4038. if(check_buddy_mlmeinfo_state(Adapter, _HW_STATE_NOLINK_))
  4039. rtw_write16(Adapter, REG_RXFLTMAP2,0x00);
  4040. if(check_buddy_mlmeinfo_state(Adapter, WIFI_FW_AP_STATE) &&
  4041. check_buddy_fwstate(Adapter, _FW_LINKED))
  4042. {
  4043. ResumeTxBeacon(Adapter);
  4044. //reset TSF 1/2 after ResumeTxBeacon
  4045. rtw_write8(Adapter, REG_DUAL_TSF_RST, BIT(1)|BIT(0));
  4046. }
  4047. }
  4048. else if(type == 2) //sta add event call back
  4049. {
  4050. //enable update TSF
  4051. if(Adapter->iface_type == IFACE_PORT1)
  4052. rtw_write8(Adapter, REG_BCN_CTRL_1, rtw_read8(Adapter, REG_BCN_CTRL_1)&(~BIT(4)));
  4053. else
  4054. rtw_write8(Adapter, REG_BCN_CTRL, rtw_read8(Adapter, REG_BCN_CTRL)&(~BIT(4)));
  4055. if(check_fwstate(pmlmepriv, WIFI_ADHOC_STATE|WIFI_ADHOC_MASTER_STATE))
  4056. {
  4057. //fixed beacon issue for 8191su...........
  4058. rtw_write8(Adapter,0x542 ,0x02);
  4059. RetryLimit = 0x7;
  4060. }
  4061. if(check_buddy_mlmeinfo_state(Adapter, WIFI_FW_AP_STATE) &&
  4062. check_buddy_fwstate(Adapter, _FW_LINKED))
  4063. {
  4064. ResumeTxBeacon(Adapter);
  4065. //reset TSF 1/2 after ResumeTxBeacon
  4066. rtw_write8(Adapter, REG_DUAL_TSF_RST, BIT(1)|BIT(0));
  4067. }
  4068. }
  4069. rtw_write16(Adapter, REG_RL, RetryLimit << RETRY_LIMIT_SHORT_SHIFT | RetryLimit << RETRY_LIMIT_LONG_SHIFT);
  4070. #endif
  4071. }
  4072. void SetHwReg8812A(PADAPTER padapter, u8 variable, u8 *pval)
  4073. {
  4074. PHAL_DATA_TYPE pHalData;
  4075. struct dm_priv *pdmpriv;
  4076. PDM_ODM_T podmpriv;
  4077. u8 val8;
  4078. u16 val16;
  4079. u32 val32;
  4080. _func_enter_;
  4081. pHalData = GET_HAL_DATA(padapter);
  4082. pdmpriv = &pHalData->dmpriv;
  4083. podmpriv = &pHalData->odmpriv;
  4084. switch (variable)
  4085. {
  4086. case HW_VAR_MEDIA_STATUS:
  4087. val8 = rtw_read8(padapter, MSR) & 0x0c;
  4088. val8 |= *pval;
  4089. rtw_write8(padapter, MSR, val8);
  4090. break;
  4091. case HW_VAR_MEDIA_STATUS1:
  4092. val8 = rtw_read8(padapter, MSR) & 0x03;
  4093. val8 |= *pval << 2;
  4094. rtw_write8(padapter, MSR, val8);
  4095. break;
  4096. case HW_VAR_SET_OPMODE:
  4097. hw_var_set_opmode(padapter, variable, pval);
  4098. break;
  4099. case HW_VAR_MAC_ADDR:
  4100. hw_var_set_macaddr(padapter, variable, pval);
  4101. break;
  4102. case HW_VAR_BSSID:
  4103. hw_var_set_bssid(padapter, variable, pval);
  4104. break;
  4105. case HW_VAR_BASIC_RATE:
  4106. {
  4107. u16 BrateCfg = 0;
  4108. u8 RateIndex = 0;
  4109. // 2007.01.16, by Emily
  4110. // Select RRSR (in Legacy-OFDM and CCK)
  4111. // For 8190, we select only 24M, 12M, 6M, 11M, 5.5M, 2M, and 1M from the Basic rate.
  4112. // We do not use other rates.
  4113. HalSetBrateCfg(padapter, pval, &BrateCfg);
  4114. if(pHalData->CurrentBandType == BAND_ON_2_4G)
  4115. {
  4116. //CCK 2M ACK should be disabled for some BCM and Atheros AP IOT
  4117. //because CCK 2M has poor TXEVM
  4118. //CCK 5.5M & 11M ACK should be enabled for better performance
  4119. pHalData->BasicRateSet = BrateCfg = (BrateCfg |0xd) & 0x15d;
  4120. BrateCfg |= 0x01; // default enable 1M ACK rate
  4121. }
  4122. else // 5G
  4123. {
  4124. pHalData->BasicRateSet &= 0xFF0;
  4125. BrateCfg |= 0x10; // default enable 6M ACK rate
  4126. }
  4127. // DBG_8192C("HW_VAR_BASIC_RATE: BrateCfg(%#x)\n", BrateCfg);
  4128. // Set RRSR rate table.
  4129. rtw_write8(padapter, REG_RRSR, BrateCfg&0xff);
  4130. rtw_write8(padapter, REG_RRSR+1, (BrateCfg>>8)&0xff);
  4131. rtw_write8(padapter, REG_RRSR+2, rtw_read8(padapter, REG_RRSR+2)&0xf0);
  4132. }
  4133. break;
  4134. case HW_VAR_TXPAUSE:
  4135. rtw_write8(padapter, REG_TXPAUSE, *pval);
  4136. break;
  4137. case HW_VAR_BCN_FUNC:
  4138. hw_var_set_bcn_func(padapter, variable, pval);
  4139. break;
  4140. case HW_VAR_CORRECT_TSF:
  4141. #ifdef CONFIG_CONCURRENT_MODE
  4142. hw_var_set_correct_tsf(padapter, variable, pval);
  4143. #else
  4144. {
  4145. u64 tsf;
  4146. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  4147. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  4148. //tsf = pmlmeext->TSFValue - ((u32)pmlmeext->TSFValue % (pmlmeinfo->bcn_interval*1024)) -1024; //us
  4149. tsf = pmlmeext->TSFValue - rtw_modular64(pmlmeext->TSFValue, (pmlmeinfo->bcn_interval*1024)) -1024; //us
  4150. if(((pmlmeinfo->state&0x03) == WIFI_FW_ADHOC_STATE) || ((pmlmeinfo->state&0x03) == WIFI_FW_AP_STATE))
  4151. {
  4152. //pHalData->RegTxPause |= STOP_BCNQ;BIT(6)
  4153. //rtw_write8(padapter, REG_TXPAUSE, (rtw_read8(padapter, REG_TXPAUSE)|BIT(6)));
  4154. StopTxBeacon(padapter);
  4155. }
  4156. //disable related TSF function
  4157. rtw_write8(padapter, REG_BCN_CTRL, rtw_read8(padapter, REG_BCN_CTRL)&(~BIT(3)));
  4158. rtw_write32(padapter, REG_TSFTR, tsf);
  4159. rtw_write32(padapter, REG_TSFTR+4, tsf>>32);
  4160. //enable related TSF function
  4161. rtw_write8(padapter, REG_BCN_CTRL, rtw_read8(padapter, REG_BCN_CTRL)|BIT(3));
  4162. if(((pmlmeinfo->state&0x03) == WIFI_FW_ADHOC_STATE) || ((pmlmeinfo->state&0x03) == WIFI_FW_AP_STATE))
  4163. {
  4164. //pHalData->RegTxPause &= (~STOP_BCNQ);
  4165. //rtw_write8(padapter, REG_TXPAUSE, (rtw_read8(padapter, REG_TXPAUSE)&(~BIT(6))));
  4166. ResumeTxBeacon(padapter);
  4167. }
  4168. }
  4169. #endif
  4170. break;
  4171. case HW_VAR_CHECK_BSSID:
  4172. val32 = rtw_read32(padapter, REG_RCR);
  4173. if (*pval)
  4174. val32 |= RCR_CBSSID_DATA|RCR_CBSSID_BCN;
  4175. else
  4176. val32 &= ~(RCR_CBSSID_DATA|RCR_CBSSID_BCN);
  4177. rtw_write32(padapter, REG_RCR, val32);
  4178. break;
  4179. case HW_VAR_MLME_DISCONNECT:
  4180. #ifdef CONFIG_CONCURRENT_MODE
  4181. hw_var_set_mlme_disconnect(padapter, variable, pval);
  4182. #else
  4183. {
  4184. // Set RCR to not to receive data frame when NO LINK state
  4185. // val32 = rtw_read32(padapter, REG_RCR);
  4186. // val32 &= ~RCR_ADF;
  4187. // rtw_write32(padapter, REG_RCR, val32);
  4188. // reject all data frames
  4189. rtw_write16(padapter, REG_RXFLTMAP2, 0x00);
  4190. // reset TSF
  4191. val8 = BIT(0) | BIT(1);
  4192. rtw_write8(padapter, REG_DUAL_TSF_RST, val8);
  4193. // disable update TSF
  4194. val8 = rtw_read8(padapter, REG_BCN_CTRL);
  4195. val8 |= BIT(4);
  4196. rtw_write8(padapter, REG_BCN_CTRL, val8);
  4197. }
  4198. #endif
  4199. break;
  4200. case HW_VAR_MLME_SITESURVEY:
  4201. hw_var_set_mlme_sitesurvey(padapter, variable, pval);
  4202. #ifdef CONFIG_BT_COEXIST
  4203. BT_WifiScanNotify(padapter, *pval?_TRUE:_FALSE);
  4204. #endif
  4205. break;
  4206. case HW_VAR_MLME_JOIN:
  4207. #ifdef CONFIG_CONCURRENT_MODE
  4208. hw_var_set_mlme_join(padapter, variable, pval);
  4209. #else // !CONFIG_CONCURRENT_MODE
  4210. {
  4211. u8 RetryLimit = 0x30;
  4212. u8 type = *(u8*)pval;
  4213. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  4214. EEPROM_EFUSE_PRIV *pEEPROM = GET_EEPROM_EFUSE_PRIV(padapter);
  4215. if (type == 0) // prepare to join
  4216. {
  4217. //enable to rx data frame.Accept all data frame
  4218. //rtw_write32(padapter, REG_RCR, rtw_read32(padapter, REG_RCR)|RCR_ADF);
  4219. rtw_write16(padapter, REG_RXFLTMAP2, 0xFFFF);
  4220. val32 = rtw_read32(padapter, REG_RCR);
  4221. if (padapter->in_cta_test)
  4222. val32 &= ~(RCR_CBSSID_DATA | RCR_CBSSID_BCN);//| RCR_ADF
  4223. else
  4224. val32 |= RCR_CBSSID_DATA|RCR_CBSSID_BCN;
  4225. rtw_write32(padapter, REG_RCR, val32);
  4226. if (check_fwstate(pmlmepriv, WIFI_STATION_STATE) == _TRUE)
  4227. {
  4228. RetryLimit = (pEEPROM->CustomerID == RT_CID_CCX) ? 7 : 48;
  4229. }
  4230. else // Ad-hoc Mode
  4231. {
  4232. RetryLimit = 0x7;
  4233. }
  4234. pHalData->bNeedIQK = _TRUE;
  4235. }
  4236. else if (type == 1) //joinbss_event call back when join res < 0
  4237. {
  4238. rtw_write16(padapter, REG_RXFLTMAP2, 0x00);
  4239. }
  4240. else if (type == 2) //sta add event call back
  4241. {
  4242. //enable update TSF
  4243. val8 = rtw_read8(padapter, REG_BCN_CTRL);
  4244. val8 &= ~BIT(4);
  4245. rtw_write8(padapter, REG_BCN_CTRL, val8);
  4246. if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE|WIFI_ADHOC_MASTER_STATE))
  4247. {
  4248. RetryLimit = 0x7;
  4249. }
  4250. }
  4251. val16 = RetryLimit << RETRY_LIMIT_SHORT_SHIFT | RetryLimit << RETRY_LIMIT_LONG_SHIFT;
  4252. rtw_write16(padapter, REG_RL, val16);
  4253. }
  4254. #endif // !CONFIG_CONCURRENT_MODE
  4255. #ifdef CONFIG_BT_COEXIST
  4256. switch (*pval)
  4257. {
  4258. case 0:
  4259. // prepare to join
  4260. BT_WifiAssociateNotify(padapter, _TRUE);
  4261. break;
  4262. case 1:
  4263. // joinbss_event callback when join res < 0
  4264. BT_WifiAssociateNotify(padapter, _FALSE);
  4265. break;
  4266. case 2:
  4267. // sta add event callback
  4268. // BT_WifiMediaStatusNotify(padapter, RT_MEDIA_CONNECT);
  4269. break;
  4270. }
  4271. #endif
  4272. break;
  4273. case HW_VAR_ON_RCR_AM:
  4274. val32 = rtw_read32(padapter, REG_RCR);
  4275. val32 |= RCR_AM;
  4276. rtw_write32(padapter, REG_RCR, val32);
  4277. DBG_8192C("%s, %d, RCR= %x\n", __FUNCTION__, __LINE__, rtw_read32(padapter, REG_RCR));
  4278. break;
  4279. case HW_VAR_OFF_RCR_AM:
  4280. val32 = rtw_read32(padapter, REG_RCR);
  4281. val32 &= ~RCR_AM;
  4282. rtw_write32(padapter, REG_RCR, val32);
  4283. DBG_8192C("%s, %d, RCR= %x\n", __FUNCTION__, __LINE__, rtw_read32(padapter, REG_RCR));
  4284. break;
  4285. case HW_VAR_BEACON_INTERVAL:
  4286. rtw_write16(padapter, REG_BCN_INTERVAL, *(u16*)pval);
  4287. #ifdef CONFIG_INTERRUPT_BASED_TXBCN_EARLY_INT
  4288. {
  4289. struct mlme_ext_priv *pmlmeext;
  4290. struct mlme_ext_info *pmlmeinfo;
  4291. u16 bcn_interval;
  4292. pmlmeext = &padapter->mlmeextpriv;
  4293. pmlmeinfo = &pmlmeext->mlmext_info;
  4294. bcn_interval = *((u16*)pval);
  4295. if ((pmlmeinfo->state&0x03) == WIFI_FW_AP_STATE)
  4296. {
  4297. DBG_8192C("%s==> bcn_interval:%d, eraly_int:%d\n", __FUNCTION__, bcn_interval, bcn_interval>>1);
  4298. rtw_write8(padapter, REG_DRVERLYINT, bcn_interval>>1);// 50ms for sdio
  4299. }
  4300. }
  4301. #endif // CONFIG_INTERRUPT_BASED_TXBCN_EARLY_INT
  4302. break;
  4303. case HW_VAR_SLOT_TIME:
  4304. rtw_write8(padapter, REG_SLOT, *pval);
  4305. break;
  4306. case HW_VAR_RESP_SIFS:
  4307. // SIFS_Timer = 0x0a0a0808;
  4308. // RESP_SIFS for CCK
  4309. rtw_write8(padapter, REG_RESP_SIFS_CCK, pval[0]); // SIFS_T2T_CCK (0x08)
  4310. rtw_write8(padapter, REG_RESP_SIFS_CCK+1, pval[1]); //SIFS_R2T_CCK(0x08)
  4311. // RESP_SIFS for OFDM
  4312. rtw_write8(padapter, REG_RESP_SIFS_OFDM, pval[2]); //SIFS_T2T_OFDM (0x0a)
  4313. rtw_write8(padapter, REG_RESP_SIFS_OFDM+1, pval[3]); //SIFS_R2T_OFDM(0x0a)
  4314. break;
  4315. case HW_VAR_ACK_PREAMBLE:
  4316. {
  4317. u8 bShortPreamble = *pval;
  4318. // Joseph marked out for Netgear 3500 TKIP channel 7 issue.(Temporarily)
  4319. val8 = (pHalData->nCur40MhzPrimeSC) << 5;
  4320. if (bShortPreamble)
  4321. val8 |= 0x80;
  4322. rtw_write8(padapter, REG_RRSR+2, val8);
  4323. }
  4324. break;
  4325. case HW_VAR_SEC_CFG:
  4326. #ifdef CONFIG_CONCURRENT_MODE
  4327. // enable tx enc and rx dec engine, and no key search for MC/BC
  4328. val8 = 0x0c | BIT(5);
  4329. #else
  4330. val8 = *pval;
  4331. #endif
  4332. rtw_write8(padapter, REG_SECCFG, val8);
  4333. break;
  4334. case HW_VAR_DM_FLAG:
  4335. podmpriv->SupportAbility = *(u32*)pval;
  4336. break;
  4337. case HW_VAR_DM_FUNC_OP:
  4338. if (*pval) // save dm flag
  4339. podmpriv->BK_SupportAbility = podmpriv->SupportAbility;
  4340. else // restore dm flag
  4341. podmpriv->SupportAbility = podmpriv->BK_SupportAbility;
  4342. break;
  4343. case HW_VAR_DM_FUNC_SET:
  4344. val32 = *(u32*)pval;
  4345. if (val32 == DYNAMIC_ALL_FUNC_ENABLE) {
  4346. pdmpriv->DMFlag = pdmpriv->InitDMFlag;
  4347. podmpriv->SupportAbility = pdmpriv->InitODMFlag;
  4348. } else {
  4349. podmpriv->SupportAbility |= val32;
  4350. }
  4351. break;
  4352. case HW_VAR_DM_FUNC_CLR:
  4353. val32 = *(u32*)pval;
  4354. // input is already a mask to clear function
  4355. // don't invert it again! George,Lucas@20130513
  4356. podmpriv->SupportAbility &= val32;
  4357. break;
  4358. case HW_VAR_CAM_EMPTY_ENTRY:
  4359. {
  4360. u8 ucIndex = *pval;
  4361. u8 i;
  4362. u32 ulCommand = 0;
  4363. u32 ulContent = 0;
  4364. u32 ulEncAlgo = CAM_AES;
  4365. for (i=0; i<CAM_CONTENT_COUNT; i++)
  4366. {
  4367. // filled id in CAM config 2 byte
  4368. if (i == 0)
  4369. {
  4370. ulContent |= (ucIndex & 0x03) | ((u16)(ulEncAlgo)<<2);
  4371. //ulContent |= CAM_VALID;
  4372. }
  4373. else
  4374. {
  4375. ulContent = 0;
  4376. }
  4377. // polling bit, and No Write enable, and address
  4378. ulCommand = CAM_CONTENT_COUNT*ucIndex+i;
  4379. ulCommand = ulCommand | CAM_POLLINIG | CAM_WRITE;
  4380. // write content 0 is equall to mark invalid
  4381. rtw_write32(padapter, WCAMI, ulContent); //delay_ms(40);
  4382. rtw_write32(padapter, RWCAM, ulCommand); //delay_ms(40);
  4383. }
  4384. }
  4385. break;
  4386. case HW_VAR_CAM_INVALID_ALL:
  4387. val32 = BIT(31) | BIT(30);
  4388. rtw_write32(padapter, RWCAM, val32);
  4389. break;
  4390. case HW_VAR_CAM_WRITE:
  4391. {
  4392. u32 cmd;
  4393. u32 *cam_val = (u32*)pval;
  4394. rtw_write32(padapter, WCAMI, cam_val[0]);
  4395. cmd = CAM_POLLINIG | CAM_WRITE | cam_val[1];
  4396. rtw_write32(padapter, RWCAM, cmd);
  4397. }
  4398. break;
  4399. case HW_VAR_CAM_READ:
  4400. break;
  4401. case HW_VAR_AC_PARAM_VO:
  4402. rtw_write32(padapter, REG_EDCA_VO_PARAM, *(u32*)pval);
  4403. break;
  4404. case HW_VAR_AC_PARAM_VI:
  4405. rtw_write32(padapter, REG_EDCA_VI_PARAM, *(u32*)pval);
  4406. break;
  4407. case HW_VAR_AC_PARAM_BE:
  4408. pHalData->AcParam_BE = *(u32*)pval;
  4409. rtw_write32(padapter, REG_EDCA_BE_PARAM, *(u32*)pval);
  4410. break;
  4411. case HW_VAR_AC_PARAM_BK:
  4412. rtw_write32(padapter, REG_EDCA_BK_PARAM, *(u32*)pval);
  4413. break;
  4414. case HW_VAR_ACM_CTRL:
  4415. {
  4416. u8 acm_ctrl;
  4417. u8 AcmCtrl;
  4418. acm_ctrl = *(u8*)pval;
  4419. AcmCtrl = rtw_read8(padapter, REG_ACMHWCTRL);
  4420. if (acm_ctrl > 1)
  4421. AcmCtrl = AcmCtrl | 0x1;
  4422. if (acm_ctrl & BIT(3))
  4423. AcmCtrl |= AcmHw_VoqEn;
  4424. else
  4425. AcmCtrl &= (~AcmHw_VoqEn);
  4426. if (acm_ctrl & BIT(2))
  4427. AcmCtrl |= AcmHw_ViqEn;
  4428. else
  4429. AcmCtrl &= (~AcmHw_ViqEn);
  4430. if (acm_ctrl & BIT(1))
  4431. AcmCtrl |= AcmHw_BeqEn;
  4432. else
  4433. AcmCtrl &= (~AcmHw_BeqEn);
  4434. DBG_8192C("[HW_VAR_ACM_CTRL] Write 0x%X\n", AcmCtrl);
  4435. rtw_write8(padapter, REG_ACMHWCTRL, AcmCtrl );
  4436. }
  4437. break;
  4438. case HW_VAR_AMPDU_MIN_SPACE:
  4439. pHalData->AMPDUDensity = *(u8*)pval;
  4440. break;
  4441. case HW_VAR_AMPDU_FACTOR:
  4442. {
  4443. u32 AMPDULen = *(u8*)pval;
  4444. if (IS_HARDWARE_TYPE_8812(padapter))
  4445. {
  4446. if (AMPDULen < VHT_AGG_SIZE_128K)
  4447. AMPDULen = (0x2000 << *(u8*)pval) - 1;
  4448. else
  4449. AMPDULen = 0x1ffff;
  4450. }
  4451. else if(IS_HARDWARE_TYPE_8821(padapter))
  4452. {
  4453. if (AMPDULen < HT_AGG_SIZE_64K)
  4454. AMPDULen = (0x2000 << *(u8*)pval) - 1;
  4455. else
  4456. AMPDULen = 0xffff;
  4457. }
  4458. AMPDULen |= BIT(31);
  4459. rtw_write32(padapter, REG_AMPDU_MAX_LENGTH_8812, AMPDULen);
  4460. }
  4461. break;
  4462. #if 0
  4463. case HW_VAR_RXDMA_AGG_PG_TH:
  4464. rtw_write8(padapter, REG_RXDMA_AGG_PG_TH, *pval);
  4465. break;
  4466. #endif
  4467. case HW_VAR_H2C_FW_PWRMODE:
  4468. {
  4469. u8 psmode = *pval;
  4470. // Forece leave RF low power mode for 1T1R to prevent conficting setting in Fw power
  4471. // saving sequence. 2010.06.07. Added by tynli. Suggested by SD3 yschang.
  4472. if ((psmode != PS_MODE_ACTIVE) && (!IS_92C_SERIAL(pHalData->VersionID)))
  4473. {
  4474. ODM_RF_Saving(podmpriv, _TRUE);
  4475. }
  4476. rtl8812_set_FwPwrMode_cmd(padapter, psmode);
  4477. }
  4478. break;
  4479. case HW_VAR_H2C_FW_JOINBSSRPT:
  4480. rtl8812_set_FwJoinBssReport_cmd(padapter, *pval);
  4481. break;
  4482. #ifdef CONFIG_P2P_PS
  4483. case HW_VAR_H2C_FW_P2P_PS_OFFLOAD:
  4484. rtl8812_set_p2p_ps_offload_cmd(padapter, *pval);
  4485. break;
  4486. #endif // CONFIG_P2P_PS
  4487. #ifdef CONFIG_TDLS
  4488. case HW_VAR_TDLS_WRCR:
  4489. val32 = rtw_read32(padapter, REG_RCR);
  4490. val32 &= ~RCR_CBSSID_DATA;
  4491. rtw_write32(padapter, REG_RCR, val32);
  4492. break;
  4493. case HW_VAR_TDLS_INIT_CH_SEN:
  4494. val32 = rtw_read32(padapter, REG_RCR);
  4495. val32 &= (~RCR_CBSSID_DATA) & (~RCR_CBSSID_BCN);
  4496. rtw_write32(padapter, REG_RCR, val32);
  4497. rtw_write16(padapter, REG_RXFLTMAP2, 0xffff);
  4498. // disable update TSF
  4499. val8 = rtw_read8(padapter, REG_BCN_CTRL);
  4500. val8 |= BIT(4);
  4501. rtw_write8(padapter, REG_BCN_CTRL, val8);
  4502. break;
  4503. case HW_VAR_TDLS_DONE_CH_SEN:
  4504. // enable update TSF
  4505. val8 = rtw_read8(padapter, REG_BCN_CTRL);
  4506. val8 &= ~BIT(4);
  4507. rtw_write8(padapter, REG_BCN_CTRL, val8);
  4508. val32 = rtw_read32(padapter, REG_RCR);
  4509. val32 |= RCR_CBSSID_BCN;
  4510. rtw_write32(padapter, REG_RCR, val32);
  4511. break;
  4512. case HW_VAR_TDLS_RS_RCR:
  4513. val32 = rtw_read32(padapter, REG_RCR);
  4514. val32 |= RCR_CBSSID_DATA;
  4515. rtw_write32(padapter, REG_RCR, val32);
  4516. break;
  4517. #endif // CONFIG_TDLS
  4518. case HW_VAR_INITIAL_GAIN:
  4519. {
  4520. pDIG_T pDigTable = &podmpriv->DM_DigTable;
  4521. u32 rx_gain = *(u32*)pval;
  4522. if (rx_gain == 0xff) {//restore rx gain
  4523. ODM_Write_DIG(podmpriv, pDigTable->BackupIGValue);
  4524. } else {
  4525. pDigTable->BackupIGValue = pDigTable->CurIGValue;
  4526. ODM_Write_DIG(podmpriv, rx_gain);
  4527. }
  4528. }
  4529. break;
  4530. #ifdef CONFIG_BT_COEXIST
  4531. case HW_VAR_BT_SET_COEXIST:
  4532. rtl8812_set_dm_bt_coexist(padapter, *pval);
  4533. break;
  4534. case HW_VAR_BT_ISSUE_DELBA:
  4535. rtl8812_issue_delete_ba(padapter, *pval);
  4536. break;
  4537. #endif
  4538. #if (RATE_ADAPTIVE_SUPPORT==1)
  4539. case HW_VAR_RPT_TIMER_SETTING:
  4540. {
  4541. val16 = *(u16*)pval;
  4542. ODM_RA_Set_TxRPT_Time(podmpriv, val16);
  4543. }
  4544. break;
  4545. #endif
  4546. #ifdef CONFIG_SW_ANTENNA_DIVERSITY
  4547. case HW_VAR_ANTENNA_DIVERSITY_LINK:
  4548. //SwAntDivRestAfterLink8192C(padapter);
  4549. ODM_SwAntDivRestAfterLink(podmpriv);
  4550. break;
  4551. case HW_VAR_ANTENNA_DIVERSITY_SELECT:
  4552. {
  4553. u8 Optimum_antenna = *pval;
  4554. u8 Ant;
  4555. //switch antenna to Optimum_antenna
  4556. //DBG_8192C("==> HW_VAR_ANTENNA_DIVERSITY_SELECT , Ant_(%s)\n",(Optimum_antenna==2)?"A":"B");
  4557. if (pHalData->CurAntenna != Optimum_antenna)
  4558. {
  4559. Ant = (Optimum_antenna==2) ? MAIN_ANT : AUX_ANT;
  4560. ODM_UpdateRxIdleAnt_88E(podmpriv, Ant);
  4561. pHalData->CurAntenna = Optimum_antenna;
  4562. //DBG_8192C("==> HW_VAR_ANTENNA_DIVERSITY_SELECT , Ant_(%s)\n",(Optimum_antenna==2)?"A":"B");
  4563. }
  4564. }
  4565. break;
  4566. #endif
  4567. case HW_VAR_EFUSE_USAGE:
  4568. pHalData->EfuseUsedPercentage = *pval;
  4569. break;
  4570. case HW_VAR_EFUSE_BYTES:
  4571. pHalData->EfuseUsedBytes = *(u16*)pval;
  4572. break;
  4573. #if 0
  4574. case HW_VAR_EFUSE_BT_USAGE:
  4575. #ifdef HAL_EFUSE_MEMORY
  4576. pHalData->EfuseHal.BTEfuseUsedPercentage = *pval;
  4577. #endif
  4578. break;
  4579. case HW_VAR_EFUSE_BT_BYTES:
  4580. #ifdef HAL_EFUSE_MEMORY
  4581. pHalData->EfuseHal.BTEfuseUsedBytes = *(u16*)pval;
  4582. #else
  4583. BTEfuseUsedBytes = *(u16*)pval;
  4584. #endif
  4585. break;
  4586. #endif
  4587. case HW_VAR_FIFO_CLEARN_UP:
  4588. {
  4589. struct pwrctrl_priv *pwrpriv;
  4590. u8 trycnt = 100;
  4591. pwrpriv = &padapter->pwrctrlpriv;
  4592. // pause tx
  4593. rtw_write8(padapter, REG_TXPAUSE, 0xff);
  4594. // keep sn
  4595. padapter->xmitpriv.nqos_ssn = rtw_read16(padapter, REG_NQOS_SEQ);
  4596. if (pwrpriv->bkeepfwalive != _TRUE)
  4597. {
  4598. // RX DMA stop
  4599. val32 = rtw_read32(padapter, REG_RXPKT_NUM);
  4600. val32 |= RW_RELEASE_EN;
  4601. rtw_write32(padapter, REG_RXPKT_NUM, val32);
  4602. do {
  4603. val32 = rtw_read32(padapter, REG_RXPKT_NUM);
  4604. val32 &= RXDMA_IDLE;
  4605. if (!val32)
  4606. break;
  4607. } while (trycnt--);
  4608. if (trycnt == 0)
  4609. {
  4610. DBG_8192C("[HW_VAR_FIFO_CLEARN_UP] Stop RX DMA failed......\n");
  4611. }
  4612. //RQPN Load 0
  4613. rtw_write16(padapter, REG_RQPN_NPQ, 0x0);
  4614. rtw_write32(padapter, REG_RQPN, 0x80000000);
  4615. rtw_mdelay_os(10);
  4616. }
  4617. }
  4618. break;
  4619. #ifdef CONFIG_CONCURRENT_MODE
  4620. case HW_VAR_CHECK_TXBUF:
  4621. {
  4622. u32 i;
  4623. u8 RetryLimit;
  4624. u32 reg_200, reg_204;
  4625. RetryLimit = 0x01;
  4626. val16 = RetryLimit << RETRY_LIMIT_SHORT_SHIFT | RetryLimit << RETRY_LIMIT_LONG_SHIFT;
  4627. rtw_write16(padapter, REG_RL, val16);
  4628. for (i=0; i<1000; i++)
  4629. {
  4630. reg_200 = rtw_read32(padapter, 0x200);
  4631. reg_204 = rtw_read32(padapter, 0x204);
  4632. if (reg_200 != reg_204)
  4633. {
  4634. // DBG_8192C("%s: (HW_VAR_CHECK_TXBUF)Tx buffer NOT empty - 0x204=0x%x, 0x200=0x%x (%d)\n", __FUNCTION__, reg_204, reg_200, i);
  4635. rtw_msleep_os(10);
  4636. }
  4637. else
  4638. {
  4639. DBG_8192C("%s: (HW_VAR_CHECK_TXBUF)Tx buffer Empty(%d)\n", __FUNCTION__, i);
  4640. break;
  4641. }
  4642. }
  4643. if (i == 1000)
  4644. {
  4645. DBG_8192C("%s: (HW_VAR_CHECK_TXBUF)TXBUF is still not Empty after %d times check!\n", __FUNCTION__, i);
  4646. DBG_8192C("%s: (HW_VAR_CHECK_TXBUF)0x204=0x%08x, 0x200=0x%08x\n", __FUNCTION__, reg_204, reg_200);
  4647. }
  4648. RetryLimit = 0x30;
  4649. val16 = RetryLimit << RETRY_LIMIT_SHORT_SHIFT | RetryLimit << RETRY_LIMIT_LONG_SHIFT;
  4650. rtw_write16(padapter, REG_RL, val16);
  4651. }
  4652. break;
  4653. #endif
  4654. #if (RATE_ADAPTIVE_SUPPORT == 1)
  4655. case HW_VAR_TX_RPT_MAX_MACID:
  4656. {
  4657. u8 maxMacid = *pval;
  4658. DBG_8192C("### MacID(%d),Set Max Tx RPT MID(%d)\n", maxMacid, maxMacid+1);
  4659. rtw_write8(padapter, REG_TX_RPT_CTRL+1, maxMacid+1);
  4660. }
  4661. break;
  4662. #endif
  4663. case HW_VAR_H2C_MEDIA_STATUS_RPT:
  4664. {
  4665. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  4666. RT_MEDIA_STATUS mstatus = *(u16*)pval & 0xFF;
  4667. rtl8812_set_FwMediaStatus_cmd(padapter, *(u16*)pval);
  4668. if (check_fwstate(pmlmepriv, WIFI_STATION_STATE))
  4669. Hal_PatchwithJaguar_8812(padapter, mstatus);
  4670. }
  4671. break;
  4672. case HW_VAR_APFM_ON_MAC:
  4673. pHalData->bMacPwrCtrlOn = *pval;
  4674. DBG_8192C("%s: bMacPwrCtrlOn=%d\n", __FUNCTION__, pHalData->bMacPwrCtrlOn);
  4675. break;
  4676. case HW_VAR_NAV_UPPER:
  4677. {
  4678. u32 usNavUpper = *((u32*)pval);
  4679. if (usNavUpper > HAL_NAV_UPPER_UNIT * 0xFF)
  4680. {
  4681. DBG_8192C("%s: [HW_VAR_NAV_UPPER] set value(0x%08X us) is larger than (%d * 0xFF)!\n",
  4682. __FUNCTION__, usNavUpper, HAL_NAV_UPPER_UNIT);
  4683. break;
  4684. }
  4685. // The value of ((usNavUpper + HAL_NAV_UPPER_UNIT - 1) / HAL_NAV_UPPER_UNIT)
  4686. // is getting the upper integer.
  4687. usNavUpper = (usNavUpper + HAL_NAV_UPPER_UNIT - 1) / HAL_NAV_UPPER_UNIT;
  4688. rtw_write8(padapter, REG_NAV_UPPER, (u8)usNavUpper);
  4689. }
  4690. break;
  4691. case HW_VAR_BCN_VALID:
  4692. #ifdef CONFIG_CONCURRENT_MODE
  4693. if (IS_HARDWARE_TYPE_8821(padapter) && padapter->iface_type == IFACE_PORT1)
  4694. {
  4695. val8 = rtw_read8(padapter, REG_TDECTRL1_8812+2);
  4696. val8 |= BIT(0);
  4697. rtw_write8(padapter, REG_TDECTRL1_8812+2, val8);
  4698. }
  4699. else
  4700. #endif
  4701. {
  4702. // BCN_VALID, BIT16 of REG_TDECTRL = BIT0 of REG_TDECTRL+2, write 1 to clear, Clear by sw
  4703. val8 = rtw_read8(padapter, REG_TDECTRL+2);
  4704. val8 |= BIT(0);
  4705. rtw_write8(padapter, REG_TDECTRL+2, val8);
  4706. }
  4707. break;
  4708. case HW_VAR_DL_BCN_SEL:
  4709. #ifdef CONFIG_CONCURRENT_MODE
  4710. if (IS_HARDWARE_TYPE_8821(padapter) && padapter->iface_type == IFACE_PORT1)
  4711. {
  4712. // SW_BCN_SEL - Port1
  4713. val8 = rtw_read8(padapter, REG_TDECTRL1_8812+2);
  4714. val8 |= BIT(4);
  4715. rtw_write8(padapter, REG_TDECTRL1_8812+2, val8);
  4716. }
  4717. else
  4718. #endif
  4719. {
  4720. // SW_BCN_SEL - Port0
  4721. val8 = rtw_read8(padapter, REG_TDECTRL1_8812+2);
  4722. val8 &= ~BIT(4);
  4723. rtw_write8(padapter, REG_TDECTRL1_8812+2, val8);
  4724. }
  4725. break;
  4726. case HW_VAR_WIRELESS_MODE:
  4727. {
  4728. u8 R2T_SIFS = 0, SIFS_Timer = 0;
  4729. u8 wireless_mode = *pval;
  4730. if ((wireless_mode == WIRELESS_11BG) || (wireless_mode == WIRELESS_11G))
  4731. SIFS_Timer = 0xa;
  4732. else
  4733. SIFS_Timer = 0xe;
  4734. // SIFS for OFDM Data ACK
  4735. rtw_write8(padapter, REG_SIFS_CTX+1, SIFS_Timer);
  4736. // SIFS for OFDM consecutive tx like CTS data!
  4737. rtw_write8(padapter, REG_SIFS_TRX+1, SIFS_Timer);
  4738. rtw_write8(padapter,REG_SPEC_SIFS+1, SIFS_Timer);
  4739. rtw_write8(padapter,REG_MAC_SPEC_SIFS+1, SIFS_Timer);
  4740. // 20100719 Joseph: Revise SIFS setting due to Hardware register definition change.
  4741. rtw_write8(padapter, REG_RESP_SIFS_OFDM+1, SIFS_Timer);
  4742. rtw_write8(padapter, REG_RESP_SIFS_OFDM, SIFS_Timer);
  4743. //
  4744. // Adjust R2T SIFS for IOT issue. Add by hpfan 2013.01.25
  4745. // Set R2T SIFS to 0x0a for Atheros IOT. Add by hpfan 2013.02.22
  4746. //
  4747. // Mac has 10 us delay so use 0xa value is enough.
  4748. R2T_SIFS = 0xa;
  4749. rtw_write8(padapter, REG_RESP_SIFS_OFDM+1, R2T_SIFS);
  4750. }
  4751. break;
  4752. default:
  4753. DBG_8192C("%s: [WARNNING] variable(%d) not defined!\n", __FUNCTION__, variable);
  4754. break;
  4755. }
  4756. _func_exit_;
  4757. }
  4758. void GetHwReg8812A(PADAPTER padapter, u8 variable, u8 *pval)
  4759. {
  4760. PHAL_DATA_TYPE pHalData;
  4761. PDM_ODM_T podmpriv;
  4762. u8 val8;
  4763. u16 val16;
  4764. u32 val32;
  4765. _func_enter_;
  4766. pHalData = GET_HAL_DATA(padapter);
  4767. podmpriv = &pHalData->odmpriv;
  4768. switch (variable)
  4769. {
  4770. case HW_VAR_BASIC_RATE:
  4771. *(u16*)pval = pHalData->BasicRateSet;
  4772. break;
  4773. case HW_VAR_TXPAUSE:
  4774. *pval = rtw_read8(padapter, REG_TXPAUSE);
  4775. break;
  4776. case HW_VAR_BCN_VALID:
  4777. #ifdef CONFIG_CONCURRENT_MODE
  4778. if (IS_HARDWARE_TYPE_8821(padapter) && padapter->iface_type == IFACE_PORT1)
  4779. {
  4780. val8 = rtw_read8(padapter, REG_TDECTRL1_8812+2);
  4781. *pval = (BIT(0) & val8) ? _TRUE:_FALSE;
  4782. }
  4783. else
  4784. #endif
  4785. {
  4786. //BCN_VALID, BIT16 of REG_TDECTRL = BIT0 of REG_TDECTRL+2
  4787. val8 = rtw_read8(padapter, REG_TDECTRL+2);
  4788. *pval = (BIT(0) & val8) ? _TRUE:_FALSE;
  4789. }
  4790. break;
  4791. case HW_VAR_DM_FLAG:
  4792. *pval = podmpriv->SupportAbility;
  4793. break;
  4794. case HW_VAR_RF_TYPE:
  4795. *pval = pHalData->rf_type;
  4796. break;
  4797. case HW_VAR_FWLPS_RF_ON:
  4798. //When we halt NIC, we should check if FW LPS is leave.
  4799. if(padapter->pwrctrlpriv.rf_pwrstate == rf_off)
  4800. {
  4801. // If it is in HW/SW Radio OFF or IPS state, we do not check Fw LPS Leave,
  4802. // because Fw is unload.
  4803. *pval = _TRUE;
  4804. }
  4805. else
  4806. {
  4807. u32 valRCR;
  4808. valRCR = rtw_read32(padapter, REG_RCR);
  4809. valRCR &= 0x00070000;
  4810. if(valRCR)
  4811. *pval = _FALSE;
  4812. else
  4813. *pval = _TRUE;
  4814. }
  4815. break;
  4816. #ifdef CONFIG_ANTENNA_DIVERSITY
  4817. case HW_VAR_CURRENT_ANTENNA:
  4818. *pval = pHalData->CurAntenna;
  4819. break;
  4820. #endif
  4821. case HW_VAR_EFUSE_BYTES: // To get EFUE total used bytes, added by Roger, 2008.12.22.
  4822. *(u16*)pval = pHalData->EfuseUsedBytes;
  4823. break;
  4824. case HW_VAR_APFM_ON_MAC:
  4825. *pval = pHalData->bMacPwrCtrlOn;
  4826. break;
  4827. case HW_VAR_CHK_HI_QUEUE_EMPTY:
  4828. val16 = rtw_read16(padapter, REG_TXPKT_EMPTY);
  4829. *pval = (val16 & BIT(10)) ? _TRUE:_FALSE;
  4830. break;
  4831. default:
  4832. DBG_8192C("%s: [WARNNING] variable(%d) not defined!\n", __FUNCTION__, variable);
  4833. break;
  4834. }
  4835. _func_exit_;
  4836. }
  4837. /*
  4838. * Description:
  4839. * Change default setting of specified variable.
  4840. */
  4841. u8 SetHalDefVar8812A(PADAPTER padapter, HAL_DEF_VARIABLE variable, void *pval)
  4842. {
  4843. PHAL_DATA_TYPE pHalData;
  4844. u8 bResult;
  4845. pHalData = GET_HAL_DATA(padapter);
  4846. bResult = _SUCCESS;
  4847. switch (variable)
  4848. {
  4849. case HAL_DEF_DBG_DM_FUNC:
  4850. {
  4851. u8 dm_func;
  4852. struct dm_priv *pdmpriv;
  4853. DM_ODM_T *podmpriv;
  4854. dm_func = *((u8*)pval);
  4855. pdmpriv = &pHalData->dmpriv;
  4856. podmpriv = &pHalData->odmpriv;
  4857. if (dm_func == 0)
  4858. {
  4859. //disable all dynamic func
  4860. podmpriv->SupportAbility = DYNAMIC_FUNC_DISABLE;
  4861. DBG_8192C("==> Disable all dynamic function...\n");
  4862. }
  4863. else if (dm_func == 1)
  4864. {
  4865. // disable DIG
  4866. podmpriv->SupportAbility &= (~DYNAMIC_BB_DIG);
  4867. DBG_8192C("==> Disable DIG...\n");
  4868. }
  4869. else if (dm_func == 2)
  4870. {
  4871. // disable High power
  4872. podmpriv->SupportAbility &= (~DYNAMIC_BB_DYNAMIC_TXPWR);
  4873. }
  4874. else if (dm_func == 3)
  4875. {
  4876. // disable tx power tracking
  4877. podmpriv->SupportAbility &= (~DYNAMIC_RF_CALIBRATION);
  4878. DBG_8192C("==> Disable tx power tracking...\n");
  4879. }
  4880. // else if (dm_func == 4)
  4881. // {
  4882. // disable BT coexistence
  4883. // pdmpriv->DMFlag &= (~DYNAMIC_FUNC_BT);
  4884. // }
  4885. else if (dm_func == 5)
  4886. {
  4887. // disable antenna diversity
  4888. podmpriv->SupportAbility &= (~DYNAMIC_BB_ANT_DIV);
  4889. }
  4890. else if (dm_func == 6)
  4891. {
  4892. // turn on all dynamic func
  4893. if (!(podmpriv->SupportAbility & DYNAMIC_BB_DIG))
  4894. {
  4895. pDIG_T pDigTable = &podmpriv->DM_DigTable;
  4896. pDigTable->CurIGValue = rtw_read8(padapter, 0xc50);
  4897. }
  4898. // pdmpriv->DMFlag |= DYNAMIC_FUNC_BT;
  4899. podmpriv->SupportAbility = DYNAMIC_ALL_FUNC_ENABLE;
  4900. DBG_8192C("==> Turn on all dynamic function...\n");
  4901. }
  4902. }
  4903. break;
  4904. case HAL_DEF_DBG_DUMP_RXPKT:
  4905. pHalData->bDumpRxPkt = *(u8*)pval;
  4906. break;
  4907. case HAL_DEF_DBG_DUMP_TXPKT:
  4908. pHalData->bDumpTxPkt = *(u8*)pval;
  4909. break;
  4910. case HW_DEF_FA_CNT_DUMP:
  4911. {
  4912. u8 mac_id;
  4913. PDM_ODM_T pDM_Odm;
  4914. mac_id = *(u8*)pval;
  4915. pDM_Odm = &pHalData->odmpriv;
  4916. if (padapter->bLinkInfoDump & BIT(1))
  4917. pDM_Odm->DebugComponents |= ODM_COMP_DIG;
  4918. else
  4919. pDM_Odm->DebugComponents &= ~ODM_COMP_DIG;
  4920. if (padapter->bLinkInfoDump & BIT(2))
  4921. pDM_Odm->DebugComponents |= ODM_COMP_FA_CNT;
  4922. else
  4923. pDM_Odm->DebugComponents &= ~ODM_COMP_FA_CNT;
  4924. }
  4925. break;
  4926. case HW_DEF_ODM_DBG_FLAG:
  4927. {
  4928. u64 DebugComponents;
  4929. PDM_ODM_T pDM_Odm;
  4930. DebugComponents = *((u64*)pval);
  4931. pDM_Odm = &pHalData->odmpriv;
  4932. pDM_Odm->DebugComponents = DebugComponents;
  4933. }
  4934. break;
  4935. default:
  4936. DBG_8192C("%s: [ERROR] HAL_DEF_VARIABLE(%d) not defined!\n", __FUNCTION__, variable);
  4937. bResult = _FAIL;
  4938. break;
  4939. }
  4940. return bResult;
  4941. }
  4942. /*
  4943. * Description:
  4944. * Query setting of specified variable.
  4945. */
  4946. u8 GetHalDefVar8812A(PADAPTER padapter, HAL_DEF_VARIABLE variable, void *pval)
  4947. {
  4948. PHAL_DATA_TYPE pHalData;
  4949. u8 bResult;
  4950. pHalData = GET_HAL_DATA(padapter);
  4951. bResult = _SUCCESS;
  4952. switch (variable)
  4953. {
  4954. case HAL_DEF_UNDERCORATEDSMOOTHEDPWDB:
  4955. {
  4956. struct mlme_priv *pmlmepriv;
  4957. struct sta_priv *pstapriv;
  4958. struct sta_info *psta;
  4959. pmlmepriv = &padapter->mlmepriv;
  4960. pstapriv = &padapter->stapriv;
  4961. psta = rtw_get_stainfo(pstapriv, pmlmepriv->cur_network.network.MacAddress);
  4962. if (psta)
  4963. {
  4964. *((int*)pval) = psta->rssi_stat.UndecoratedSmoothedPWDB;
  4965. }
  4966. }
  4967. break;
  4968. #ifdef CONFIG_ANTENNA_DIVERSITY
  4969. case HAL_DEF_IS_SUPPORT_ANT_DIV:
  4970. *((u8*)pval) = (pHalData->AntDivCfg==0) ? _FALSE : _TRUE;
  4971. break;
  4972. #endif
  4973. #ifdef CONFIG_ANTENNA_DIVERSITY
  4974. case HAL_DEF_CURRENT_ANTENNA:
  4975. *((u8*)pval) = pHalData->CurAntenna;
  4976. break;
  4977. #endif
  4978. case HAL_DEF_DRVINFO_SZ:
  4979. *((u32*)pval) = DRVINFO_SZ;
  4980. break;
  4981. case HAL_DEF_MAX_RECVBUF_SZ:
  4982. *((u32*)pval) = MAX_RECVBUF_SZ;
  4983. break;
  4984. case HAL_DEF_RX_PACKET_OFFSET:
  4985. *((u32*)pval) = RXDESC_SIZE + DRVINFO_SZ;
  4986. break;
  4987. case HAL_DEF_DBG_DM_FUNC:
  4988. *((u32*)pval) = pHalData->odmpriv.SupportAbility;
  4989. break;
  4990. #if (RATE_ADAPTIVE_SUPPORT == 1)
  4991. case HAL_DEF_RA_DECISION_RATE:
  4992. {
  4993. u8 MacID = *(u8*)pval;
  4994. *((u8*)pval) = ODM_RA_GetDecisionRate_8812A(&pHalData->odmpriv, MacID);
  4995. }
  4996. break;
  4997. case HAL_DEF_RA_SGI:
  4998. {
  4999. u8 MacID = *(u8*)pval;
  5000. *((u8*)pval) = ODM_RA_GetShortGI_8812A(&pHalData->odmpriv, MacID);
  5001. }
  5002. break;
  5003. #endif // (RATE_ADAPTIVE_SUPPORT == 1)
  5004. #if (POWER_TRAINING_ACTIVE == 1)
  5005. case HAL_DEF_PT_PWR_STATUS:
  5006. {
  5007. u8 MacID = *(u8*)pval;
  5008. *(u8*)pval = ODM_RA_GetHwPwrStatus_8812A(&pHalData->odmpriv, MacID);
  5009. }
  5010. break;
  5011. #endif //(POWER_TRAINING_ACTIVE == 1)
  5012. case HW_VAR_MAX_RX_AMPDU_FACTOR:
  5013. *((u32*)pval) = MAX_AMPDU_FACTOR_64K;
  5014. break;
  5015. case HAL_DEF_LDPC:
  5016. if (IS_VENDOR_8812A_C_CUT(padapter))
  5017. *(u8*)pval = _TRUE;
  5018. else if (IS_HARDWARE_TYPE_8821(padapter))
  5019. *(u8*)pval = _FALSE;
  5020. else
  5021. *(u8*)pval = _FALSE;
  5022. #if (MP_DRIVER == 1)
  5023. if (padapter->registrypriv.mp_mode == 1)
  5024. *(u8*)pval = _TRUE;
  5025. #endif
  5026. break;
  5027. case HAL_DEF_TX_STBC:
  5028. if (pHalData->rf_type == RF_2T2R)
  5029. *(u8*)pval = 1;
  5030. else
  5031. *(u8*)pval = 0;
  5032. break;
  5033. case HAL_DEF_RX_STBC:
  5034. *(u8*)pval = 1;
  5035. break;
  5036. case HW_DEF_RA_INFO_DUMP:
  5037. {
  5038. u8 mac_id = *(u8*)pval;
  5039. u32 cmd = 0x40000400 | mac_id;
  5040. u32 ra_info1, ra_info2;
  5041. u32 rate_mask1, rate_mask2;
  5042. if ((padapter->bLinkInfoDump & BIT(0))
  5043. && (check_fwstate(&padapter->mlmepriv, _FW_LINKED) == _TRUE))
  5044. {
  5045. DBG_8192C("============ RA status check Mac_id:%d ===================\n", mac_id);
  5046. rtw_write32(padapter, REG_HMEBOX_E2_E3_8812,cmd);
  5047. ra_info1 = rtw_read32(padapter, REG_RSVD5_8812);
  5048. ra_info2 = rtw_read32(padapter, REG_RSVD6_8812);
  5049. rate_mask1 = rtw_read32(padapter,REG_RSVD7_8812);
  5050. rate_mask2 = rtw_read32(padapter,REG_RSVD8_8812);
  5051. DBG_8192C("[ ra_info1:0x%08x ] =>RSSI=%d, BW_setting=0x%02x, DISRA=0x%02x, VHT_EN=0x%02x\n",
  5052. ra_info1,
  5053. ra_info1&0xFF,
  5054. (ra_info1>>8) & 0xFF,
  5055. (ra_info1>>16) & 0xFF,
  5056. (ra_info1>>24) & 0xFF);
  5057. DBG_8192C("[ ra_info2:0x%08x ] =>hight_rate=0x%02x, lowest_rate=0x%02x, SGI=0x%02x, RateID=%d\n",
  5058. ra_info2,
  5059. ra_info2&0xFF,
  5060. (ra_info2>>8) & 0xFF,
  5061. (ra_info2>>16) & 0xFF,
  5062. (ra_info2>>24) & 0xFF);
  5063. DBG_8192C("rate_mask2=0x%08x, rate_mask1=0x%08x\n", rate_mask2, rate_mask1);
  5064. }
  5065. }
  5066. break;
  5067. case HAL_DEF_DBG_DUMP_RXPKT:
  5068. *(u8*)pval = pHalData->bDumpRxPkt;
  5069. break;
  5070. case HAL_DEF_DBG_DUMP_TXPKT:
  5071. *(u8*)pval = pHalData->bDumpTxPkt;
  5072. break;
  5073. case HW_DEF_ODM_DBG_FLAG:
  5074. {
  5075. u64 DebugComponents;
  5076. PDM_ODM_T pDM_Odm;
  5077. pDM_Odm = &pHalData->odmpriv;
  5078. DebugComponents = pDM_Odm->DebugComponents;
  5079. DBG_8192C("%s: pDM_Odm->DebugComponents=0x%llx\n", __FUNCTION__, DebugComponents);
  5080. *((u64*)pval) = DebugComponents;
  5081. }
  5082. break;
  5083. case HAL_DEF_TX_PAGE_BOUNDARY:
  5084. if (!padapter->registrypriv.wifi_spec)
  5085. {
  5086. if (IS_HARDWARE_TYPE_8812(padapter))
  5087. *(u8*)pval = TX_PAGE_BOUNDARY_8812;
  5088. else
  5089. *(u8*)pval = TX_PAGE_BOUNDARY_8821;
  5090. }
  5091. else
  5092. {
  5093. if (IS_HARDWARE_TYPE_8812(padapter))
  5094. *(u8*)pval = WMM_NORMAL_TX_PAGE_BOUNDARY_8812;
  5095. else
  5096. *(u8*)pval = WMM_NORMAL_TX_PAGE_BOUNDARY_8821;
  5097. }
  5098. break;
  5099. case HAL_DEF_TX_PAGE_BOUNDARY_WOWLAN:
  5100. *(u8*)pval = TX_PAGE_BOUNDARY_WOWLAN_8812;
  5101. break;
  5102. default:
  5103. DBG_8192C("%s: [ERROR] HAL_DEF_VARIABLE(%d) not defined!\n", __FUNCTION__, variable);
  5104. bResult = _FAIL;
  5105. break;
  5106. }
  5107. return bResult;
  5108. }
  5109. void rtl8812_set_hal_ops(struct hal_ops *pHalFunc)
  5110. {
  5111. pHalFunc->free_hal_data = &rtl8812_free_hal_data;
  5112. pHalFunc->dm_init = &rtl8812_init_dm_priv;
  5113. pHalFunc->dm_deinit = &rtl8812_deinit_dm_priv;
  5114. pHalFunc->UpdateRAMaskHandler = &UpdateHalRAMask8812A;
  5115. pHalFunc->read_chip_version = &ReadChipVersion8812A;
  5116. pHalFunc->set_bwmode_handler = &PHY_SetBWMode8812;
  5117. pHalFunc->set_channel_handler = &PHY_SwChnl8812;
  5118. pHalFunc->set_chnl_bw_handler = &PHY_SetSwChnlBWMode8812;
  5119. pHalFunc->hal_dm_watchdog = &rtl8812_HalDmWatchDog;
  5120. pHalFunc->Add_RateATid = &rtl8812_Add_RateATid;
  5121. #ifdef CONFIG_CONCURRENT_MODE
  5122. pHalFunc->clone_haldata = &rtl8812_clone_haldata;
  5123. #endif
  5124. pHalFunc->run_thread= &rtl8812_start_thread;
  5125. pHalFunc->cancel_thread= &rtl8812_stop_thread;
  5126. #ifdef CONFIG_ANTENNA_DIVERSITY
  5127. pHalFunc->AntDivBeforeLinkHandler = &AntDivBeforeLink8812;
  5128. pHalFunc->AntDivCompareHandler = &AntDivCompare8812;
  5129. #endif
  5130. pHalFunc->read_bbreg = &PHY_QueryBBReg8812;
  5131. pHalFunc->write_bbreg = &PHY_SetBBReg8812;
  5132. pHalFunc->read_rfreg = &PHY_QueryRFReg8812;
  5133. pHalFunc->write_rfreg = &PHY_SetRFReg8812;
  5134. // Efuse related function
  5135. pHalFunc->EfusePowerSwitch = &rtl8812_EfusePowerSwitch;
  5136. pHalFunc->ReadEFuse = &rtl8812_ReadEFuse;
  5137. pHalFunc->EFUSEGetEfuseDefinition = &rtl8812_EFUSE_GetEfuseDefinition;
  5138. pHalFunc->EfuseGetCurrentSize = &rtl8812_EfuseGetCurrentSize;
  5139. pHalFunc->Efuse_PgPacketRead = &rtl8812_Efuse_PgPacketRead;
  5140. pHalFunc->Efuse_PgPacketWrite = &rtl8812_Efuse_PgPacketWrite;
  5141. pHalFunc->Efuse_WordEnableDataWrite = &rtl8812_Efuse_WordEnableDataWrite;
  5142. #ifdef DBG_CONFIG_ERROR_DETECT
  5143. pHalFunc->sreset_init_value = &sreset_init_value;
  5144. pHalFunc->sreset_reset_value = &sreset_reset_value;
  5145. pHalFunc->silentreset = &sreset_reset;
  5146. pHalFunc->sreset_xmit_status_check = &rtl8812_sreset_xmit_status_check;
  5147. pHalFunc->sreset_linked_status_check = &rtl8812_sreset_linked_status_check;
  5148. pHalFunc->sreset_get_wifi_status = &sreset_get_wifi_status;
  5149. pHalFunc->sreset_inprogress= &sreset_inprogress;
  5150. #endif //DBG_CONFIG_ERROR_DETECT
  5151. pHalFunc->GetHalODMVarHandler = &rtl8812_GetHalODMVar;
  5152. pHalFunc->SetHalODMVarHandler = &rtl8812_SetHalODMVar;
  5153. pHalFunc->hal_notch_filter = &hal_notch_filter_8812;
  5154. pHalFunc->SetBeaconRelatedRegistersHandler = &SetBeaconRelatedRegisters8812A;
  5155. }