odm.c 386 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405
  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. //============================================================
  21. // include files
  22. //============================================================
  23. #include "odm_precomp.h"
  24. const u2Byte dB_Invert_Table[8][12] = {
  25. { 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 4, 4},
  26. { 4, 5, 6, 6, 7, 8, 9, 10, 11, 13, 14, 16},
  27. { 18, 20, 22, 25, 28, 32, 35, 40, 45, 50, 56, 63},
  28. { 71, 79, 89, 100, 112, 126, 141, 158, 178, 200, 224, 251},
  29. { 282, 316, 355, 398, 447, 501, 562, 631, 708, 794, 891, 1000},
  30. { 1122, 1259, 1413, 1585, 1778, 1995, 2239, 2512, 2818, 3162, 3548, 3981},
  31. { 4467, 5012, 5623, 6310, 7079, 7943, 8913, 10000, 11220, 12589, 14125, 15849},
  32. { 17783, 19953, 22387, 25119, 28184, 31623, 35481, 39811, 44668, 50119, 56234, 65535}};
  33. // 20100515 Joseph: Add global variable to keep temporary scan list for antenna switching test.
  34. //u1Byte tmpNumBssDesc;
  35. //RT_WLAN_BSS tmpbssDesc[MAX_BSS_DESC];
  36. #if (DM_ODM_SUPPORT_TYPE & (ODM_WIN|ODM_CE))
  37. static u4Byte edca_setting_UL[HT_IOT_PEER_MAX] =
  38. // UNKNOWN REALTEK_90 REALTEK_92SE BROADCOM RALINK ATHEROS CISCO MERU MARVELL 92U_AP SELF_AP(DownLink/Tx)
  39. { 0x5e4322, 0xa44f, 0x5e4322, 0x5ea32b, 0x5ea422, 0x5ea322, 0x3ea430, 0x5ea42b, 0x5ea44f, 0x5e4322, 0x5e4322};
  40. static u4Byte edca_setting_DL[HT_IOT_PEER_MAX] =
  41. // UNKNOWN REALTEK_90 REALTEK_92SE BROADCOM RALINK ATHEROS CISCO MERU, MARVELL 92U_AP SELF_AP(UpLink/Rx)
  42. { 0xa44f, 0x5ea44f, 0x5e4322, 0x5ea42b, 0xa44f, 0xa630, 0x5ea630, 0x5ea42b, 0xa44f, 0xa42b, 0xa42b};
  43. static u4Byte edca_setting_DL_GMode[HT_IOT_PEER_MAX] =
  44. // UNKNOWN REALTEK_90 REALTEK_92SE BROADCOM RALINK ATHEROS CISCO MERU, MARVELL 92U_AP SELF_AP
  45. { 0x4322, 0xa44f, 0x5e4322, 0xa42b, 0x5e4322, 0x4322, 0xa42b, 0x5ea42b, 0xa44f, 0x5e4322, 0x5ea42b};
  46. //============================================================
  47. // EDCA Paramter for AP/ADSL by Mingzhi 2011-11-22
  48. //============================================================
  49. #elif (DM_ODM_SUPPORT_TYPE &ODM_ADSL)
  50. enum qos_prio { BK, BE, VI, VO, VI_AG, VO_AG };
  51. static const struct ParaRecord rtl_ap_EDCA[] =
  52. {
  53. //ACM,AIFSN, ECWmin, ECWmax, TXOplimit
  54. {0, 7, 4, 10, 0}, //BK
  55. {0, 3, 4, 6, 0}, //BE
  56. {0, 1, 3, 4, 188}, //VI
  57. {0, 1, 2, 3, 102}, //VO
  58. {0, 1, 3, 4, 94}, //VI_AG
  59. {0, 1, 2, 3, 47}, //VO_AG
  60. };
  61. static const struct ParaRecord rtl_sta_EDCA[] =
  62. {
  63. //ACM,AIFSN, ECWmin, ECWmax, TXOplimit
  64. {0, 7, 4, 10, 0},
  65. {0, 3, 4, 10, 0},
  66. {0, 2, 3, 4, 188},
  67. {0, 2, 2, 3, 102},
  68. {0, 2, 3, 4, 94},
  69. {0, 2, 2, 3, 47},
  70. };
  71. #endif
  72. //============================================================
  73. // Global var
  74. //============================================================
  75. u4Byte OFDMSwingTable[OFDM_TABLE_SIZE_92D] = {
  76. 0x7f8001fe, // 0, +6.0dB
  77. 0x788001e2, // 1, +5.5dB
  78. 0x71c001c7, // 2, +5.0dB
  79. 0x6b8001ae, // 3, +4.5dB
  80. 0x65400195, // 4, +4.0dB
  81. 0x5fc0017f, // 5, +3.5dB
  82. 0x5a400169, // 6, +3.0dB
  83. 0x55400155, // 7, +2.5dB
  84. 0x50800142, // 8, +2.0dB
  85. 0x4c000130, // 9, +1.5dB
  86. 0x47c0011f, // 10, +1.0dB
  87. 0x43c0010f, // 11, +0.5dB
  88. 0x40000100, // 12, +0dB
  89. 0x3c8000f2, // 13, -0.5dB
  90. 0x390000e4, // 14, -1.0dB
  91. 0x35c000d7, // 15, -1.5dB
  92. 0x32c000cb, // 16, -2.0dB
  93. 0x300000c0, // 17, -2.5dB
  94. 0x2d4000b5, // 18, -3.0dB
  95. 0x2ac000ab, // 19, -3.5dB
  96. 0x288000a2, // 20, -4.0dB
  97. 0x26000098, // 21, -4.5dB
  98. 0x24000090, // 22, -5.0dB
  99. 0x22000088, // 23, -5.5dB
  100. 0x20000080, // 24, -6.0dB
  101. 0x1e400079, // 25, -6.5dB
  102. 0x1c800072, // 26, -7.0dB
  103. 0x1b00006c, // 27. -7.5dB
  104. 0x19800066, // 28, -8.0dB
  105. 0x18000060, // 29, -8.5dB
  106. 0x16c0005b, // 30, -9.0dB
  107. 0x15800056, // 31, -9.5dB
  108. 0x14400051, // 32, -10.0dB
  109. 0x1300004c, // 33, -10.5dB
  110. 0x12000048, // 34, -11.0dB
  111. 0x11000044, // 35, -11.5dB
  112. 0x10000040, // 36, -12.0dB
  113. };
  114. u1Byte CCKSwingTable_Ch1_Ch13[CCK_TABLE_SIZE][8] = {
  115. {0x36, 0x35, 0x2e, 0x25, 0x1c, 0x12, 0x09, 0x04}, // 0, +0dB
  116. {0x33, 0x32, 0x2b, 0x23, 0x1a, 0x11, 0x08, 0x04}, // 1, -0.5dB
  117. {0x30, 0x2f, 0x29, 0x21, 0x19, 0x10, 0x08, 0x03}, // 2, -1.0dB
  118. {0x2d, 0x2d, 0x27, 0x1f, 0x18, 0x0f, 0x08, 0x03}, // 3, -1.5dB
  119. {0x2b, 0x2a, 0x25, 0x1e, 0x16, 0x0e, 0x07, 0x03}, // 4, -2.0dB
  120. {0x28, 0x28, 0x22, 0x1c, 0x15, 0x0d, 0x07, 0x03}, // 5, -2.5dB
  121. {0x26, 0x25, 0x21, 0x1b, 0x14, 0x0d, 0x06, 0x03}, // 6, -3.0dB
  122. {0x24, 0x23, 0x1f, 0x19, 0x13, 0x0c, 0x06, 0x03}, // 7, -3.5dB
  123. {0x22, 0x21, 0x1d, 0x18, 0x11, 0x0b, 0x06, 0x02}, // 8, -4.0dB
  124. {0x20, 0x20, 0x1b, 0x16, 0x11, 0x08, 0x05, 0x02}, // 9, -4.5dB
  125. {0x1f, 0x1e, 0x1a, 0x15, 0x10, 0x0a, 0x05, 0x02}, // 10, -5.0dB
  126. {0x1d, 0x1c, 0x18, 0x14, 0x0f, 0x0a, 0x05, 0x02}, // 11, -5.5dB
  127. {0x1b, 0x1a, 0x17, 0x13, 0x0e, 0x09, 0x04, 0x02}, // 12, -6.0dB <== default
  128. {0x1a, 0x19, 0x16, 0x12, 0x0d, 0x09, 0x04, 0x02}, // 13, -6.5dB
  129. {0x18, 0x17, 0x15, 0x11, 0x0c, 0x08, 0x04, 0x02}, // 14, -7.0dB
  130. {0x17, 0x16, 0x13, 0x10, 0x0c, 0x08, 0x04, 0x02}, // 15, -7.5dB
  131. {0x16, 0x15, 0x12, 0x0f, 0x0b, 0x07, 0x04, 0x01}, // 16, -8.0dB
  132. {0x14, 0x14, 0x11, 0x0e, 0x0b, 0x07, 0x03, 0x02}, // 17, -8.5dB
  133. {0x13, 0x13, 0x10, 0x0d, 0x0a, 0x06, 0x03, 0x01}, // 18, -9.0dB
  134. {0x12, 0x12, 0x0f, 0x0c, 0x09, 0x06, 0x03, 0x01}, // 19, -9.5dB
  135. {0x11, 0x11, 0x0f, 0x0c, 0x09, 0x06, 0x03, 0x01}, // 20, -10.0dB
  136. {0x10, 0x10, 0x0e, 0x0b, 0x08, 0x05, 0x03, 0x01}, // 21, -10.5dB
  137. {0x0f, 0x0f, 0x0d, 0x0b, 0x08, 0x05, 0x03, 0x01}, // 22, -11.0dB
  138. {0x0e, 0x0e, 0x0c, 0x0a, 0x08, 0x05, 0x02, 0x01}, // 23, -11.5dB
  139. {0x0d, 0x0d, 0x0c, 0x0a, 0x07, 0x05, 0x02, 0x01}, // 24, -12.0dB
  140. {0x0d, 0x0c, 0x0b, 0x09, 0x07, 0x04, 0x02, 0x01}, // 25, -12.5dB
  141. {0x0c, 0x0c, 0x0a, 0x09, 0x06, 0x04, 0x02, 0x01}, // 26, -13.0dB
  142. {0x0b, 0x0b, 0x0a, 0x08, 0x06, 0x04, 0x02, 0x01}, // 27, -13.5dB
  143. {0x0b, 0x0a, 0x09, 0x08, 0x06, 0x04, 0x02, 0x01}, // 28, -14.0dB
  144. {0x0a, 0x0a, 0x09, 0x07, 0x05, 0x03, 0x02, 0x01}, // 29, -14.5dB
  145. {0x0a, 0x09, 0x08, 0x07, 0x05, 0x03, 0x02, 0x01}, // 30, -15.0dB
  146. {0x09, 0x09, 0x08, 0x06, 0x05, 0x03, 0x01, 0x01}, // 31, -15.5dB
  147. {0x09, 0x08, 0x07, 0x06, 0x04, 0x03, 0x01, 0x01} // 32, -16.0dB
  148. };
  149. u1Byte CCKSwingTable_Ch14[CCK_TABLE_SIZE][8] = {
  150. {0x36, 0x35, 0x2e, 0x1b, 0x00, 0x00, 0x00, 0x00}, // 0, +0dB
  151. {0x33, 0x32, 0x2b, 0x19, 0x00, 0x00, 0x00, 0x00}, // 1, -0.5dB
  152. {0x30, 0x2f, 0x29, 0x18, 0x00, 0x00, 0x00, 0x00}, // 2, -1.0dB
  153. {0x2d, 0x2d, 0x17, 0x17, 0x00, 0x00, 0x00, 0x00}, // 3, -1.5dB
  154. {0x2b, 0x2a, 0x25, 0x15, 0x00, 0x00, 0x00, 0x00}, // 4, -2.0dB
  155. {0x28, 0x28, 0x24, 0x14, 0x00, 0x00, 0x00, 0x00}, // 5, -2.5dB
  156. {0x26, 0x25, 0x21, 0x13, 0x00, 0x00, 0x00, 0x00}, // 6, -3.0dB
  157. {0x24, 0x23, 0x1f, 0x12, 0x00, 0x00, 0x00, 0x00}, // 7, -3.5dB
  158. {0x22, 0x21, 0x1d, 0x11, 0x00, 0x00, 0x00, 0x00}, // 8, -4.0dB
  159. {0x20, 0x20, 0x1b, 0x10, 0x00, 0x00, 0x00, 0x00}, // 9, -4.5dB
  160. {0x1f, 0x1e, 0x1a, 0x0f, 0x00, 0x00, 0x00, 0x00}, // 10, -5.0dB
  161. {0x1d, 0x1c, 0x18, 0x0e, 0x00, 0x00, 0x00, 0x00}, // 11, -5.5dB
  162. {0x1b, 0x1a, 0x17, 0x0e, 0x00, 0x00, 0x00, 0x00}, // 12, -6.0dB <== default
  163. {0x1a, 0x19, 0x16, 0x0d, 0x00, 0x00, 0x00, 0x00}, // 13, -6.5dB
  164. {0x18, 0x17, 0x15, 0x0c, 0x00, 0x00, 0x00, 0x00}, // 14, -7.0dB
  165. {0x17, 0x16, 0x13, 0x0b, 0x00, 0x00, 0x00, 0x00}, // 15, -7.5dB
  166. {0x16, 0x15, 0x12, 0x0b, 0x00, 0x00, 0x00, 0x00}, // 16, -8.0dB
  167. {0x14, 0x14, 0x11, 0x0a, 0x00, 0x00, 0x00, 0x00}, // 17, -8.5dB
  168. {0x13, 0x13, 0x10, 0x0a, 0x00, 0x00, 0x00, 0x00}, // 18, -9.0dB
  169. {0x12, 0x12, 0x0f, 0x09, 0x00, 0x00, 0x00, 0x00}, // 19, -9.5dB
  170. {0x11, 0x11, 0x0f, 0x09, 0x00, 0x00, 0x00, 0x00}, // 20, -10.0dB
  171. {0x10, 0x10, 0x0e, 0x08, 0x00, 0x00, 0x00, 0x00}, // 21, -10.5dB
  172. {0x0f, 0x0f, 0x0d, 0x08, 0x00, 0x00, 0x00, 0x00}, // 22, -11.0dB
  173. {0x0e, 0x0e, 0x0c, 0x07, 0x00, 0x00, 0x00, 0x00}, // 23, -11.5dB
  174. {0x0d, 0x0d, 0x0c, 0x07, 0x00, 0x00, 0x00, 0x00}, // 24, -12.0dB
  175. {0x0d, 0x0c, 0x0b, 0x06, 0x00, 0x00, 0x00, 0x00}, // 25, -12.5dB
  176. {0x0c, 0x0c, 0x0a, 0x06, 0x00, 0x00, 0x00, 0x00}, // 26, -13.0dB
  177. {0x0b, 0x0b, 0x0a, 0x06, 0x00, 0x00, 0x00, 0x00}, // 27, -13.5dB
  178. {0x0b, 0x0a, 0x09, 0x05, 0x00, 0x00, 0x00, 0x00}, // 28, -14.0dB
  179. {0x0a, 0x0a, 0x09, 0x05, 0x00, 0x00, 0x00, 0x00}, // 29, -14.5dB
  180. {0x0a, 0x09, 0x08, 0x05, 0x00, 0x00, 0x00, 0x00}, // 30, -15.0dB
  181. {0x09, 0x09, 0x08, 0x05, 0x00, 0x00, 0x00, 0x00}, // 31, -15.5dB
  182. {0x09, 0x08, 0x07, 0x04, 0x00, 0x00, 0x00, 0x00} // 32, -16.0dB
  183. };
  184. u4Byte OFDMSwingTable_New[OFDM_TABLE_SIZE_92D] = {
  185. 0x0b40002d, // 0, -15.0dB
  186. 0x0c000030, // 1, -14.5dB
  187. 0x0cc00033, // 2, -14.0dB
  188. 0x0d800036, // 3, -13.5dB
  189. 0x0e400039, // 4, -13.0dB
  190. 0x0f00003c, // 5, -12.5dB
  191. 0x10000040, // 6, -12.0dB
  192. 0x11000044, // 7, -11.5dB
  193. 0x12000048, // 8, -11.0dB
  194. 0x1300004c, // 9, -10.5dB
  195. 0x14400051, // 10, -10.0dB
  196. 0x15800056, // 11, -9.5dB
  197. 0x16c0005b, // 12, -9.0dB
  198. 0x18000060, // 13, -8.5dB
  199. 0x19800066, // 14, -8.0dB
  200. 0x1b00006c, // 15, -7.5dB
  201. 0x1c800072, // 16, -7.0dB
  202. 0x1e400079, // 17, -6.5dB
  203. 0x20000080, // 18, -6.0dB
  204. 0x22000088, // 19, -5.5dB
  205. 0x24000090, // 20, -5.0dB
  206. 0x26000098, // 21, -4.5dB
  207. 0x288000a2, // 22, -4.0dB
  208. 0x2ac000ab, // 23, -3.5dB
  209. 0x2d4000b5, // 24, -3.0dB
  210. 0x300000c0, // 25, -2.5dB
  211. 0x32c000cb, // 26, -2.0dB
  212. 0x35c000d7, // 27, -1.5dB
  213. 0x390000e4, // 28, -1.0dB
  214. 0x3c8000f2, // 29, -0.5dB
  215. 0x40000100, // 30, +0dB
  216. 0x43c0010f, // 31, +0.5dB
  217. 0x47c0011f, // 32, +1.0dB
  218. 0x4c000130, // 33, +1.5dB
  219. 0x50800142, // 34, +2.0dB
  220. 0x55400155, // 35, +2.5dB
  221. 0x5a400169, // 36, +3.0dB
  222. 0x5fc0017f, // 37, +3.5dB
  223. 0x65400195, // 38, +4.0dB
  224. 0x6b8001ae, // 39, +4.5dB
  225. 0x71c001c7, // 40, +5.0dB
  226. 0x788001e2, // 41, +5.5dB
  227. 0x7f8001fe // 42, +6.0dB
  228. };
  229. u1Byte CCKSwingTable_Ch1_Ch13_New[CCK_TABLE_SIZE][8] = {
  230. {0x09, 0x08, 0x07, 0x06, 0x04, 0x03, 0x01, 0x01}, // 0, -16.0dB
  231. {0x09, 0x09, 0x08, 0x06, 0x05, 0x03, 0x01, 0x01}, // 1, -15.5dB
  232. {0x0a, 0x09, 0x08, 0x07, 0x05, 0x03, 0x02, 0x01}, // 2, -15.0dB
  233. {0x0a, 0x0a, 0x09, 0x07, 0x05, 0x03, 0x02, 0x01}, // 3, -14.5dB
  234. {0x0b, 0x0a, 0x09, 0x08, 0x06, 0x04, 0x02, 0x01}, // 4, -14.0dB
  235. {0x0b, 0x0b, 0x0a, 0x08, 0x06, 0x04, 0x02, 0x01}, // 5, -13.5dB
  236. {0x0c, 0x0c, 0x0a, 0x09, 0x06, 0x04, 0x02, 0x01}, // 6, -13.0dB
  237. {0x0d, 0x0c, 0x0b, 0x09, 0x07, 0x04, 0x02, 0x01}, // 7, -12.5dB
  238. {0x0d, 0x0d, 0x0c, 0x0a, 0x07, 0x05, 0x02, 0x01}, // 8, -12.0dB
  239. {0x0e, 0x0e, 0x0c, 0x0a, 0x08, 0x05, 0x02, 0x01}, // 9, -11.5dB
  240. {0x0f, 0x0f, 0x0d, 0x0b, 0x08, 0x05, 0x03, 0x01}, // 10, -11.0dB
  241. {0x10, 0x10, 0x0e, 0x0b, 0x08, 0x05, 0x03, 0x01}, // 11, -10.5dB
  242. {0x11, 0x11, 0x0f, 0x0c, 0x09, 0x06, 0x03, 0x01}, // 12, -10.0dB
  243. {0x12, 0x12, 0x0f, 0x0c, 0x09, 0x06, 0x03, 0x01}, // 13, -9.5dB
  244. {0x13, 0x13, 0x10, 0x0d, 0x0a, 0x06, 0x03, 0x01}, // 14, -9.0dB
  245. {0x14, 0x14, 0x11, 0x0e, 0x0b, 0x07, 0x03, 0x02}, // 15, -8.5dB
  246. {0x16, 0x15, 0x12, 0x0f, 0x0b, 0x07, 0x04, 0x01}, // 16, -8.0dB
  247. {0x17, 0x16, 0x13, 0x10, 0x0c, 0x08, 0x04, 0x02}, // 17, -7.5dB
  248. {0x18, 0x17, 0x15, 0x11, 0x0c, 0x08, 0x04, 0x02}, // 18, -7.0dB
  249. {0x1a, 0x19, 0x16, 0x12, 0x0d, 0x09, 0x04, 0x02}, // 19, -6.5dB
  250. {0x1b, 0x1a, 0x17, 0x13, 0x0e, 0x09, 0x04, 0x02}, // 20, -6.0dB
  251. {0x1d, 0x1c, 0x18, 0x14, 0x0f, 0x0a, 0x05, 0x02}, // 21, -5.5dB
  252. {0x1f, 0x1e, 0x1a, 0x15, 0x10, 0x0a, 0x05, 0x02}, // 22, -5.0dB
  253. {0x20, 0x20, 0x1b, 0x16, 0x11, 0x08, 0x05, 0x02}, // 23, -4.5dB
  254. {0x22, 0x21, 0x1d, 0x18, 0x11, 0x0b, 0x06, 0x02}, // 24, -4.0dB
  255. {0x24, 0x23, 0x1f, 0x19, 0x13, 0x0c, 0x06, 0x03}, // 25, -3.5dB
  256. {0x26, 0x25, 0x21, 0x1b, 0x14, 0x0d, 0x06, 0x03}, // 26, -3.0dB
  257. {0x28, 0x28, 0x22, 0x1c, 0x15, 0x0d, 0x07, 0x03}, // 27, -2.5dB
  258. {0x2b, 0x2a, 0x25, 0x1e, 0x16, 0x0e, 0x07, 0x03}, // 28, -2.0dB
  259. {0x2d, 0x2d, 0x27, 0x1f, 0x18, 0x0f, 0x08, 0x03}, // 29, -1.5dB
  260. {0x30, 0x2f, 0x29, 0x21, 0x19, 0x10, 0x08, 0x03}, // 30, -1.0dB
  261. {0x33, 0x32, 0x2b, 0x23, 0x1a, 0x11, 0x08, 0x04}, // 31, -0.5dB
  262. {0x36, 0x35, 0x2e, 0x25, 0x1c, 0x12, 0x09, 0x04} // 32, +0dB
  263. };
  264. u1Byte CCKSwingTable_Ch14_New[CCK_TABLE_SIZE][8]= {
  265. {0x09, 0x08, 0x07, 0x04, 0x00, 0x00, 0x00, 0x00}, // 0, -16.0dB
  266. {0x09, 0x09, 0x08, 0x05, 0x00, 0x00, 0x00, 0x00}, // 1, -15.5dB
  267. {0x0a, 0x09, 0x08, 0x05, 0x00, 0x00, 0x00, 0x00}, // 2, -15.0dB
  268. {0x0a, 0x0a, 0x09, 0x05, 0x00, 0x00, 0x00, 0x00}, // 3, -14.5dB
  269. {0x0b, 0x0a, 0x09, 0x05, 0x00, 0x00, 0x00, 0x00}, // 4, -14.0dB
  270. {0x0b, 0x0b, 0x0a, 0x06, 0x00, 0x00, 0x00, 0x00}, // 5, -13.5dB
  271. {0x0c, 0x0c, 0x0a, 0x06, 0x00, 0x00, 0x00, 0x00}, // 6, -13.0dB
  272. {0x0d, 0x0c, 0x0b, 0x06, 0x00, 0x00, 0x00, 0x00}, // 7, -12.5dB
  273. {0x0d, 0x0d, 0x0c, 0x07, 0x00, 0x00, 0x00, 0x00}, // 8, -12.0dB
  274. {0x0e, 0x0e, 0x0c, 0x07, 0x00, 0x00, 0x00, 0x00}, // 9, -11.5dB
  275. {0x0f, 0x0f, 0x0d, 0x08, 0x00, 0x00, 0x00, 0x00}, // 10, -11.0dB
  276. {0x10, 0x10, 0x0e, 0x08, 0x00, 0x00, 0x00, 0x00}, // 11, -10.5dB
  277. {0x11, 0x11, 0x0f, 0x09, 0x00, 0x00, 0x00, 0x00}, // 12, -10.0dB
  278. {0x12, 0x12, 0x0f, 0x09, 0x00, 0x00, 0x00, 0x00}, // 13, -9.5dB
  279. {0x13, 0x13, 0x10, 0x0a, 0x00, 0x00, 0x00, 0x00}, // 14, -9.0dB
  280. {0x14, 0x14, 0x11, 0x0a, 0x00, 0x00, 0x00, 0x00}, // 15, -8.5dB
  281. {0x16, 0x15, 0x12, 0x0b, 0x00, 0x00, 0x00, 0x00}, // 16, -8.0dB
  282. {0x17, 0x16, 0x13, 0x0b, 0x00, 0x00, 0x00, 0x00}, // 17, -7.5dB
  283. {0x18, 0x17, 0x15, 0x0c, 0x00, 0x00, 0x00, 0x00}, // 18, -7.0dB
  284. {0x1a, 0x19, 0x16, 0x0d, 0x00, 0x00, 0x00, 0x00}, // 19, -6.5dB
  285. {0x1b, 0x1a, 0x17, 0x0e, 0x00, 0x00, 0x00, 0x00}, // 20, -6.0dB
  286. {0x1d, 0x1c, 0x18, 0x0e, 0x00, 0x00, 0x00, 0x00}, // 21, -5.5dB
  287. {0x1f, 0x1e, 0x1a, 0x0f, 0x00, 0x00, 0x00, 0x00}, // 22, -5.0dB
  288. {0x20, 0x20, 0x1b, 0x10, 0x00, 0x00, 0x00, 0x00}, // 23, -4.5dB
  289. {0x22, 0x21, 0x1d, 0x11, 0x00, 0x00, 0x00, 0x00}, // 24, -4.0dB
  290. {0x24, 0x23, 0x1f, 0x12, 0x00, 0x00, 0x00, 0x00}, // 25, -3.5dB
  291. {0x26, 0x25, 0x21, 0x13, 0x00, 0x00, 0x00, 0x00}, // 26, -3.0dB
  292. {0x28, 0x28, 0x24, 0x14, 0x00, 0x00, 0x00, 0x00}, // 27, -2.5dB
  293. {0x2b, 0x2a, 0x25, 0x15, 0x00, 0x00, 0x00, 0x00}, // 28, -2.0dB
  294. {0x2d, 0x2d, 0x17, 0x17, 0x00, 0x00, 0x00, 0x00}, // 29, -1.5dB
  295. {0x30, 0x2f, 0x29, 0x18, 0x00, 0x00, 0x00, 0x00}, // 30, -1.0dB
  296. {0x33, 0x32, 0x2b, 0x19, 0x00, 0x00, 0x00, 0x00}, // 31, -0.5dB
  297. {0x36, 0x35, 0x2e, 0x1b, 0x00, 0x00, 0x00, 0x00} // 32, +0dB
  298. };
  299. u4Byte TxScalingTable_Jaguar[TXSCALE_TABLE_SIZE] =
  300. {
  301. 0x081, // 0, -12.0dB
  302. 0x088, // 1, -11.5dB
  303. 0x090, // 2, -11.0dB
  304. 0x099, // 3, -10.5dB
  305. 0x0A2, // 4, -10.0dB
  306. 0x0AC, // 5, -9.5dB
  307. 0x0B6, // 6, -9.0dB
  308. 0x0C0, // 7, -8.5dB
  309. 0x0CC, // 8, -8.0dB
  310. 0x0D8, // 9, -7.5dB
  311. 0x0E5, // 10, -7.0dB
  312. 0x0F2, // 11, -6.5dB
  313. 0x101, // 12, -6.0dB
  314. 0x110, // 13, -5.5dB
  315. 0x120, // 14, -5.0dB
  316. 0x131, // 15, -4.5dB
  317. 0x143, // 16, -4.0dB
  318. 0x156, // 17, -3.5dB
  319. 0x16A, // 18, -3.0dB
  320. 0x180, // 19, -2.5dB
  321. 0x197, // 20, -2.0dB
  322. 0x1AF, // 21, -1.5dB
  323. 0x1C8, // 22, -1.0dB
  324. 0x1E3, // 23, -0.5dB
  325. 0x200, // 24, +0 dB
  326. 0x21E, // 25, +0.5dB
  327. 0x23E, // 26, +1.0dB
  328. 0x261, // 27, +1.5dB
  329. 0x285, // 28, +2.0dB
  330. 0x2AB, // 29, +2.5dB
  331. 0x2D3, // 30, +3.0dB
  332. 0x2FE, // 31, +3.5dB
  333. 0x32B, // 32, +4.0dB
  334. 0x35C, // 33, +4.5dB
  335. 0x38E, // 34, +5.0dB
  336. 0x3C4, // 35, +5.5dB
  337. 0x3FE // 36, +6.0dB
  338. };
  339. #ifdef AP_BUILD_WORKAROUND
  340. unsigned int TxPwrTrk_OFDM_SwingTbl[TxPwrTrk_OFDM_SwingTbl_Len] = {
  341. /* +6.0dB */ 0x7f8001fe,
  342. /* +5.5dB */ 0x788001e2,
  343. /* +5.0dB */ 0x71c001c7,
  344. /* +4.5dB */ 0x6b8001ae,
  345. /* +4.0dB */ 0x65400195,
  346. /* +3.5dB */ 0x5fc0017f,
  347. /* +3.0dB */ 0x5a400169,
  348. /* +2.5dB */ 0x55400155,
  349. /* +2.0dB */ 0x50800142,
  350. /* +1.5dB */ 0x4c000130,
  351. /* +1.0dB */ 0x47c0011f,
  352. /* +0.5dB */ 0x43c0010f,
  353. /* 0.0dB */ 0x40000100,
  354. /* -0.5dB */ 0x3c8000f2,
  355. /* -1.0dB */ 0x390000e4,
  356. /* -1.5dB */ 0x35c000d7,
  357. /* -2.0dB */ 0x32c000cb,
  358. /* -2.5dB */ 0x300000c0,
  359. /* -3.0dB */ 0x2d4000b5,
  360. /* -3.5dB */ 0x2ac000ab,
  361. /* -4.0dB */ 0x288000a2,
  362. /* -4.5dB */ 0x26000098,
  363. /* -5.0dB */ 0x24000090,
  364. /* -5.5dB */ 0x22000088,
  365. /* -6.0dB */ 0x20000080,
  366. /* -6.5dB */ 0x1a00006c,
  367. /* -7.0dB */ 0x1c800072,
  368. /* -7.5dB */ 0x18000060,
  369. /* -8.0dB */ 0x19800066,
  370. /* -8.5dB */ 0x15800056,
  371. /* -9.0dB */ 0x26c0005b,
  372. /* -9.5dB */ 0x14400051,
  373. /* -10.0dB */ 0x24400051,
  374. /* -10.5dB */ 0x1300004c,
  375. /* -11.0dB */ 0x12000048,
  376. /* -11.5dB */ 0x11000044,
  377. /* -12.0dB */ 0x10000040
  378. };
  379. #endif
  380. //============================================================
  381. // Local Function predefine.
  382. //============================================================
  383. //START------------COMMON INFO RELATED---------------//
  384. VOID
  385. odm_CommonInfoSelfInit(
  386. IN PDM_ODM_T pDM_Odm
  387. );
  388. VOID
  389. odm_CommonInfoSelfUpdate(
  390. IN PDM_ODM_T pDM_Odm
  391. );
  392. VOID
  393. odm_CmnInfoInit_Debug(
  394. IN PDM_ODM_T pDM_Odm
  395. );
  396. VOID
  397. odm_CmnInfoHook_Debug(
  398. IN PDM_ODM_T pDM_Odm
  399. );
  400. VOID
  401. odm_CmnInfoUpdate_Debug(
  402. IN PDM_ODM_T pDM_Odm
  403. );
  404. VOID
  405. odm_BasicDbgMessage
  406. (
  407. IN PDM_ODM_T pDM_Odm
  408. );
  409. /*
  410. VOID
  411. odm_FindMinimumRSSI(
  412. IN PDM_ODM_T pDM_Odm
  413. );
  414. VOID
  415. odm_IsLinked(
  416. IN PDM_ODM_T pDM_Odm
  417. );
  418. */
  419. //END------------COMMON INFO RELATED---------------//
  420. //START---------------DIG---------------------------//
  421. VOID
  422. odm_FalseAlarmCounterStatistics(
  423. IN PDM_ODM_T pDM_Odm
  424. );
  425. VOID
  426. odm_DIGInit(
  427. IN PDM_ODM_T pDM_Odm
  428. );
  429. VOID
  430. odm_DIG(
  431. IN PDM_ODM_T pDM_Odm
  432. );
  433. BOOLEAN
  434. odm_DigAbort(
  435. IN PDM_ODM_T pDM_Odm
  436. );
  437. VOID
  438. odm_CCKPacketDetectionThresh(
  439. IN PDM_ODM_T pDM_Odm
  440. );
  441. VOID
  442. odm_AdaptivityInit(
  443. IN PDM_ODM_T pDM_Odm
  444. );
  445. VOID
  446. odm_Adaptivity(
  447. IN PDM_ODM_T pDM_Odm,
  448. IN u1Byte IGI
  449. );
  450. //END---------------DIG---------------------------//
  451. //START-------BB POWER SAVE-----------------------//
  452. VOID
  453. odm_DynamicBBPowerSavingInit(
  454. IN PDM_ODM_T pDM_Odm
  455. );
  456. VOID
  457. odm_DynamicBBPowerSaving(
  458. IN PDM_ODM_T pDM_Odm
  459. );
  460. VOID
  461. odm_1R_CCA(
  462. IN PDM_ODM_T pDM_Odm
  463. );
  464. //END---------BB POWER SAVE-----------------------//
  465. //START-----------------PSD-----------------------//
  466. #if(DM_ODM_SUPPORT_TYPE & (ODM_WIN))
  467. //============================================================
  468. // Function predefine.
  469. //============================================================
  470. VOID odm_PathDiversityInit_92C( IN PADAPTER Adapter);
  471. VOID odm_2TPathDiversityInit_92C( IN PADAPTER Adapter);
  472. VOID odm_1TPathDiversityInit_92C( IN PADAPTER Adapter);
  473. BOOLEAN odm_IsConnected_92C(IN PADAPTER Adapter);
  474. VOID odm_PathDiversityAfterLink_92C( IN PADAPTER Adapter);
  475. VOID
  476. odm_CCKTXPathDiversityCallback(
  477. PRT_TIMER pTimer
  478. );
  479. VOID
  480. odm_CCKTXPathDiversityWorkItemCallback(
  481. IN PVOID pContext
  482. );
  483. VOID
  484. odm_PathDivChkAntSwitchCallback(
  485. PRT_TIMER pTimer
  486. );
  487. VOID
  488. odm_PathDivChkAntSwitchWorkitemCallback(
  489. IN PVOID pContext
  490. );
  491. VOID odm_SetRespPath_92C( IN PADAPTER Adapter, IN u1Byte DefaultRespPath);
  492. VOID odm_OFDMTXPathDiversity_92C( IN PADAPTER Adapter);
  493. VOID odm_CCKTXPathDiversity_92C( IN PADAPTER Adapter);
  494. VOID odm_ResetPathDiversity_92C( IN PADAPTER Adapter);
  495. //Start-------------------- RX High Power------------------------//
  496. VOID odm_RXHPInit( IN PDM_ODM_T pDM_Odm);
  497. VOID odm_RXHP( IN PDM_ODM_T pDM_Odm);
  498. VOID odm_Write_RXHP( IN PDM_ODM_T pDM_Odm);
  499. VOID odm_PSD_RXHP( IN PDM_ODM_T pDM_Odm);
  500. VOID odm_PSD_RXHPCallback( PRT_TIMER pTimer);
  501. VOID odm_PSD_RXHPWorkitemCallback( IN PVOID pContext);
  502. //End--------------------- RX High Power -----------------------//
  503. VOID odm_PathDivInit_92D( IN PDM_ODM_T pDM_Odm);
  504. VOID
  505. odm_SetRespPath_92C(
  506. IN PADAPTER Adapter,
  507. IN u1Byte DefaultRespPath
  508. );
  509. #endif
  510. //END-------------------PSD-----------------------//
  511. VOID
  512. odm_RefreshRateAdaptiveMaskMP(
  513. IN PDM_ODM_T pDM_Odm
  514. );
  515. VOID
  516. odm_RefreshRateAdaptiveMaskCE(
  517. IN PDM_ODM_T pDM_Odm
  518. );
  519. VOID
  520. odm_RefreshRateAdaptiveMaskAPADSL(
  521. IN PDM_ODM_T pDM_Odm
  522. );
  523. VOID
  524. odm_DynamicATCSwitch_init(
  525. IN PDM_ODM_T pDM_Odm
  526. );
  527. VOID
  528. odm_DynamicATCSwitch(
  529. IN PDM_ODM_T pDM_Odm
  530. );
  531. VOID
  532. odm_Write_CrystalCap(
  533. IN PDM_ODM_T pDM_Odm,
  534. IN u1Byte CrystalCap
  535. );
  536. VOID
  537. odm_DynamicTxPowerInit(
  538. IN PDM_ODM_T pDM_Odm
  539. );
  540. VOID
  541. odm_DynamicTxPowerRestorePowerIndex(
  542. IN PDM_ODM_T pDM_Odm
  543. );
  544. VOID
  545. odm_DynamicTxPowerNIC(
  546. IN PDM_ODM_T pDM_Odm
  547. );
  548. #if(DM_ODM_SUPPORT_TYPE & (ODM_WIN|ODM_CE))
  549. VOID
  550. odm_DynamicTxPowerSavePowerIndex(
  551. IN PDM_ODM_T pDM_Odm
  552. );
  553. VOID
  554. odm_DynamicTxPowerWritePowerIndex(
  555. IN PDM_ODM_T pDM_Odm,
  556. IN u1Byte Value);
  557. VOID
  558. odm_DynamicTxPower_92C(
  559. IN PDM_ODM_T pDM_Odm
  560. );
  561. VOID
  562. odm_DynamicTxPower_92D(
  563. IN PDM_ODM_T pDM_Odm
  564. );
  565. VOID
  566. odm_MPT_DIGCallback(
  567. PRT_TIMER pTimer
  568. );
  569. VOID
  570. odm_MPT_DIGWorkItemCallback(
  571. IN PVOID pContext
  572. );
  573. #endif
  574. VOID
  575. odm_RSSIMonitorInit(
  576. IN PDM_ODM_T pDM_Odm
  577. );
  578. VOID
  579. odm_RSSIMonitorCheckMP(
  580. IN PDM_ODM_T pDM_Odm
  581. );
  582. VOID
  583. odm_RSSIMonitorCheckCE(
  584. IN PDM_ODM_T pDM_Odm
  585. );
  586. VOID
  587. odm_RSSIMonitorCheckAP(
  588. IN PDM_ODM_T pDM_Odm
  589. );
  590. VOID
  591. odm_RSSIMonitorCheck(
  592. IN PDM_ODM_T pDM_Odm
  593. );
  594. VOID
  595. odm_DynamicTxPower(
  596. IN PDM_ODM_T pDM_Odm
  597. );
  598. VOID
  599. odm_DynamicTxPowerAP(
  600. IN PDM_ODM_T pDM_Odm
  601. );
  602. VOID
  603. odm_SwAntDivInit(
  604. IN PDM_ODM_T pDM_Odm
  605. );
  606. VOID
  607. odm_SwAntDivInit_NIC(
  608. IN PDM_ODM_T pDM_Odm
  609. );
  610. VOID
  611. odm_SwAntDivChkAntSwitch(
  612. IN PDM_ODM_T pDM_Odm,
  613. IN u1Byte Step
  614. );
  615. VOID
  616. odm_SwAntDivChkAntSwitchNIC(
  617. IN PDM_ODM_T pDM_Odm,
  618. IN u1Byte Step
  619. );
  620. #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
  621. VOID
  622. odm_SwAntDivChkAntSwitchCallback(
  623. PRT_TIMER pTimer
  624. );
  625. VOID
  626. odm_SwAntDivChkAntSwitchWorkitemCallback(
  627. IN PVOID pContext
  628. );
  629. #elif (DM_ODM_SUPPORT_TYPE == ODM_CE)
  630. VOID odm_SwAntDivChkAntSwitchCallback(void *FunctionContext);
  631. #elif (DM_ODM_SUPPORT_TYPE & (ODM_AP|ODM_ADSL))
  632. VOID odm_SwAntDivChkAntSwitchCallback(void *FunctionContext);
  633. #endif
  634. VOID
  635. odm_GlobalAdapterCheck(
  636. IN VOID
  637. );
  638. VOID
  639. odm_RefreshBasicRateMask(
  640. IN PDM_ODM_T pDM_Odm
  641. );
  642. VOID
  643. odm_RefreshRateAdaptiveMask(
  644. IN PDM_ODM_T pDM_Odm
  645. );
  646. VOID
  647. ODM_TXPowerTrackingCheck(
  648. IN PDM_ODM_T pDM_Odm
  649. );
  650. VOID
  651. odm_TXPowerTrackingCheckAP(
  652. IN PDM_ODM_T pDM_Odm
  653. );
  654. VOID
  655. odm_RateAdaptiveMaskInit(
  656. IN PDM_ODM_T pDM_Odm
  657. );
  658. VOID
  659. odm_TXPowerTrackingThermalMeterInit(
  660. IN PDM_ODM_T pDM_Odm
  661. );
  662. VOID
  663. odm_TXPowerTrackingInit(
  664. IN PDM_ODM_T pDM_Odm
  665. );
  666. VOID
  667. odm_TXPowerTrackingCheckMP(
  668. IN PDM_ODM_T pDM_Odm
  669. );
  670. VOID
  671. odm_TXPowerTrackingCheckCE(
  672. IN PDM_ODM_T pDM_Odm
  673. );
  674. #if(DM_ODM_SUPPORT_TYPE & (ODM_WIN))
  675. VOID
  676. ODM_RateAdaptiveStateApInit(
  677. IN PADAPTER Adapter ,
  678. IN PRT_WLAN_STA pEntry
  679. );
  680. VOID
  681. odm_TXPowerTrackingCallbackThermalMeter92C(
  682. IN PADAPTER Adapter
  683. );
  684. VOID
  685. odm_TXPowerTrackingCallbackRXGainThermalMeter92D(
  686. IN PADAPTER Adapter
  687. );
  688. VOID
  689. odm_TXPowerTrackingCallbackThermalMeter92D(
  690. IN PADAPTER Adapter
  691. );
  692. VOID
  693. odm_TXPowerTrackingDirectCall92C(
  694. IN PADAPTER Adapter
  695. );
  696. VOID
  697. odm_TXPowerTrackingThermalMeterCheck(
  698. IN PADAPTER Adapter
  699. );
  700. #endif
  701. VOID
  702. odm_EdcaTurboCheck(
  703. IN PDM_ODM_T pDM_Odm
  704. );
  705. VOID
  706. ODM_EdcaTurboInit(
  707. IN PDM_ODM_T pDM_Odm
  708. );
  709. #if(DM_ODM_SUPPORT_TYPE==ODM_WIN)
  710. VOID
  711. odm_EdcaTurboCheckMP(
  712. IN PDM_ODM_T pDM_Odm
  713. );
  714. //check if edca turbo is disabled
  715. BOOLEAN
  716. odm_IsEdcaTurboDisable(
  717. IN PDM_ODM_T pDM_Odm
  718. );
  719. //choose edca paramter for special IOT case
  720. VOID
  721. ODM_EdcaParaSelByIot(
  722. IN PDM_ODM_T pDM_Odm,
  723. OUT u4Byte *EDCA_BE_UL,
  724. OUT u4Byte *EDCA_BE_DL
  725. );
  726. //check if it is UL or DL
  727. VOID
  728. odm_EdcaChooseTrafficIdx(
  729. IN PDM_ODM_T pDM_Odm,
  730. IN u8Byte cur_tx_bytes,
  731. IN u8Byte cur_rx_bytes,
  732. IN BOOLEAN bBiasOnRx,
  733. OUT BOOLEAN *pbIsCurRDLState
  734. );
  735. #elif (DM_ODM_SUPPORT_TYPE==ODM_CE)
  736. VOID
  737. odm_EdcaTurboCheckCE(
  738. IN PDM_ODM_T pDM_Odm
  739. );
  740. #else
  741. VOID
  742. odm_IotEngine(
  743. IN PDM_ODM_T pDM_Odm
  744. );
  745. VOID
  746. odm_EdcaParaInit(
  747. IN PDM_ODM_T pDM_Odm
  748. );
  749. #endif
  750. #define RxDefaultAnt1 0x65a9
  751. #define RxDefaultAnt2 0x569a
  752. VOID
  753. odm_InitHybridAntDiv(
  754. IN PDM_ODM_T pDM_Odm
  755. );
  756. BOOLEAN
  757. odm_StaDefAntSel(
  758. IN PDM_ODM_T pDM_Odm,
  759. IN u4Byte OFDM_Ant1_Cnt,
  760. IN u4Byte OFDM_Ant2_Cnt,
  761. IN u4Byte CCK_Ant1_Cnt,
  762. IN u4Byte CCK_Ant2_Cnt,
  763. OUT u1Byte *pDefAnt
  764. );
  765. VOID
  766. odm_SetRxIdleAnt(
  767. IN PDM_ODM_T pDM_Odm,
  768. IN u1Byte Ant,
  769. IN BOOLEAN bDualPath
  770. );
  771. VOID
  772. odm_HwAntDiv(
  773. IN PDM_ODM_T pDM_Odm
  774. );
  775. VOID odm_PathDiversityInit(IN PDM_ODM_T pDM_Odm);
  776. VOID odm_PathDiversity( IN PDM_ODM_T pDM_Odm);
  777. #if 0
  778. //#if ((DM_ODM_SUPPORT_TYPE==ODM_AP)&&defined(HW_ANT_SWITCH))
  779. VOID
  780. odm_HW_AntennaSwitchInit(
  781. IN PDM_ODM_T pDM_Odm
  782. );
  783. VOID
  784. odm_SetRxIdleAnt(
  785. IN PDM_ODM_T pDM_Odm,
  786. IN u1Byte Ant
  787. );
  788. VOID
  789. odm_StaAntSelect(
  790. IN PDM_ODM_T pDM_Odm,
  791. IN struct stat_info *pstat
  792. );
  793. VOID
  794. odm_HW_IdleAntennaSelect(
  795. IN PDM_ODM_T pDM_Odm
  796. );
  797. u1Byte
  798. ODM_Diversity_AntennaSelect(
  799. IN PDM_ODM_T pDM_Odm,
  800. IN u1Byte *data
  801. );
  802. #endif
  803. //============================================================
  804. //3 Export Interface
  805. //============================================================
  806. //
  807. // 2011/09/21 MH Add to describe different team necessary resource allocate??
  808. //
  809. VOID
  810. ODM_DMInit(
  811. IN PDM_ODM_T pDM_Odm
  812. )
  813. {
  814. //2012.05.03 Luke: For all IC series
  815. odm_CommonInfoSelfInit(pDM_Odm);
  816. odm_CmnInfoInit_Debug(pDM_Odm);
  817. odm_DIGInit(pDM_Odm);
  818. odm_AdaptivityInit(pDM_Odm);
  819. odm_RateAdaptiveMaskInit(pDM_Odm);
  820. #if (RTL8192E_SUPPORT == 1)
  821. if(pDM_Odm->SupportICType==ODM_RTL8192E)
  822. {
  823. odm_PrimaryCCA_Check_Init(pDM_Odm);
  824. }
  825. #endif
  826. //#if (MP_DRIVER != 1)
  827. if ( *(pDM_Odm->mp_mode) != 1)
  828. odm_PathDiversityInit(pDM_Odm);
  829. //#endif
  830. ODM_EdcaTurboInit(pDM_Odm);
  831. if(pDM_Odm->SupportICType & ODM_IC_11AC_SERIES)
  832. {
  833. odm_TXPowerTrackingInit(pDM_Odm);
  834. //#if (MP_DRIVER != 1)
  835. if ( *(pDM_Odm->mp_mode) != 1)
  836. odm_InitHybridAntDiv(pDM_Odm);
  837. //#endif
  838. }
  839. else if(pDM_Odm->SupportICType & ODM_IC_11N_SERIES)
  840. {
  841. odm_DynamicBBPowerSavingInit(pDM_Odm);
  842. odm_DynamicTxPowerInit(pDM_Odm);
  843. odm_TXPowerTrackingInit(pDM_Odm);
  844. //ODM_EdcaTurboInit(pDM_Odm);
  845. //#if (MP_DRIVER != 1)
  846. if ( *(pDM_Odm->mp_mode) != 1) {
  847. if(pDM_Odm->SupportICType==ODM_RTL8723A)
  848. odm_SwAntDivInit(pDM_Odm);
  849. else if(pDM_Odm->SupportICType & (ODM_RTL8192C|ODM_RTL8192D))
  850. {
  851. if(pDM_Odm->AntDivType == HW_ANTDIV)
  852. odm_InitHybridAntDiv(pDM_Odm);
  853. else
  854. odm_SwAntDivInit(pDM_Odm);
  855. }
  856. else
  857. odm_InitHybridAntDiv(pDM_Odm);
  858. }
  859. //#endif
  860. //2010.05.30 LukeLee: For CE platform, files in IC subfolders may not be included to be compiled,
  861. // so compile flags must be left here to prevent from compile errors
  862. #if (RTL8188E_SUPPORT == 1)
  863. if(pDM_Odm->SupportICType==ODM_RTL8188E)
  864. {
  865. odm_PrimaryCCA_Init(pDM_Odm); // Gary
  866. ODM_RAInfo_Init_all(pDM_Odm);
  867. }
  868. #endif
  869. //2010.05.30 LukeLee: Following are not incorporated into ODM structure yet.
  870. #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
  871. if(pDM_Odm->SupportICType&ODM_RTL8723A)
  872. odm_PSDMonitorInit(pDM_Odm);
  873. if(!(pDM_Odm->SupportICType & (ODM_RTL8723A|ODM_RTL8188E)))
  874. {
  875. odm_RXHPInit(pDM_Odm);
  876. }
  877. if(pDM_Odm->SupportICType==ODM_RTL8192D)
  878. {
  879. odm_PathDivInit_92D(pDM_Odm); //92D Path Div Init //Neil Chen
  880. }
  881. #endif
  882. }
  883. odm_DynamicATCSwitch_init(pDM_Odm);
  884. }
  885. //
  886. // 2011/09/20 MH This is the entry pointer for all team to execute HW out source DM.
  887. // You can not add any dummy function here, be care, you can only use DM structure
  888. // to perform any new ODM_DM.
  889. //
  890. VOID
  891. ODM_DMWatchdog(
  892. IN PDM_ODM_T pDM_Odm
  893. )
  894. {
  895. //odm_CmnInfoHook_Debug(pDM_Odm);
  896. //odm_CmnInfoUpdate_Debug(pDM_Odm);
  897. odm_CommonInfoSelfUpdate(pDM_Odm);
  898. odm_BasicDbgMessage(pDM_Odm);
  899. odm_FalseAlarmCounterStatistics(pDM_Odm);
  900. ODM_RT_TRACE(pDM_Odm, ODM_COMP_DIG, ODM_DBG_LOUD, ("odm_DIG(): RSSI=0x%x\n",pDM_Odm->RSSI_Min));
  901. odm_RSSIMonitorCheck(pDM_Odm);
  902. #if (DM_ODM_SUPPORT_TYPE == ODM_CE)
  903. //#ifdef CONFIG_PLATFORM_SPRD
  904. //For CE Platform(SPRD or Tablet)
  905. //8723A or 8189ES platform
  906. //NeilChen--2012--08--24--
  907. //Fix Leave LPS issue
  908. if( (pDM_Odm->Adapter->pwrctrlpriv.pwr_mode != PS_MODE_ACTIVE) &&// in LPS mode
  909. (
  910. (pDM_Odm->SupportICType & (ODM_RTL8723A ) )||
  911. (pDM_Odm->SupportICType & (ODM_RTL8188E) &&((pDM_Odm->SupportInterface == ODM_ITRF_SDIO)) )
  912. )
  913. )
  914. {
  915. ODM_RT_TRACE(pDM_Odm,ODM_COMP_DIG, ODM_DBG_LOUD, ("----Step1: odm_DIG is in LPS mode\n"));
  916. ODM_RT_TRACE(pDM_Odm,ODM_COMP_DIG, ODM_DBG_LOUD, ("---Step2: 8723AS is in LPS mode\n"));
  917. odm_DIGbyRSSI_LPS(pDM_Odm);
  918. }
  919. else
  920. //#endif
  921. #endif
  922. {
  923. odm_DIG(pDM_Odm);
  924. }
  925. {
  926. pDIG_T pDM_DigTable = &pDM_Odm->DM_DigTable;
  927. odm_Adaptivity(pDM_Odm, pDM_DigTable->CurIGValue);
  928. }
  929. odm_CCKPacketDetectionThresh(pDM_Odm);
  930. if(*(pDM_Odm->pbPowerSaving)==TRUE)
  931. return;
  932. odm_RefreshRateAdaptiveMask(pDM_Odm);
  933. odm_RefreshBasicRateMask(pDM_Odm);
  934. odm_DynamicBBPowerSaving(pDM_Odm);
  935. odm_EdcaTurboCheck(pDM_Odm);
  936. odm_PathDiversity(pDM_Odm);
  937. odm_DynamicATCSwitch(pDM_Odm);
  938. #if 0
  939. #if (RTL8723B_SUPPORT == 1)
  940. if(pDM_Odm->SupportICType==ODM_RTL8723B)
  941. odm_DynamicPrimaryCCA_Check(pDM_Odm);
  942. #endif
  943. #endif
  944. #if (RTL8192E_SUPPORT == 1)
  945. if(pDM_Odm->SupportICType==ODM_RTL8192E)
  946. odm_DynamicPrimaryCCA_Check(pDM_Odm);
  947. #endif
  948. if(pDM_Odm->SupportICType == ODM_RTL8192E)
  949. return;
  950. //#if (MP_DRIVER != 1)
  951. if ( *(pDM_Odm->mp_mode) != 1) {
  952. if(pDM_Odm->SupportICType==ODM_RTL8723A)
  953. {
  954. odm_SwAntDivChkAntSwitch(pDM_Odm, SWAW_STEP_PEAK);
  955. }
  956. else if(pDM_Odm->SupportICType & (ODM_RTL8192C|ODM_RTL8192D))
  957. {
  958. if(pDM_Odm->AntDivType == HW_ANTDIV)
  959. odm_HwAntDiv(pDM_Odm);
  960. else
  961. odm_SwAntDivChkAntSwitch(pDM_Odm, SWAW_STEP_PEAK);
  962. }
  963. else
  964. odm_HwAntDiv(pDM_Odm);
  965. }
  966. //#endif
  967. if(pDM_Odm->SupportICType & ODM_IC_11AC_SERIES)
  968. {
  969. if (pDM_Odm->SupportICType & (ODM_RTL8812|ODM_RTL8821))
  970. //if (pDM_Odm->SupportICType & ODM_RTL8812)
  971. {
  972. ODM_TXPowerTrackingCheck(pDM_Odm);
  973. }
  974. #if (RTL8821A_SUPPORT == 1)
  975. if(pDM_Odm->SupportICType & ODM_RTL8821)
  976. {
  977. if(pDM_Odm->bLinked)
  978. {
  979. if((*pDM_Odm->pChannel != pDM_Odm->preChannel) && (!*pDM_Odm->pbScanInProcess))
  980. {
  981. pDM_Odm->preChannel = *pDM_Odm->pChannel;
  982. pDM_Odm->LinkedInterval = 0;
  983. }
  984. if(pDM_Odm->LinkedInterval < 3)
  985. pDM_Odm->LinkedInterval++;
  986. if(pDM_Odm->LinkedInterval == 2)
  987. {
  988. PADAPTER pAdapter = pDM_Odm->Adapter;
  989. //mark out IQK flow to prevent tx stuck. by Maddest 20130306
  990. //PHY_IQCalibrate_8821A(pAdapter, FALSE);
  991. }
  992. }
  993. else
  994. pDM_Odm->LinkedInterval = 0;
  995. }
  996. #endif
  997. }
  998. else if(pDM_Odm->SupportICType & ODM_IC_11N_SERIES)
  999. {
  1000. if (!(pDM_Odm->SupportICType & (ODM_RTL8723B)))
  1001. ODM_TXPowerTrackingCheck(pDM_Odm);
  1002. //odm_EdcaTurboCheck(pDM_Odm);
  1003. odm_DynamicTxPower(pDM_Odm);
  1004. #if( DM_ODM_SUPPORT_TYPE & (ODM_WIN))
  1005. if(!(pDM_Odm->SupportICType & (ODM_RTL8723A|ODM_RTL8188E)))
  1006. odm_RXHP(pDM_Odm);
  1007. #endif
  1008. //2010.05.30 LukeLee: For CE platform, files in IC subfolders may not be included to be compiled,
  1009. // so compile flags must be left here to prevent from compile errors
  1010. #if (RTL8192D_SUPPORT == 1)
  1011. if(pDM_Odm->SupportICType==ODM_RTL8192D)
  1012. ODM_DynamicEarlyMode(pDM_Odm);
  1013. #endif
  1014. odm_DynamicBBPowerSaving(pDM_Odm);
  1015. #if (RTL8188E_SUPPORT == 1)
  1016. if(pDM_Odm->SupportICType==ODM_RTL8188E)
  1017. odm_DynamicPrimaryCCA(pDM_Odm);
  1018. #endif
  1019. }
  1020. pDM_Odm->PhyDbgInfo.NumQryBeaconPkt = 0;
  1021. #if (DM_ODM_SUPPORT_TYPE == ODM_CE)
  1022. odm_dtc(pDM_Odm);
  1023. #endif
  1024. }
  1025. //
  1026. // Init /.. Fixed HW value. Only init time.
  1027. //
  1028. VOID
  1029. ODM_CmnInfoInit(
  1030. IN PDM_ODM_T pDM_Odm,
  1031. IN ODM_CMNINFO_E CmnInfo,
  1032. IN u4Byte Value
  1033. )
  1034. {
  1035. //ODM_RT_TRACE(pDM_Odm,);
  1036. //
  1037. // This section is used for init value
  1038. //
  1039. switch (CmnInfo)
  1040. {
  1041. //
  1042. // Fixed ODM value.
  1043. //
  1044. case ODM_CMNINFO_ABILITY:
  1045. pDM_Odm->SupportAbility = (u4Byte)Value;
  1046. break;
  1047. case ODM_CMNINFO_RF_TYPE:
  1048. pDM_Odm->RFType = (u1Byte)Value;
  1049. break;
  1050. case ODM_CMNINFO_PLATFORM:
  1051. pDM_Odm->SupportPlatform = (u1Byte)Value;
  1052. break;
  1053. case ODM_CMNINFO_INTERFACE:
  1054. pDM_Odm->SupportInterface = (u1Byte)Value;
  1055. break;
  1056. case ODM_CMNINFO_MP_TEST_CHIP:
  1057. pDM_Odm->bIsMPChip= (u1Byte)Value;
  1058. break;
  1059. case ODM_CMNINFO_IC_TYPE:
  1060. pDM_Odm->SupportICType = Value;
  1061. break;
  1062. case ODM_CMNINFO_CUT_VER:
  1063. pDM_Odm->CutVersion = (u1Byte)Value;
  1064. break;
  1065. case ODM_CMNINFO_FAB_VER:
  1066. pDM_Odm->FabVersion = (u1Byte)Value;
  1067. break;
  1068. case ODM_CMNINFO_RFE_TYPE:
  1069. pDM_Odm->RFEType = (u1Byte)Value;
  1070. break;
  1071. case ODM_CMNINFO_RF_ANTENNA_TYPE:
  1072. pDM_Odm->AntDivType= (u1Byte)Value;
  1073. break;
  1074. case ODM_CMNINFO_BOARD_TYPE:
  1075. pDM_Odm->BoardType = (u1Byte)Value;
  1076. break;
  1077. case ODM_CMNINFO_EXT_LNA:
  1078. pDM_Odm->ExtLNA = (u1Byte)Value;
  1079. break;
  1080. case ODM_CMNINFO_5G_EXT_LNA:
  1081. pDM_Odm->ExtLNA5G = (u1Byte)Value;
  1082. break;
  1083. case ODM_CMNINFO_EXT_PA:
  1084. pDM_Odm->ExtPA = (u1Byte)Value;
  1085. break;
  1086. case ODM_CMNINFO_5G_EXT_PA:
  1087. pDM_Odm->ExtPA5G = (u1Byte)Value;
  1088. break;
  1089. case ODM_CMNINFO_EXT_TRSW:
  1090. pDM_Odm->ExtTRSW = (u1Byte)Value;
  1091. break;
  1092. case ODM_CMNINFO_PATCH_ID:
  1093. pDM_Odm->PatchID = (u1Byte)Value;
  1094. break;
  1095. case ODM_CMNINFO_BINHCT_TEST:
  1096. pDM_Odm->bInHctTest = (BOOLEAN)Value;
  1097. break;
  1098. case ODM_CMNINFO_BWIFI_TEST:
  1099. pDM_Odm->bWIFITest = (BOOLEAN)Value;
  1100. break;
  1101. case ODM_CMNINFO_SMART_CONCURRENT:
  1102. pDM_Odm->bDualMacSmartConcurrent = (BOOLEAN )Value;
  1103. break;
  1104. //To remove the compiler warning, must add an empty default statement to handle the other values.
  1105. default:
  1106. //do nothing
  1107. break;
  1108. }
  1109. }
  1110. VOID
  1111. ODM_CmnInfoHook(
  1112. IN PDM_ODM_T pDM_Odm,
  1113. IN ODM_CMNINFO_E CmnInfo,
  1114. IN PVOID pValue
  1115. )
  1116. {
  1117. //
  1118. // Hook call by reference pointer.
  1119. //
  1120. switch (CmnInfo)
  1121. {
  1122. //
  1123. // Dynamic call by reference pointer.
  1124. //
  1125. case ODM_CMNINFO_MAC_PHY_MODE:
  1126. pDM_Odm->pMacPhyMode = (u1Byte *)pValue;
  1127. break;
  1128. case ODM_CMNINFO_TX_UNI:
  1129. pDM_Odm->pNumTxBytesUnicast = (u8Byte *)pValue;
  1130. break;
  1131. case ODM_CMNINFO_RX_UNI:
  1132. pDM_Odm->pNumRxBytesUnicast = (u8Byte *)pValue;
  1133. break;
  1134. case ODM_CMNINFO_WM_MODE:
  1135. pDM_Odm->pWirelessMode = (u1Byte *)pValue;
  1136. break;
  1137. case ODM_CMNINFO_BAND:
  1138. pDM_Odm->pBandType = (u1Byte *)pValue;
  1139. break;
  1140. case ODM_CMNINFO_SEC_CHNL_OFFSET:
  1141. pDM_Odm->pSecChOffset = (u1Byte *)pValue;
  1142. break;
  1143. case ODM_CMNINFO_SEC_MODE:
  1144. pDM_Odm->pSecurity = (u1Byte *)pValue;
  1145. break;
  1146. case ODM_CMNINFO_BW:
  1147. pDM_Odm->pBandWidth = (u1Byte *)pValue;
  1148. break;
  1149. case ODM_CMNINFO_CHNL:
  1150. pDM_Odm->pChannel = (u1Byte *)pValue;
  1151. break;
  1152. case ODM_CMNINFO_DMSP_GET_VALUE:
  1153. pDM_Odm->pbGetValueFromOtherMac = (BOOLEAN *)pValue;
  1154. break;
  1155. case ODM_CMNINFO_BUDDY_ADAPTOR:
  1156. pDM_Odm->pBuddyAdapter = (PADAPTER *)pValue;
  1157. break;
  1158. case ODM_CMNINFO_DMSP_IS_MASTER:
  1159. pDM_Odm->pbMasterOfDMSP = (BOOLEAN *)pValue;
  1160. break;
  1161. case ODM_CMNINFO_SCAN:
  1162. pDM_Odm->pbScanInProcess = (BOOLEAN *)pValue;
  1163. break;
  1164. case ODM_CMNINFO_POWER_SAVING:
  1165. pDM_Odm->pbPowerSaving = (BOOLEAN *)pValue;
  1166. break;
  1167. case ODM_CMNINFO_ONE_PATH_CCA:
  1168. pDM_Odm->pOnePathCCA = (u1Byte *)pValue;
  1169. break;
  1170. case ODM_CMNINFO_DRV_STOP:
  1171. pDM_Odm->pbDriverStopped = (BOOLEAN *)pValue;
  1172. break;
  1173. case ODM_CMNINFO_PNP_IN:
  1174. pDM_Odm->pbDriverIsGoingToPnpSetPowerSleep = (BOOLEAN *)pValue;
  1175. break;
  1176. case ODM_CMNINFO_INIT_ON:
  1177. pDM_Odm->pinit_adpt_in_progress = (BOOLEAN *)pValue;
  1178. break;
  1179. case ODM_CMNINFO_ANT_TEST:
  1180. pDM_Odm->pAntennaTest = (u1Byte *)pValue;
  1181. break;
  1182. case ODM_CMNINFO_NET_CLOSED:
  1183. pDM_Odm->pbNet_closed = (BOOLEAN *)pValue;
  1184. break;
  1185. case ODM_CMNINFO_FORCED_RATE:
  1186. pDM_Odm->pForcedDataRate = (pu2Byte)pValue;
  1187. break;
  1188. case ODM_CMNINFO_MP_MODE:
  1189. pDM_Odm->mp_mode = (u1Byte *)pValue;
  1190. break;
  1191. //case ODM_CMNINFO_RTSTA_AID:
  1192. // pDM_Odm->pAidMap = (u1Byte *)pValue;
  1193. // break;
  1194. //case ODM_CMNINFO_BT_COEXIST:
  1195. // pDM_Odm->BTCoexist = (BOOLEAN *)pValue;
  1196. //case ODM_CMNINFO_STA_STATUS:
  1197. //pDM_Odm->pODM_StaInfo[] = (PSTA_INFO_T)pValue;
  1198. //break;
  1199. //case ODM_CMNINFO_PHY_STATUS:
  1200. // pDM_Odm->pPhyInfo = (ODM_PHY_INFO *)pValue;
  1201. // break;
  1202. //case ODM_CMNINFO_MAC_STATUS:
  1203. // pDM_Odm->pMacInfo = (ODM_MAC_INFO *)pValue;
  1204. // break;
  1205. //To remove the compiler warning, must add an empty default statement to handle the other values.
  1206. default:
  1207. //do nothing
  1208. break;
  1209. }
  1210. }
  1211. VOID
  1212. ODM_CmnInfoPtrArrayHook(
  1213. IN PDM_ODM_T pDM_Odm,
  1214. IN ODM_CMNINFO_E CmnInfo,
  1215. IN u2Byte Index,
  1216. IN PVOID pValue
  1217. )
  1218. {
  1219. //
  1220. // Hook call by reference pointer.
  1221. //
  1222. switch (CmnInfo)
  1223. {
  1224. //
  1225. // Dynamic call by reference pointer.
  1226. //
  1227. case ODM_CMNINFO_STA_STATUS:
  1228. pDM_Odm->pODM_StaInfo[Index] = (PSTA_INFO_T)pValue;
  1229. break;
  1230. //To remove the compiler warning, must add an empty default statement to handle the other values.
  1231. default:
  1232. //do nothing
  1233. break;
  1234. }
  1235. }
  1236. //
  1237. // Update Band/CHannel/.. The values are dynamic but non-per-packet.
  1238. //
  1239. VOID
  1240. ODM_CmnInfoUpdate(
  1241. IN PDM_ODM_T pDM_Odm,
  1242. IN u4Byte CmnInfo,
  1243. IN u8Byte Value
  1244. )
  1245. {
  1246. //
  1247. // This init variable may be changed in run time.
  1248. //
  1249. switch (CmnInfo)
  1250. {
  1251. case ODM_CMNINFO_LINK_IN_PROGRESS:
  1252. pDM_Odm->bLinkInProcess = (BOOLEAN)Value;
  1253. break;
  1254. case ODM_CMNINFO_ABILITY:
  1255. pDM_Odm->SupportAbility = (u4Byte)Value;
  1256. break;
  1257. case ODM_CMNINFO_RF_TYPE:
  1258. pDM_Odm->RFType = (u1Byte)Value;
  1259. break;
  1260. case ODM_CMNINFO_WIFI_DIRECT:
  1261. pDM_Odm->bWIFI_Direct = (BOOLEAN)Value;
  1262. break;
  1263. case ODM_CMNINFO_WIFI_DISPLAY:
  1264. pDM_Odm->bWIFI_Display = (BOOLEAN)Value;
  1265. break;
  1266. case ODM_CMNINFO_LINK:
  1267. pDM_Odm->bLinked = (BOOLEAN)Value;
  1268. break;
  1269. case ODM_CMNINFO_RSSI_MIN:
  1270. pDM_Odm->RSSI_Min= (u1Byte)Value;
  1271. break;
  1272. case ODM_CMNINFO_DBG_COMP:
  1273. pDM_Odm->DebugComponents = Value;
  1274. break;
  1275. case ODM_CMNINFO_DBG_LEVEL:
  1276. pDM_Odm->DebugLevel = (u4Byte)Value;
  1277. break;
  1278. case ODM_CMNINFO_RA_THRESHOLD_HIGH:
  1279. pDM_Odm->RateAdaptive.HighRSSIThresh = (u1Byte)Value;
  1280. break;
  1281. case ODM_CMNINFO_RA_THRESHOLD_LOW:
  1282. pDM_Odm->RateAdaptive.LowRSSIThresh = (u1Byte)Value;
  1283. break;
  1284. // The following is for BT HS mode and BT coexist mechanism.
  1285. case ODM_CMNINFO_BT_DISABLED:
  1286. pDM_Odm->bBtDisabled = (BOOLEAN)Value;
  1287. break;
  1288. case ODM_CMNINFO_BT_HS_CONNECT_PROCESS:
  1289. pDM_Odm->bBtConnectProcess = (BOOLEAN)Value;
  1290. break;
  1291. case ODM_CMNINFO_BT_HS_RSSI:
  1292. pDM_Odm->btHsRssi = (u1Byte)Value;
  1293. break;
  1294. case ODM_CMNINFO_BT_OPERATION:
  1295. pDM_Odm->bBtHsOperation = (BOOLEAN)Value;
  1296. break;
  1297. case ODM_CMNINFO_BT_LIMITED_DIG:
  1298. pDM_Odm->bBtLimitedDig = (BOOLEAN)Value;
  1299. break;
  1300. case ODM_CMNINFO_BT_DISABLE_EDCA:
  1301. pDM_Odm->bBtDisableEdcaTurbo = (BOOLEAN)Value;
  1302. break;
  1303. /*
  1304. case ODM_CMNINFO_OP_MODE:
  1305. pDM_Odm->OPMode = (u1Byte)Value;
  1306. break;
  1307. case ODM_CMNINFO_WM_MODE:
  1308. pDM_Odm->WirelessMode = (u1Byte)Value;
  1309. break;
  1310. case ODM_CMNINFO_BAND:
  1311. pDM_Odm->BandType = (u1Byte)Value;
  1312. break;
  1313. case ODM_CMNINFO_SEC_CHNL_OFFSET:
  1314. pDM_Odm->SecChOffset = (u1Byte)Value;
  1315. break;
  1316. case ODM_CMNINFO_SEC_MODE:
  1317. pDM_Odm->Security = (u1Byte)Value;
  1318. break;
  1319. case ODM_CMNINFO_BW:
  1320. pDM_Odm->BandWidth = (u1Byte)Value;
  1321. break;
  1322. case ODM_CMNINFO_CHNL:
  1323. pDM_Odm->Channel = (u1Byte)Value;
  1324. break;
  1325. */
  1326. default:
  1327. //do nothing
  1328. break;
  1329. }
  1330. }
  1331. VOID
  1332. odm_CommonInfoSelfInit(
  1333. IN PDM_ODM_T pDM_Odm
  1334. )
  1335. {
  1336. pDM_Odm->bCckHighPower = (BOOLEAN) ODM_GetBBReg(pDM_Odm, ODM_REG(CCK_RPT_FORMAT,pDM_Odm), ODM_BIT(CCK_RPT_FORMAT,pDM_Odm));
  1337. pDM_Odm->RFPathRxEnable = (u1Byte) ODM_GetBBReg(pDM_Odm, ODM_REG(BB_RX_PATH,pDM_Odm), ODM_BIT(BB_RX_PATH,pDM_Odm));
  1338. #if (DM_ODM_SUPPORT_TYPE != ODM_CE)
  1339. pDM_Odm->pbNet_closed = &pDM_Odm->BOOLEAN_temp;
  1340. #endif
  1341. if(pDM_Odm->SupportICType==ODM_RTL8723A)
  1342. {
  1343. pDM_Odm->AntDivType = SW_ANTDIV;
  1344. }
  1345. else if(pDM_Odm->SupportICType==ODM_RTL8723B)
  1346. {
  1347. //pDM_Odm->AntDivType = S0S1_HW_ANTDIV;
  1348. pDM_Odm->AntDivType = CG_TRX_HW_ANTDIV;
  1349. }
  1350. else if(pDM_Odm->SupportICType & (ODM_RTL8192C|ODM_RTL8192D))
  1351. {
  1352. #if(defined(CONFIG_HW_ANTENNA_DIVERSITY))
  1353. pDM_Odm->AntDivType = HW_ANTDIV;
  1354. #elif (defined(CONFIG_SW_ANTENNA_DIVERSITY))
  1355. pDM_Odm->AntDivType = SW_ANTDIV;
  1356. #endif
  1357. }
  1358. pDM_Odm->TxRate = 0xFF;
  1359. ODM_InitDebugSetting(pDM_Odm);
  1360. }
  1361. VOID
  1362. odm_CommonInfoSelfUpdate(
  1363. IN PDM_ODM_T pDM_Odm
  1364. )
  1365. {
  1366. u1Byte EntryCnt=0;
  1367. u1Byte i;
  1368. PSTA_INFO_T pEntry;
  1369. #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
  1370. PADAPTER Adapter = pDM_Odm->Adapter;
  1371. PMGNT_INFO pMgntInfo = &Adapter->MgntInfo;
  1372. pEntry = pDM_Odm->pODM_StaInfo[0];
  1373. if(pMgntInfo->mAssoc)
  1374. {
  1375. pEntry->bUsed=TRUE;
  1376. for (i=0; i<6; i++)
  1377. pEntry->MacAddr[i] = pMgntInfo->Bssid[i];
  1378. }
  1379. else
  1380. {
  1381. pEntry->bUsed=FALSE;
  1382. for (i=0; i<6; i++)
  1383. pEntry->MacAddr[i] = 0;
  1384. }
  1385. #endif
  1386. if(*(pDM_Odm->pBandWidth) == ODM_BW40M)
  1387. {
  1388. if(*(pDM_Odm->pSecChOffset) == 1)
  1389. pDM_Odm->ControlChannel = *(pDM_Odm->pChannel) -2;
  1390. else if(*(pDM_Odm->pSecChOffset) == 2)
  1391. pDM_Odm->ControlChannel = *(pDM_Odm->pChannel) +2;
  1392. }
  1393. else
  1394. pDM_Odm->ControlChannel = *(pDM_Odm->pChannel);
  1395. for (i=0; i<ODM_ASSOCIATE_ENTRY_NUM; i++)
  1396. {
  1397. pEntry = pDM_Odm->pODM_StaInfo[i];
  1398. if(IS_STA_VALID(pEntry))
  1399. EntryCnt++;
  1400. }
  1401. if(EntryCnt == 1)
  1402. pDM_Odm->bOneEntryOnly = TRUE;
  1403. else
  1404. pDM_Odm->bOneEntryOnly = FALSE;
  1405. }
  1406. VOID
  1407. odm_CmnInfoInit_Debug(
  1408. IN PDM_ODM_T pDM_Odm
  1409. )
  1410. {
  1411. ODM_RT_TRACE(pDM_Odm,ODM_COMP_COMMON, ODM_DBG_LOUD, ("odm_CmnInfoInit_Debug==>\n"));
  1412. ODM_RT_TRACE(pDM_Odm,ODM_COMP_COMMON, ODM_DBG_LOUD, ("SupportPlatform=%d\n",pDM_Odm->SupportPlatform) );
  1413. ODM_RT_TRACE(pDM_Odm,ODM_COMP_COMMON, ODM_DBG_LOUD, ("SupportAbility=0x%x\n",pDM_Odm->SupportAbility) );
  1414. ODM_RT_TRACE(pDM_Odm,ODM_COMP_COMMON, ODM_DBG_LOUD, ("SupportInterface=%d\n",pDM_Odm->SupportInterface) );
  1415. ODM_RT_TRACE(pDM_Odm,ODM_COMP_COMMON, ODM_DBG_LOUD, ("SupportICType=0x%x\n",pDM_Odm->SupportICType) );
  1416. ODM_RT_TRACE(pDM_Odm,ODM_COMP_COMMON, ODM_DBG_LOUD, ("CutVersion=%d\n",pDM_Odm->CutVersion) );
  1417. ODM_RT_TRACE(pDM_Odm,ODM_COMP_COMMON, ODM_DBG_LOUD, ("FabVersion=%d\n",pDM_Odm->FabVersion) );
  1418. ODM_RT_TRACE(pDM_Odm,ODM_COMP_COMMON, ODM_DBG_LOUD, ("RFType=%d\n",pDM_Odm->RFType) );
  1419. ODM_RT_TRACE(pDM_Odm,ODM_COMP_COMMON, ODM_DBG_LOUD, ("BoardType=%d\n",pDM_Odm->BoardType) );
  1420. ODM_RT_TRACE(pDM_Odm,ODM_COMP_COMMON, ODM_DBG_LOUD, ("ExtLNA=%d\n",pDM_Odm->ExtLNA) );
  1421. ODM_RT_TRACE(pDM_Odm,ODM_COMP_COMMON, ODM_DBG_LOUD, ("ExtPA=%d\n",pDM_Odm->ExtPA) );
  1422. ODM_RT_TRACE(pDM_Odm,ODM_COMP_COMMON, ODM_DBG_LOUD, ("ExtTRSW=%d\n",pDM_Odm->ExtTRSW) );
  1423. ODM_RT_TRACE(pDM_Odm,ODM_COMP_COMMON, ODM_DBG_LOUD, ("PatchID=%d\n",pDM_Odm->PatchID) );
  1424. ODM_RT_TRACE(pDM_Odm,ODM_COMP_COMMON, ODM_DBG_LOUD, ("bInHctTest=%d\n",pDM_Odm->bInHctTest) );
  1425. ODM_RT_TRACE(pDM_Odm,ODM_COMP_COMMON, ODM_DBG_LOUD, ("bWIFITest=%d\n",pDM_Odm->bWIFITest) );
  1426. ODM_RT_TRACE(pDM_Odm,ODM_COMP_COMMON, ODM_DBG_LOUD, ("bDualMacSmartConcurrent=%d\n",pDM_Odm->bDualMacSmartConcurrent) );
  1427. }
  1428. VOID
  1429. odm_CmnInfoHook_Debug(
  1430. IN PDM_ODM_T pDM_Odm
  1431. )
  1432. {
  1433. ODM_RT_TRACE(pDM_Odm,ODM_COMP_COMMON, ODM_DBG_LOUD, ("odm_CmnInfoHook_Debug==>\n"));
  1434. ODM_RT_TRACE(pDM_Odm,ODM_COMP_COMMON, ODM_DBG_LOUD, ("pNumTxBytesUnicast=%llu\n",*(pDM_Odm->pNumTxBytesUnicast)) );
  1435. ODM_RT_TRACE(pDM_Odm,ODM_COMP_COMMON, ODM_DBG_LOUD, ("pNumRxBytesUnicast=%llu\n",*(pDM_Odm->pNumRxBytesUnicast)) );
  1436. ODM_RT_TRACE(pDM_Odm,ODM_COMP_COMMON, ODM_DBG_LOUD, ("pWirelessMode=0x%x\n",*(pDM_Odm->pWirelessMode)) );
  1437. ODM_RT_TRACE(pDM_Odm,ODM_COMP_COMMON, ODM_DBG_LOUD, ("pSecChOffset=%d\n",*(pDM_Odm->pSecChOffset)) );
  1438. ODM_RT_TRACE(pDM_Odm,ODM_COMP_COMMON, ODM_DBG_LOUD, ("pSecurity=%d\n",*(pDM_Odm->pSecurity)) );
  1439. ODM_RT_TRACE(pDM_Odm,ODM_COMP_COMMON, ODM_DBG_LOUD, ("pBandWidth=%d\n",*(pDM_Odm->pBandWidth)) );
  1440. ODM_RT_TRACE(pDM_Odm,ODM_COMP_COMMON, ODM_DBG_LOUD, ("pChannel=%d\n",*(pDM_Odm->pChannel)) );
  1441. if(pDM_Odm->SupportICType==ODM_RTL8192D)
  1442. {
  1443. if(pDM_Odm->pBandType)
  1444. ODM_RT_TRACE(pDM_Odm,ODM_COMP_COMMON, ODM_DBG_LOUD, ("pBandType=%d\n",*(pDM_Odm->pBandType)) );
  1445. if(pDM_Odm->pMacPhyMode)
  1446. ODM_RT_TRACE(pDM_Odm,ODM_COMP_COMMON, ODM_DBG_LOUD, ("pMacPhyMode=%d\n",*(pDM_Odm->pMacPhyMode)) );
  1447. if(pDM_Odm->pBuddyAdapter)
  1448. ODM_RT_TRACE(pDM_Odm,ODM_COMP_COMMON, ODM_DBG_LOUD, ("pbGetValueFromOtherMac=%d\n",*(pDM_Odm->pbGetValueFromOtherMac)) );
  1449. if(pDM_Odm->pBuddyAdapter)
  1450. ODM_RT_TRACE(pDM_Odm,ODM_COMP_COMMON, ODM_DBG_LOUD, ("pBuddyAdapter=%p\n",*(pDM_Odm->pBuddyAdapter)) );
  1451. if(pDM_Odm->pbMasterOfDMSP)
  1452. ODM_RT_TRACE(pDM_Odm,ODM_COMP_COMMON, ODM_DBG_LOUD, ("pbMasterOfDMSP=%d\n",*(pDM_Odm->pbMasterOfDMSP)) );
  1453. }
  1454. ODM_RT_TRACE(pDM_Odm,ODM_COMP_COMMON, ODM_DBG_LOUD, ("pbScanInProcess=%d\n",*(pDM_Odm->pbScanInProcess)) );
  1455. ODM_RT_TRACE(pDM_Odm,ODM_COMP_COMMON, ODM_DBG_LOUD, ("pbPowerSaving=%d\n",*(pDM_Odm->pbPowerSaving)) );
  1456. if(pDM_Odm->SupportPlatform & (ODM_AP|ODM_ADSL))
  1457. ODM_RT_TRACE(pDM_Odm,ODM_COMP_COMMON, ODM_DBG_LOUD, ("pOnePathCCA=%d\n",*(pDM_Odm->pOnePathCCA)) );
  1458. }
  1459. VOID
  1460. odm_CmnInfoUpdate_Debug(
  1461. IN PDM_ODM_T pDM_Odm
  1462. )
  1463. {
  1464. ODM_RT_TRACE(pDM_Odm,ODM_COMP_COMMON, ODM_DBG_LOUD, ("odm_CmnInfoUpdate_Debug==>\n"));
  1465. ODM_RT_TRACE(pDM_Odm,ODM_COMP_COMMON, ODM_DBG_LOUD, ("bWIFI_Direct=%d\n",pDM_Odm->bWIFI_Direct) );
  1466. ODM_RT_TRACE(pDM_Odm,ODM_COMP_COMMON, ODM_DBG_LOUD, ("bWIFI_Display=%d\n",pDM_Odm->bWIFI_Display) );
  1467. ODM_RT_TRACE(pDM_Odm,ODM_COMP_COMMON, ODM_DBG_LOUD, ("bLinked=%d\n",pDM_Odm->bLinked) );
  1468. ODM_RT_TRACE(pDM_Odm,ODM_COMP_COMMON, ODM_DBG_LOUD, ("RSSI_Min=%d\n",pDM_Odm->RSSI_Min) );
  1469. }
  1470. VOID
  1471. odm_BasicDbgMessage
  1472. (
  1473. IN PDM_ODM_T pDM_Odm
  1474. )
  1475. {
  1476. PFALSE_ALARM_STATISTICS FalseAlmCnt = &(pDM_Odm->FalseAlmCnt);
  1477. pDIG_T pDM_DigTable = &pDM_Odm->DM_DigTable;
  1478. ODM_RT_TRACE(pDM_Odm,ODM_COMP_COMMON, ODM_DBG_LOUD, ("odm_BasicDbgMsg==>\n"));
  1479. ODM_RT_TRACE(pDM_Odm,ODM_COMP_COMMON, ODM_DBG_LOUD, ("bLinked = %d, RSSI_Min = %d, CurrentIGI = 0x%x \n",
  1480. pDM_Odm->bLinked, pDM_Odm->RSSI_Min, pDM_DigTable->CurIGValue) );
  1481. ODM_RT_TRACE(pDM_Odm,ODM_COMP_COMMON, ODM_DBG_LOUD, ("Cnt_Cck_fail = %d, Cnt_Ofdm_fail = %d, Total False Alarm = %d\n",
  1482. FalseAlmCnt->Cnt_Cck_fail, FalseAlmCnt->Cnt_Ofdm_fail, FalseAlmCnt->Cnt_all));
  1483. ODM_RT_TRACE(pDM_Odm,ODM_COMP_COMMON, ODM_DBG_LOUD, ("RxRate = 0x%x, RSSI_A = %d, RSSI_B = %d\n",
  1484. pDM_Odm->RxRate, pDM_Odm->RSSI_A, pDM_Odm->RSSI_B));
  1485. }
  1486. #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
  1487. VOID
  1488. ODM_InitAllWorkItems(IN PDM_ODM_T pDM_Odm )
  1489. {
  1490. #if USE_WORKITEM
  1491. PADAPTER pAdapter = pDM_Odm->Adapter;
  1492. ODM_InitializeWorkItem( pDM_Odm,
  1493. &pDM_Odm->DM_SWAT_Table.SwAntennaSwitchWorkitem,
  1494. (RT_WORKITEM_CALL_BACK)odm_SwAntDivChkAntSwitchWorkitemCallback,
  1495. (PVOID)pAdapter,
  1496. "AntennaSwitchWorkitem"
  1497. );
  1498. ODM_InitializeWorkItem(
  1499. pDM_Odm,
  1500. &(pDM_Odm->PathDivSwitchWorkitem),
  1501. (RT_WORKITEM_CALL_BACK)odm_PathDivChkAntSwitchWorkitemCallback,
  1502. (PVOID)pAdapter,
  1503. "SWAS_WorkItem");
  1504. ODM_InitializeWorkItem(
  1505. pDM_Odm,
  1506. &(pDM_Odm->CCKPathDiversityWorkitem),
  1507. (RT_WORKITEM_CALL_BACK)odm_CCKTXPathDiversityWorkItemCallback,
  1508. (PVOID)pAdapter,
  1509. "CCKTXPathDiversityWorkItem");
  1510. ODM_InitializeWorkItem(
  1511. pDM_Odm,
  1512. &(pDM_Odm->MPT_DIGWorkitem),
  1513. (RT_WORKITEM_CALL_BACK)odm_MPT_DIGWorkItemCallback,
  1514. (PVOID)pAdapter,
  1515. "MPT_DIGWorkitem");
  1516. #if(defined(CONFIG_HW_ANTENNA_DIVERSITY))
  1517. #if (RTL8188E_SUPPORT == 1)
  1518. ODM_InitializeWorkItem(
  1519. pDM_Odm,
  1520. &(pDM_Odm->FastAntTrainingWorkitem),
  1521. (RT_WORKITEM_CALL_BACK)odm_FastAntTrainingWorkItemCallback,
  1522. (PVOID)pAdapter,
  1523. "FastAntTrainingWorkitem");
  1524. #endif
  1525. #endif
  1526. ODM_InitializeWorkItem(
  1527. pDM_Odm,
  1528. &(pDM_Odm->DM_RXHP_Table.PSDTimeWorkitem),
  1529. (RT_WORKITEM_CALL_BACK)odm_PSD_RXHPWorkitemCallback,
  1530. (PVOID)pAdapter,
  1531. "PSDRXHP_WorkItem");
  1532. #endif
  1533. }
  1534. VOID
  1535. ODM_FreeAllWorkItems(IN PDM_ODM_T pDM_Odm )
  1536. {
  1537. #if USE_WORKITEM
  1538. ODM_FreeWorkItem( &(pDM_Odm->DM_SWAT_Table.SwAntennaSwitchWorkitem));
  1539. ODM_FreeWorkItem(&(pDM_Odm->PathDivSwitchWorkitem));
  1540. ODM_FreeWorkItem(&(pDM_Odm->CCKPathDiversityWorkitem));
  1541. ODM_FreeWorkItem(&(pDM_Odm->FastAntTrainingWorkitem));
  1542. ODM_FreeWorkItem(&(pDM_Odm->MPT_DIGWorkitem));
  1543. ODM_FreeWorkItem((&pDM_Odm->DM_RXHP_Table.PSDTimeWorkitem));
  1544. #endif
  1545. }
  1546. #endif
  1547. /*
  1548. VOID
  1549. odm_FindMinimumRSSI(
  1550. IN PDM_ODM_T pDM_Odm
  1551. )
  1552. {
  1553. u4Byte i;
  1554. u1Byte RSSI_Min = 0xFF;
  1555. for(i=0; i<ODM_ASSOCIATE_ENTRY_NUM; i++)
  1556. {
  1557. // if(pDM_Odm->pODM_StaInfo[i] != NULL)
  1558. if(IS_STA_VALID(pDM_Odm->pODM_StaInfo[i]) )
  1559. {
  1560. if(pDM_Odm->pODM_StaInfo[i]->RSSI_Ave < RSSI_Min)
  1561. {
  1562. RSSI_Min = pDM_Odm->pODM_StaInfo[i]->RSSI_Ave;
  1563. }
  1564. }
  1565. }
  1566. pDM_Odm->RSSI_Min = RSSI_Min;
  1567. }
  1568. VOID
  1569. odm_IsLinked(
  1570. IN PDM_ODM_T pDM_Odm
  1571. )
  1572. {
  1573. u4Byte i;
  1574. BOOLEAN Linked = FALSE;
  1575. for(i=0; i<ODM_ASSOCIATE_ENTRY_NUM; i++)
  1576. {
  1577. if(IS_STA_VALID(pDM_Odm->pODM_StaInfo[i]) )
  1578. {
  1579. Linked = TRUE;
  1580. break;
  1581. }
  1582. }
  1583. pDM_Odm->bLinked = Linked;
  1584. }
  1585. */
  1586. //3============================================================
  1587. //3 DIG
  1588. //3============================================================
  1589. /*-----------------------------------------------------------------------------
  1590. * Function: odm_DIGInit()
  1591. *
  1592. * Overview: Set DIG scheme init value.
  1593. *
  1594. * Input: NONE
  1595. *
  1596. * Output: NONE
  1597. *
  1598. * Return: NONE
  1599. *
  1600. * Revised History:
  1601. * When Who Remark
  1602. *
  1603. *---------------------------------------------------------------------------*/
  1604. VOID
  1605. ODM_ChangeDynamicInitGainThresh(
  1606. IN PDM_ODM_T pDM_Odm,
  1607. IN u4Byte DM_Type,
  1608. IN u4Byte DM_Value
  1609. )
  1610. {
  1611. pDIG_T pDM_DigTable = &pDM_Odm->DM_DigTable;
  1612. if (DM_Type == DIG_TYPE_THRESH_HIGH)
  1613. {
  1614. pDM_DigTable->RssiHighThresh = DM_Value;
  1615. }
  1616. else if (DM_Type == DIG_TYPE_THRESH_LOW)
  1617. {
  1618. pDM_DigTable->RssiLowThresh = DM_Value;
  1619. }
  1620. else if (DM_Type == DIG_TYPE_ENABLE)
  1621. {
  1622. pDM_DigTable->Dig_Enable_Flag = TRUE;
  1623. }
  1624. else if (DM_Type == DIG_TYPE_DISABLE)
  1625. {
  1626. pDM_DigTable->Dig_Enable_Flag = FALSE;
  1627. }
  1628. else if (DM_Type == DIG_TYPE_BACKOFF)
  1629. {
  1630. if(DM_Value > 30)
  1631. DM_Value = 30;
  1632. pDM_DigTable->BackoffVal = (u1Byte)DM_Value;
  1633. }
  1634. else if(DM_Type == DIG_TYPE_RX_GAIN_MIN)
  1635. {
  1636. if(DM_Value == 0)
  1637. DM_Value = 0x1;
  1638. pDM_DigTable->rx_gain_range_min = (u1Byte)DM_Value;
  1639. }
  1640. else if(DM_Type == DIG_TYPE_RX_GAIN_MAX)
  1641. {
  1642. if(DM_Value > 0x50)
  1643. DM_Value = 0x50;
  1644. pDM_DigTable->rx_gain_range_max = (u1Byte)DM_Value;
  1645. }
  1646. } /* DM_ChangeDynamicInitGainThresh */
  1647. int getIGIForDiff(int value_IGI)
  1648. {
  1649. #define ONERCCA_LOW_TH 0x30
  1650. #define ONERCCA_LOW_DIFF 8
  1651. if (value_IGI < ONERCCA_LOW_TH) {
  1652. if ((ONERCCA_LOW_TH - value_IGI) < ONERCCA_LOW_DIFF)
  1653. return ONERCCA_LOW_TH;
  1654. else
  1655. return value_IGI + ONERCCA_LOW_DIFF;
  1656. } else {
  1657. return value_IGI;
  1658. }
  1659. }
  1660. VOID
  1661. odm_AdaptivityInit(
  1662. IN PDM_ODM_T pDM_Odm
  1663. )
  1664. {
  1665. PADAPTER pAdapter = pDM_Odm->Adapter;
  1666. if(IS_HARDWARE_TYPE_8723B(pAdapter))
  1667. {
  1668. pDM_Odm->TH_H = 0xf8; //-8dB
  1669. pDM_Odm->TH_L = 0xfb; //-5dB
  1670. }
  1671. else if(IS_HARDWARE_TYPE_8192EE(pAdapter))
  1672. {
  1673. pDM_Odm->TH_H = 0xf0; //-16dB
  1674. pDM_Odm->TH_L = 0xf3; //-13dB
  1675. }
  1676. else
  1677. {
  1678. pDM_Odm->TH_H = 0xfa; //-6dB
  1679. pDM_Odm->TH_L = 0xfd; //-3dB
  1680. }
  1681. pDM_Odm->IGI_Base = 0x32;
  1682. pDM_Odm->IGI_target = 0x1c;
  1683. pDM_Odm->ForceEDCCA = 0;
  1684. pDM_Odm->AdapEn_RSSI = 32;//45;
  1685. }
  1686. // Add by Neil Chen to enable edcca to MP Platform
  1687. #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
  1688. VOID
  1689. odm_EnableEDCCA(
  1690. IN PDM_ODM_T pDM_Odm
  1691. )
  1692. {
  1693. // This should be moved out of OUTSRC
  1694. PADAPTER pAdapter = pDM_Odm->Adapter;
  1695. // Enable EDCCA. The value is suggested by SD3 Wilson.
  1696. //
  1697. // Revised for ASUS 11b/g performance issues, suggested by BB Neil, 2012.04.13.
  1698. //
  1699. if((pDM_Odm->SupportICType == ODM_RTL8723A)&&(IS_WIRELESS_MODE_G(pAdapter)))
  1700. {
  1701. //PlatformEFIOWrite1Byte(Adapter, rOFDM0_ECCAThreshold, 0x00);
  1702. ODM_Write1Byte(pDM_Odm,rOFDM0_ECCAThreshold,0x00);
  1703. ODM_Write1Byte(pDM_Odm,rOFDM0_ECCAThreshold+2,0xFD);
  1704. }
  1705. else
  1706. {
  1707. //PlatformEFIOWrite1Byte(Adapter, rOFDM0_ECCAThreshold, 0x03);
  1708. ODM_Write1Byte(pDM_Odm,rOFDM0_ECCAThreshold,0x03);
  1709. ODM_Write1Byte(pDM_Odm,rOFDM0_ECCAThreshold+2,0x00);
  1710. }
  1711. //PlatformEFIOWrite1Byte(Adapter, rOFDM0_ECCAThreshold+2, 0x00);
  1712. }
  1713. VOID
  1714. odm_DisableEDCCA(
  1715. IN PDM_ODM_T pDM_Odm
  1716. )
  1717. {
  1718. // Disable EDCCA..
  1719. ODM_Write1Byte(pDM_Odm, rOFDM0_ECCAThreshold, 0x7f);
  1720. ODM_Write1Byte(pDM_Odm, rOFDM0_ECCAThreshold+2, 0x7f);
  1721. }
  1722. //
  1723. // Description: According to initial gain value to determine to enable or disable EDCCA.
  1724. //
  1725. // Suggested by SD3 Wilson. Added by tynli. 2011.11.25.
  1726. //
  1727. VOID
  1728. odm_DynamicEDCCA(
  1729. IN PDM_ODM_T pDM_Odm
  1730. )
  1731. {
  1732. PADAPTER pAdapter = pDM_Odm->Adapter;
  1733. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(pAdapter);
  1734. u1Byte RegC50, RegC58;
  1735. BOOLEAN bFwCurrentInPSMode=FALSE;
  1736. pAdapter->HalFunc.GetHwRegHandler(pAdapter, HW_VAR_FW_PSMODE_STATUS, (pu1Byte)(&bFwCurrentInPSMode));
  1737. // Disable EDCCA mode while under LPS mode, added by Roger, 2012.09.14.
  1738. if(bFwCurrentInPSMode)
  1739. return;
  1740. RegC50 = (u1Byte)ODM_GetBBReg(pDM_Odm, rOFDM0_XAAGCCore1, bMaskByte0);
  1741. RegC58 = (u1Byte)ODM_GetBBReg(pDM_Odm, rOFDM0_XBAGCCore1, bMaskByte0);
  1742. if((RegC50 > 0x28 && RegC58 > 0x28) ||
  1743. ((pDM_Odm->SupportICType == ODM_RTL8723A && IS_WIRELESS_MODE_G(pAdapter) && RegC50>0x26)) ||
  1744. (pDM_Odm->SupportICType == ODM_RTL8188E && RegC50 > 0x28))
  1745. {
  1746. if(!pHalData->bPreEdccaEnable)
  1747. {
  1748. odm_EnableEDCCA(pDM_Odm);
  1749. pHalData->bPreEdccaEnable = TRUE;
  1750. }
  1751. }
  1752. else if((RegC50 < 0x25 && RegC58 < 0x25) || (pDM_Odm->SupportICType == ODM_RTL8188E && RegC50 < 0x25))
  1753. {
  1754. if(pHalData->bPreEdccaEnable)
  1755. {
  1756. odm_DisableEDCCA(pDM_Odm);
  1757. pHalData->bPreEdccaEnable = FALSE;
  1758. }
  1759. }
  1760. }
  1761. #endif // end MP platform support
  1762. VOID
  1763. odm_DynamicATCSwitch_init(
  1764. IN PDM_ODM_T pDM_Odm
  1765. )
  1766. {
  1767. PADAPTER Adapter = pDM_Odm->Adapter;
  1768. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  1769. #if (DM_ODM_SUPPORT_TYPE == ODM_WIN )
  1770. pDM_Odm->CrystalCap = pHalData->CrystalCap;
  1771. pDM_Odm->bATCStatus = (u1Byte)ODM_GetBBReg(pDM_Odm, rOFDM1_CFOTracking, BIT11);
  1772. pDM_Odm->CFOThreshold = CFO_Threshold_Xtal;
  1773. #endif
  1774. }
  1775. VOID
  1776. odm_DynamicATCSwitch(
  1777. IN PDM_ODM_T pDM_Odm
  1778. )
  1779. {
  1780. PADAPTER Adapter = pDM_Odm->Adapter;
  1781. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  1782. u1Byte CrystalCap,ATC_status_temp = 0;
  1783. u4Byte packet_count;
  1784. int CFO_kHz_A,CFO_kHz_B,CFO_ave = 0, Adjust_Xtal = 0;
  1785. int CFO_ave_diff;
  1786. #if (DM_ODM_SUPPORT_TYPE == ODM_WIN )
  1787. if(!(pDM_Odm->SupportAbility & ODM_BB_DYNAMIC_ATC))
  1788. return;
  1789. ODM_RT_TRACE(pDM_Odm, ODM_COMP_DYNAMIC_ATC, ODM_DBG_LOUD, ("=========> odm_DynamicATCSwitch()\n"));
  1790. //2 No link!
  1791. //
  1792. if(!pDM_Odm->bLinked)
  1793. {
  1794. //3
  1795. //3 1.Enable ATC
  1796. if(pDM_Odm->bATCStatus == ATC_Status_Off)
  1797. {
  1798. if(pDM_Odm->SupportICType & ODM_IC_11N_SERIES)
  1799. ODM_SetBBReg(pDM_Odm, rOFDM1_CFOTracking, BIT11, ATC_Status_On);
  1800. if(pDM_Odm->SupportICType & ODM_IC_11AC_SERIES)
  1801. ODM_SetBBReg(pDM_Odm, rFc_area_Jaguar, BIT14, ATC_Status_On);
  1802. pDM_Odm->bATCStatus = ATC_Status_On;
  1803. }
  1804. ODM_RT_TRACE(pDM_Odm, ODM_COMP_DYNAMIC_ATC, ODM_DBG_LOUD, ("odm_DynamicATCSwitch(): No link!!\n"));
  1805. ODM_RT_TRACE(pDM_Odm, ODM_COMP_DYNAMIC_ATC, ODM_DBG_LOUD, ("odm_DynamicATCSwitch(): ATCStatus = %d\n", pDM_Odm->bATCStatus));
  1806. //3 2.Disable CFO tracking for BT
  1807. if(!pDM_Odm->bBtDisabled)
  1808. {
  1809. ODM_RT_TRACE(pDM_Odm, ODM_COMP_DYNAMIC_ATC, ODM_DBG_LOUD, ("odm_DynamicATCSwitch(): Disable CFO tracking for BT!!\n"));
  1810. return;
  1811. }
  1812. //3 3.Reset Crystal Cap.
  1813. if(pDM_Odm->CrystalCap != pHalData->CrystalCap)
  1814. {
  1815. pDM_Odm->CrystalCap = pHalData->CrystalCap;
  1816. CrystalCap = pDM_Odm->CrystalCap & 0x3f;
  1817. odm_Write_CrystalCap(pDM_Odm,CrystalCap);
  1818. }
  1819. ODM_RT_TRACE(pDM_Odm, ODM_COMP_DYNAMIC_ATC, ODM_DBG_LOUD, ("odm_DynamicATCSwitch(): CrystalCap = 0x%x\n", pDM_Odm->CrystalCap));
  1820. }
  1821. else
  1822. {
  1823. //2 Initialization
  1824. //
  1825. //3 1. Calculate CFO for path-A & path-B
  1826. CFO_kHz_A = (int)(pDM_Odm->CFO_tail[0] * 3125) / 1280;
  1827. CFO_kHz_B = (int)(pDM_Odm->CFO_tail[1] * 3125) / 1280;
  1828. packet_count = pDM_Odm->packetCount;
  1829. //3 2.No new packet
  1830. if(packet_count == pDM_Odm->packetCount_pre)
  1831. {
  1832. ODM_RT_TRACE(pDM_Odm, ODM_COMP_DYNAMIC_ATC, ODM_DBG_LOUD, ("odm_DynamicATCSwitch(): packet counter doesn't change\n"));
  1833. return;
  1834. }
  1835. pDM_Odm->packetCount_pre = packet_count;
  1836. ODM_RT_TRACE(pDM_Odm, ODM_COMP_DYNAMIC_ATC, ODM_DBG_LOUD, ("odm_DynamicATCSwitch(): packet counter = %d\n", pDM_Odm->packetCount));
  1837. //3 3.Average CFO
  1838. if(pDM_Odm->RFType == ODM_1T1R)
  1839. CFO_ave = CFO_kHz_A;
  1840. else
  1841. CFO_ave = (int)(CFO_kHz_A + CFO_kHz_B) >> 1;
  1842. ODM_RT_TRACE(pDM_Odm, ODM_COMP_DYNAMIC_ATC, ODM_DBG_LOUD, ("odm_DynamicATCSwitch(): CFO_kHz_A = %dkHz, CFO_kHz_B = %dkHz, CFO_ave = %dkHz\n",
  1843. CFO_kHz_A, CFO_kHz_B, CFO_ave));
  1844. //3 4.Avoid abnormal large CFO
  1845. CFO_ave_diff = (pDM_Odm->CFO_ave_pre >= CFO_ave)?(pDM_Odm->CFO_ave_pre - CFO_ave):(CFO_ave - pDM_Odm->CFO_ave_pre);
  1846. if(CFO_ave_diff > 20 && pDM_Odm->largeCFOHit == 0)
  1847. {
  1848. ODM_RT_TRACE(pDM_Odm, ODM_COMP_DYNAMIC_ATC, ODM_DBG_LOUD, ("odm_DynamicATCSwitch(): first large CFO hit\n"));
  1849. pDM_Odm->largeCFOHit = 1;
  1850. return;
  1851. }
  1852. else
  1853. pDM_Odm->largeCFOHit = 0;
  1854. pDM_Odm->CFO_ave_pre = CFO_ave;
  1855. //2 CFO tracking by adjusting Xtal cap.
  1856. //
  1857. if (pDM_Odm->bBtDisabled)
  1858. {
  1859. //3 1.Dynamic Xtal threshold
  1860. if(CFO_ave >= -pDM_Odm->CFOThreshold && CFO_ave <= pDM_Odm->CFOThreshold && pDM_Odm->bIsfreeze == 0)
  1861. {
  1862. if (pDM_Odm->CFOThreshold == CFO_Threshold_Xtal)
  1863. {
  1864. pDM_Odm->CFOThreshold = CFO_Threshold_Xtal + 10;
  1865. pDM_Odm->bIsfreeze = 1;
  1866. }
  1867. else
  1868. pDM_Odm->CFOThreshold = CFO_Threshold_Xtal;
  1869. }
  1870. ODM_RT_TRACE(pDM_Odm, ODM_COMP_DYNAMIC_ATC, ODM_DBG_LOUD, ("odm_DynamicATCSwitch(): Dynamic threshold = %d\n", pDM_Odm->CFOThreshold));
  1871. //3 2.Calculate Xtal offset
  1872. if(CFO_ave > pDM_Odm->CFOThreshold && pDM_Odm->CrystalCap < 0x3f)
  1873. Adjust_Xtal = ((CFO_ave - CFO_Threshold_Xtal) >> 2) + 1;
  1874. else if(CFO_ave < (-pDM_Odm->CFOThreshold) && pDM_Odm->CrystalCap > 0)
  1875. Adjust_Xtal = ((CFO_ave + CFO_Threshold_Xtal) >> 2) - 1;
  1876. ODM_RT_TRACE(pDM_Odm, ODM_COMP_DYNAMIC_ATC, ODM_DBG_LOUD, ("odm_DynamicATCSwitch(): Crystal cap = 0x%x, Crystal cap offset = %d\n", pDM_Odm->CrystalCap, Adjust_Xtal));
  1877. //3 3.Adjudt Crystal Cap.
  1878. if(Adjust_Xtal != 0)
  1879. {
  1880. pDM_Odm->bIsfreeze = 0;
  1881. pDM_Odm->CrystalCap = pDM_Odm->CrystalCap + Adjust_Xtal;
  1882. if(pDM_Odm->CrystalCap > 0x3f)
  1883. pDM_Odm->CrystalCap = 0x3f;
  1884. else if (pDM_Odm->CrystalCap < 0)
  1885. pDM_Odm->CrystalCap = 0;
  1886. CrystalCap = pDM_Odm->CrystalCap & 0x3f;
  1887. odm_Write_CrystalCap(pDM_Odm,CrystalCap);
  1888. ODM_RT_TRACE(pDM_Odm, ODM_COMP_DYNAMIC_ATC, ODM_DBG_LOUD, ("odm_DynamicATCSwitch(): New crystal cap = 0x%x \n", pDM_Odm->CrystalCap));
  1889. }
  1890. }
  1891. else if(pDM_Odm->CrystalCap != pHalData->CrystalCap)
  1892. {
  1893. //3 Reset Xtal Cap when BT is enable
  1894. pDM_Odm->CrystalCap = pHalData->CrystalCap;
  1895. CrystalCap = pDM_Odm->CrystalCap & 0x3f;
  1896. odm_Write_CrystalCap(pDM_Odm,CrystalCap);
  1897. ODM_RT_TRACE(pDM_Odm, ODM_COMP_DYNAMIC_ATC, ODM_DBG_LOUD, ("odm_DynamicATCSwitch(): Disable CFO tracking for BT!!\n"));
  1898. }
  1899. else
  1900. ODM_RT_TRACE(pDM_Odm, ODM_COMP_DYNAMIC_ATC, ODM_DBG_LOUD, ("odm_DynamicATCSwitch(): Disable CFO tracking for BT!!\n"));
  1901. if(pDM_Odm->SupportICType & ODM_IC_11N_SERIES){
  1902. //2 Dynamic ATC switch
  1903. //
  1904. //3 1.Enable ATC when CFO is larger then 80kHz
  1905. if(CFO_ave < CFO_Threshold_ATC && CFO_ave > -CFO_Threshold_ATC)
  1906. {
  1907. if(pDM_Odm->bATCStatus == ATC_Status_On)
  1908. {
  1909. ODM_SetBBReg(pDM_Odm, rOFDM1_CFOTracking, BIT11, ATC_Status_Off);
  1910. pDM_Odm->bATCStatus = ATC_Status_Off;
  1911. }
  1912. ODM_RT_TRACE(pDM_Odm, ODM_COMP_DYNAMIC_ATC, ODM_DBG_LOUD, ("odm_DynamicATCSwitch(): Disable ATC!!\n"));
  1913. }
  1914. else
  1915. {
  1916. if(pDM_Odm->bATCStatus == ATC_Status_Off)
  1917. {
  1918. ODM_SetBBReg(pDM_Odm, rOFDM1_CFOTracking, BIT11, ATC_Status_On);
  1919. pDM_Odm->bATCStatus = ATC_Status_On;
  1920. }
  1921. ODM_RT_TRACE(pDM_Odm, ODM_COMP_DYNAMIC_ATC, ODM_DBG_LOUD, ("odm_DynamicATCSwitch(): Enable ATC!!\n"));
  1922. }
  1923. }
  1924. }
  1925. #endif
  1926. }
  1927. VOID
  1928. odm_Write_CrystalCap(
  1929. IN PDM_ODM_T pDM_Odm,
  1930. IN u1Byte CrystalCap
  1931. )
  1932. {
  1933. PADAPTER Adapter = pDM_Odm->Adapter;
  1934. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  1935. if(IS_HARDWARE_TYPE_8192D(Adapter))
  1936. {
  1937. PHY_SetBBReg(Adapter, 0x24, 0xF0, CrystalCap & 0x0F);
  1938. PHY_SetBBReg(Adapter, 0x28, 0xF0000000, ((CrystalCap & 0xF0) >> 4));
  1939. }
  1940. if(IS_HARDWARE_TYPE_8188E(Adapter))
  1941. {
  1942. // write 0x24[16:11] = 0x24[22:17] = CrystalCap
  1943. PHY_SetBBReg(Adapter, REG_AFE_XTAL_CTRL, 0x7ff800, (CrystalCap | (CrystalCap << 6)));
  1944. }
  1945. if(IS_HARDWARE_TYPE_8812(Adapter))
  1946. {
  1947. // write 0x2C[30:25] = 0x2C[24:19] = CrystalCap
  1948. CrystalCap = CrystalCap & 0x3F;
  1949. PHY_SetBBReg(Adapter, REG_MAC_PHY_CTRL, 0x7FF80000, (CrystalCap | (CrystalCap << 6)));
  1950. }
  1951. //only for B-cut
  1952. if ((IS_HARDWARE_TYPE_8723A(Adapter) && pHalData->EEPROMVersion >= 0x01) ||
  1953. IS_HARDWARE_TYPE_8723B(Adapter) ||IS_HARDWARE_TYPE_8192E(Adapter) || IS_HARDWARE_TYPE_8821(Adapter))
  1954. {
  1955. // 0x2C[23:18] = 0x2C[17:12] = CrystalCap
  1956. CrystalCap = CrystalCap & 0x3F;
  1957. PHY_SetBBReg(Adapter, REG_MAC_PHY_CTRL, 0xFFF000, (CrystalCap | (CrystalCap << 6)));
  1958. }
  1959. if(IS_HARDWARE_TYPE_8723AE(Adapter))
  1960. PHY_SetBBReg(Adapter, REG_LDOA15_CTRL, bMaskDWord, 0x01572505);
  1961. }
  1962. VOID
  1963. odm_Adaptivity(
  1964. IN PDM_ODM_T pDM_Odm,
  1965. IN u1Byte IGI
  1966. )
  1967. {
  1968. s4Byte TH_H_dmc, TH_L_dmc;
  1969. s4Byte TH_H, TH_L, Diff, IGI_target;
  1970. u4Byte value32;
  1971. BOOLEAN EDCCA_State;
  1972. #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
  1973. PADAPTER pAdapter = pDM_Odm->Adapter;
  1974. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(pAdapter);
  1975. BOOLEAN bFwCurrentInPSMode=FALSE;
  1976. PMGNT_INFO pMgntInfo = &(pAdapter->MgntInfo);
  1977. pAdapter->HalFunc.GetHwRegHandler(pAdapter, HW_VAR_FW_PSMODE_STATUS, (pu1Byte)(&bFwCurrentInPSMode));
  1978. // Disable EDCCA mode while under LPS mode, added by Roger, 2012.09.14.
  1979. if(bFwCurrentInPSMode)
  1980. return;
  1981. #endif
  1982. if(!(pDM_Odm->SupportAbility & ODM_BB_ADAPTIVITY))
  1983. {
  1984. ODM_RT_TRACE(pDM_Odm,ODM_COMP_DIG, ODM_DBG_LOUD, ("Go to odm_DynamicEDCCA() \n"));
  1985. // Add by Neil Chen to enable edcca to MP Platform
  1986. #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
  1987. // Adjust EDCCA.
  1988. if(pDM_Odm->SupportICType & ODM_IC_11N_SERIES)
  1989. odm_DynamicEDCCA(pDM_Odm);
  1990. #endif
  1991. return;
  1992. }
  1993. ODM_RT_TRACE(pDM_Odm,ODM_COMP_DIG, ODM_DBG_LOUD, ("odm_Adaptivity() =====> \n"));
  1994. if(pDM_Odm->bForceThresh)
  1995. {
  1996. pDM_Odm->TH_H = pDM_Odm->Force_TH_H;
  1997. pDM_Odm->TH_L = pDM_Odm->Force_TH_L;
  1998. }
  1999. else
  2000. {
  2001. if(pDM_Odm->SupportICType & ODM_IC_11AC_SERIES)
  2002. {
  2003. if(*pDM_Odm->pBandType == BAND_ON_5G)
  2004. {
  2005. pDM_Odm->TH_H = 0xf4;//0xf8;
  2006. pDM_Odm->TH_L = 0xf7;//0xfb;
  2007. }
  2008. else
  2009. {
  2010. pDM_Odm->TH_H = 0xf4;//0xfa;
  2011. pDM_Odm->TH_L = 0xf7;//0xfd;
  2012. }
  2013. }
  2014. }
  2015. ODM_RT_TRACE(pDM_Odm,ODM_COMP_DIG, ODM_DBG_LOUD, ("pDM_Odm->ForceEDCCA=%d, IGI_Base=0x%x, TH_H=0x%x, TH_L=0x%x, AdapEn_RSSI = %d\n",
  2016. pDM_Odm->ForceEDCCA, pDM_Odm->IGI_Base, pDM_Odm->TH_H, pDM_Odm->TH_L, pDM_Odm->AdapEn_RSSI));
  2017. if(pDM_Odm->SupportICType & ODM_IC_11AC_SERIES)
  2018. ODM_SetBBReg(pDM_Odm, 0x800, BIT10, 0); //ADC_mask enable
  2019. if(!pDM_Odm->bLinked)
  2020. {
  2021. return;
  2022. }
  2023. if(!pDM_Odm->ForceEDCCA)
  2024. {
  2025. if(pDM_Odm->RSSI_Min > pDM_Odm->AdapEn_RSSI)
  2026. EDCCA_State = 1;
  2027. else if(pDM_Odm->RSSI_Min < (pDM_Odm->AdapEn_RSSI - 5))
  2028. EDCCA_State = 0;
  2029. }
  2030. else
  2031. EDCCA_State = 1;
  2032. //if((pDM_Odm->SupportICType & ODM_IC_11AC_SERIES) && (*pDM_Odm->pBandType == BAND_ON_5G))
  2033. //IGI_target = pDM_Odm->IGI_Base;
  2034. //else
  2035. {
  2036. if(*pDM_Odm->pBandWidth == ODM_BW20M) //CHANNEL_WIDTH_20
  2037. IGI_target = pDM_Odm->IGI_Base;
  2038. else if(*pDM_Odm->pBandWidth == ODM_BW40M)
  2039. IGI_target = pDM_Odm->IGI_Base + 2;
  2040. else if(*pDM_Odm->pBandWidth == ODM_BW80M)
  2041. IGI_target = pDM_Odm->IGI_Base + 6;
  2042. else
  2043. IGI_target = pDM_Odm->IGI_Base;
  2044. }
  2045. pDM_Odm->IGI_target = IGI_target;
  2046. if(pDM_Odm->TH_H & BIT7)
  2047. TH_H = pDM_Odm->TH_H | 0xFFFFFF00;
  2048. else
  2049. TH_H = pDM_Odm->TH_H;
  2050. if(pDM_Odm->TH_L & BIT7)
  2051. TH_L = pDM_Odm->TH_L | 0xFFFFFF00;
  2052. else
  2053. TH_L = pDM_Odm->TH_L;
  2054. ODM_RT_TRACE(pDM_Odm,ODM_COMP_DIG, ODM_DBG_LOUD, ("BandWidth=%s, IGI_target=0x%x, EDCCA_State=%d\n",
  2055. (*pDM_Odm->pBandWidth==ODM_BW80M)?"80M":((*pDM_Odm->pBandWidth==ODM_BW40M)?"40M":"20M"), IGI_target, EDCCA_State));
  2056. if(EDCCA_State == 1)
  2057. {
  2058. if(IGI < IGI_target)
  2059. {
  2060. Diff = IGI_target -(s4Byte)IGI;
  2061. TH_H_dmc = TH_H + Diff;
  2062. if(TH_H_dmc > 10)
  2063. TH_H_dmc = 10;
  2064. TH_L_dmc = TH_L + Diff;
  2065. if(TH_L_dmc > 10)
  2066. TH_L_dmc = 10;
  2067. }
  2068. else
  2069. {
  2070. Diff = (s4Byte)IGI - IGI_target;
  2071. TH_H_dmc = TH_H - Diff;
  2072. TH_L_dmc = TH_L - Diff;
  2073. }
  2074. TH_H_dmc = (TH_H_dmc & 0xFF);
  2075. TH_L_dmc = (TH_L_dmc & 0xFF);
  2076. }
  2077. else
  2078. {
  2079. TH_H_dmc = 0x7f;
  2080. TH_L_dmc = 0x7f;
  2081. }
  2082. ODM_RT_TRACE(pDM_Odm,ODM_COMP_DIG, ODM_DBG_LOUD, ("IGI=0x%x, TH_H_dmc=0x%x, TH_L_dmc=0x%x\n",
  2083. IGI, TH_H_dmc, TH_L_dmc));
  2084. if(pDM_Odm->SupportICType & ODM_IC_11N_SERIES)
  2085. {
  2086. ODM_SetBBReg(pDM_Odm,rOFDM0_ECCAThreshold, bMaskByte0, TH_L_dmc);
  2087. ODM_SetBBReg(pDM_Odm,rOFDM0_ECCAThreshold, bMaskByte2, TH_H_dmc);
  2088. }
  2089. else
  2090. ODM_SetBBReg(pDM_Odm, rFPGA0_XB_LSSIReadBack, 0xFFFF, (TH_H_dmc<<8) | TH_L_dmc);
  2091. }
  2092. VOID
  2093. ODM_Write_DIG(
  2094. IN PDM_ODM_T pDM_Odm,
  2095. IN u1Byte CurrentIGI
  2096. )
  2097. {
  2098. pDIG_T pDM_DigTable = &pDM_Odm->DM_DigTable;
  2099. if(pDM_Odm->StopDIG)
  2100. {
  2101. ODM_RT_TRACE(pDM_Odm,ODM_COMP_DIG, ODM_DBG_LOUD, ("Stop Writing IGI\n"));
  2102. return;
  2103. }
  2104. ODM_RT_TRACE(pDM_Odm,ODM_COMP_DIG, ODM_DBG_LOUD, ("ODM_REG(IGI_A,pDM_Odm)=0x%x, ODM_BIT(IGI,pDM_Odm)=0x%x \n",
  2105. ODM_REG(IGI_A,pDM_Odm),ODM_BIT(IGI,pDM_Odm)));
  2106. if(pDM_DigTable->CurIGValue != CurrentIGI)//if(pDM_DigTable->PreIGValue != CurrentIGI)
  2107. {
  2108. if(pDM_Odm->SupportPlatform & (ODM_CE|ODM_WIN))
  2109. {
  2110. ODM_SetBBReg(pDM_Odm, ODM_REG(IGI_A,pDM_Odm), ODM_BIT(IGI,pDM_Odm), CurrentIGI);
  2111. if(pDM_Odm->RFType != ODM_1T1R)
  2112. ODM_SetBBReg(pDM_Odm, ODM_REG(IGI_B,pDM_Odm), ODM_BIT(IGI,pDM_Odm), CurrentIGI);
  2113. }
  2114. else if(pDM_Odm->SupportPlatform & (ODM_AP|ODM_ADSL))
  2115. {
  2116. switch(*(pDM_Odm->pOnePathCCA))
  2117. {
  2118. case ODM_CCA_2R:
  2119. ODM_SetBBReg(pDM_Odm, ODM_REG(IGI_A,pDM_Odm), ODM_BIT(IGI,pDM_Odm), CurrentIGI);
  2120. if(pDM_Odm->RFType != ODM_1T1R)
  2121. ODM_SetBBReg(pDM_Odm, ODM_REG(IGI_B,pDM_Odm), ODM_BIT(IGI,pDM_Odm), CurrentIGI);
  2122. break;
  2123. case ODM_CCA_1R_A:
  2124. ODM_SetBBReg(pDM_Odm, ODM_REG(IGI_A,pDM_Odm), ODM_BIT(IGI,pDM_Odm), CurrentIGI);
  2125. if(pDM_Odm->RFType != ODM_1T1R)
  2126. ODM_SetBBReg(pDM_Odm, ODM_REG(IGI_B,pDM_Odm), ODM_BIT(IGI,pDM_Odm), getIGIForDiff(CurrentIGI));
  2127. break;
  2128. case ODM_CCA_1R_B:
  2129. ODM_SetBBReg(pDM_Odm, ODM_REG(IGI_A,pDM_Odm), ODM_BIT(IGI,pDM_Odm), getIGIForDiff(CurrentIGI));
  2130. if(pDM_Odm->RFType != ODM_1T1R)
  2131. ODM_SetBBReg(pDM_Odm, ODM_REG(IGI_B,pDM_Odm), ODM_BIT(IGI,pDM_Odm), CurrentIGI);
  2132. break;
  2133. }
  2134. }
  2135. ODM_RT_TRACE(pDM_Odm,ODM_COMP_DIG, ODM_DBG_LOUD, ("CurrentIGI(0x%02x). \n",CurrentIGI));
  2136. //pDM_DigTable->PreIGValue = pDM_DigTable->CurIGValue;
  2137. pDM_DigTable->CurIGValue = CurrentIGI;
  2138. }
  2139. ODM_RT_TRACE(pDM_Odm,ODM_COMP_DIG, ODM_DBG_LOUD, ("ODM_Write_DIG():CurrentIGI=0x%x \n",CurrentIGI));
  2140. }
  2141. VOID
  2142. odm_DIGbyRSSI_LPS(
  2143. IN PDM_ODM_T pDM_Odm
  2144. )
  2145. {
  2146. //PADAPTER pAdapter =pDM_Odm->Adapter;
  2147. //pDIG_T pDM_DigTable = &pDM_Odm->DM_DigTable;
  2148. PFALSE_ALARM_STATISTICS pFalseAlmCnt = &pDM_Odm->FalseAlmCnt;
  2149. #if 0 //and 2.3.5 coding rule
  2150. struct mlme_priv *pmlmepriv = &(pAdapter->mlmepriv);
  2151. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(pAdapter);
  2152. struct dm_priv *pdmpriv = &pHalData->dmpriv;
  2153. #endif
  2154. u1Byte RSSI_Lower=DM_DIG_MIN_NIC; //0x1E or 0x1C
  2155. u1Byte CurrentIGI=pDM_Odm->RSSI_Min;
  2156. CurrentIGI=CurrentIGI+RSSI_OFFSET_DIG;
  2157. //ODM_RT_TRACE(pDM_Odm,ODM_COMP_DIG_LPS, ODM_DBG_LOUD, ("odm_DIG()==>\n"));
  2158. // Using FW PS mode to make IGI
  2159. ODM_RT_TRACE(pDM_Odm,ODM_COMP_DIG, ODM_DBG_LOUD, ("---Neil---odm_DIG is in LPS mode\n"));
  2160. //Adjust by FA in LPS MODE
  2161. if(pFalseAlmCnt->Cnt_all> DM_DIG_FA_TH2_LPS)
  2162. CurrentIGI = CurrentIGI+2;
  2163. else if (pFalseAlmCnt->Cnt_all > DM_DIG_FA_TH1_LPS)
  2164. CurrentIGI = CurrentIGI+1;
  2165. else if(pFalseAlmCnt->Cnt_all < DM_DIG_FA_TH0_LPS)
  2166. CurrentIGI = CurrentIGI-1;
  2167. //Lower bound checking
  2168. //RSSI Lower bound check
  2169. if((pDM_Odm->RSSI_Min-10) > DM_DIG_MIN_NIC)
  2170. RSSI_Lower =(pDM_Odm->RSSI_Min-10);
  2171. else
  2172. RSSI_Lower =DM_DIG_MIN_NIC;
  2173. //Upper and Lower Bound checking
  2174. if(CurrentIGI > DM_DIG_MAX_NIC)
  2175. CurrentIGI=DM_DIG_MAX_NIC;
  2176. else if(CurrentIGI < RSSI_Lower)
  2177. CurrentIGI =RSSI_Lower;
  2178. ODM_Write_DIG(pDM_Odm, CurrentIGI);//ODM_Write_DIG(pDM_Odm, pDM_DigTable->CurIGValue);
  2179. }
  2180. VOID
  2181. odm_DIGInit(
  2182. IN PDM_ODM_T pDM_Odm
  2183. )
  2184. {
  2185. pDIG_T pDM_DigTable = &pDM_Odm->DM_DigTable;
  2186. //pDM_DigTable->Dig_Enable_Flag = TRUE;
  2187. //pDM_DigTable->Dig_Ext_Port_Stage = DIG_EXT_PORT_STAGE_MAX;
  2188. pDM_DigTable->CurIGValue = (u1Byte) ODM_GetBBReg(pDM_Odm, ODM_REG(IGI_A,pDM_Odm), ODM_BIT(IGI,pDM_Odm));
  2189. //pDM_DigTable->PreIGValue = 0x0;
  2190. //pDM_DigTable->CurSTAConnectState = pDM_DigTable->PreSTAConnectState = DIG_STA_DISCONNECT;
  2191. //pDM_DigTable->CurMultiSTAConnectState = DIG_MultiSTA_DISCONNECT;
  2192. pDM_DigTable->RssiLowThresh = DM_DIG_THRESH_LOW;
  2193. pDM_DigTable->RssiHighThresh = DM_DIG_THRESH_HIGH;
  2194. pDM_DigTable->FALowThresh = DM_FALSEALARM_THRESH_LOW;
  2195. pDM_DigTable->FAHighThresh = DM_FALSEALARM_THRESH_HIGH;
  2196. if(pDM_Odm->BoardType & (ODM_BOARD_EXT_PA|ODM_BOARD_EXT_LNA))
  2197. {
  2198. pDM_DigTable->rx_gain_range_max = DM_DIG_MAX_NIC;
  2199. pDM_DigTable->rx_gain_range_min = DM_DIG_MIN_NIC;
  2200. }
  2201. else
  2202. {
  2203. pDM_DigTable->rx_gain_range_max = DM_DIG_MAX_NIC;
  2204. pDM_DigTable->rx_gain_range_min = DM_DIG_MIN_NIC;
  2205. }
  2206. pDM_DigTable->BackoffVal = DM_DIG_BACKOFF_DEFAULT;
  2207. pDM_DigTable->BackoffVal_range_max = DM_DIG_BACKOFF_MAX;
  2208. pDM_DigTable->BackoffVal_range_min = DM_DIG_BACKOFF_MIN;
  2209. pDM_DigTable->PreCCK_CCAThres = 0xFF;
  2210. pDM_DigTable->CurCCK_CCAThres = 0x83;
  2211. pDM_DigTable->ForbiddenIGI = DM_DIG_MIN_NIC;
  2212. pDM_DigTable->LargeFAHit = 0;
  2213. pDM_DigTable->Recover_cnt = 0;
  2214. pDM_DigTable->DIG_Dynamic_MIN_0 = DM_DIG_MIN_NIC;
  2215. pDM_DigTable->DIG_Dynamic_MIN_1 = DM_DIG_MIN_NIC;
  2216. pDM_DigTable->bMediaConnect_0 = FALSE;
  2217. pDM_DigTable->bMediaConnect_1 = FALSE;
  2218. //To Initialize pDM_Odm->bDMInitialGainEnable == FALSE to avoid DIG error
  2219. pDM_Odm->bDMInitialGainEnable = TRUE;
  2220. //To Initi BT30 IGI
  2221. pDM_DigTable->BT30_CurIGI=0x32;
  2222. }
  2223. VOID
  2224. odm_DigForBtHsMode(
  2225. IN PDM_ODM_T pDM_Odm
  2226. )
  2227. {
  2228. #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
  2229. pDIG_T pDM_DigTable=&pDM_Odm->DM_DigTable;
  2230. u1Byte digForBtHs=0;
  2231. u1Byte digUpBound=0x5a;
  2232. if(pDM_Odm->bBtConnectProcess)
  2233. {
  2234. if(pDM_Odm->SupportICType&(ODM_RTL8723A))
  2235. digForBtHs = 0x28;
  2236. else
  2237. digForBtHs = 0x22;
  2238. }
  2239. else
  2240. {
  2241. //
  2242. // Decide DIG value by BT HS RSSI.
  2243. //
  2244. digForBtHs = pDM_Odm->btHsRssi+4;
  2245. //DIG Bound
  2246. if(pDM_Odm->SupportICType&(ODM_RTL8723A))
  2247. digUpBound = 0x3e;
  2248. if(digForBtHs > digUpBound)
  2249. digForBtHs = digUpBound;
  2250. if(digForBtHs < 0x1c)
  2251. digForBtHs = 0x1c;
  2252. // update Current IGI
  2253. pDM_DigTable->BT30_CurIGI = digForBtHs;
  2254. }
  2255. ODM_RT_TRACE(pDM_Odm,ODM_COMP_DIG, ODM_DBG_LOUD, ("odm_DigForBtHsMode() : set DigValue=0x%x\n", digForBtHs));
  2256. #endif
  2257. }
  2258. VOID
  2259. odm_DIG(
  2260. IN PDM_ODM_T pDM_Odm
  2261. )
  2262. {
  2263. pDIG_T pDM_DigTable = &pDM_Odm->DM_DigTable;
  2264. PFALSE_ALARM_STATISTICS pFalseAlmCnt = &pDM_Odm->FalseAlmCnt;
  2265. pRXHP_T pRX_HP_Table = &pDM_Odm->DM_RXHP_Table;
  2266. u1Byte DIG_Dynamic_MIN;
  2267. u1Byte DIG_MaxOfMin;
  2268. BOOLEAN FirstConnect, FirstDisConnect;
  2269. u1Byte dm_dig_max, dm_dig_min, offset;
  2270. u1Byte CurrentIGI = pDM_DigTable->CurIGValue;
  2271. #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
  2272. // This should be moved out of OUTSRC
  2273. PADAPTER pAdapter = pDM_Odm->Adapter;
  2274. #if OS_WIN_FROM_WIN7(OS_VERSION)
  2275. if(IsAPModeExist( pAdapter) && pAdapter->bInHctTest)
  2276. {
  2277. ODM_RT_TRACE(pDM_Odm,ODM_COMP_DIG, ODM_DBG_LOUD, ("odm_DIG() Return: Is AP mode or In HCT Test \n"));
  2278. return;
  2279. }
  2280. #endif
  2281. /*
  2282. if (pDM_Odm->SupportICType==ODM_RTL8723B)
  2283. return;
  2284. */
  2285. if(pDM_Odm->bBtHsOperation)
  2286. {
  2287. odm_DigForBtHsMode(pDM_Odm);
  2288. }
  2289. if(!(pDM_Odm->SupportICType &(ODM_RTL8723A|ODM_RTL8188E)))
  2290. {
  2291. if(pRX_HP_Table->RXHP_flag == 1)
  2292. {
  2293. ODM_RT_TRACE(pDM_Odm,ODM_COMP_DIG, ODM_DBG_LOUD, ("odm_DIG() Return: In RXHP Operation \n"));
  2294. return;
  2295. }
  2296. }
  2297. #endif
  2298. #if (DM_ODM_SUPPORT_TYPE == ODM_CE)
  2299. #ifdef CONFIG_SPECIAL_SETTING_FOR_FUNAI_TV
  2300. if((pDM_Odm->bLinked) && (pDM_Odm->Adapter->registrypriv.force_igi !=0))
  2301. {
  2302. printk("pDM_Odm->RSSI_Min=%d \n",pDM_Odm->RSSI_Min);
  2303. ODM_Write_DIG(pDM_Odm,pDM_Odm->Adapter->registrypriv.force_igi);
  2304. return;
  2305. }
  2306. #endif
  2307. #endif
  2308. #if (DM_ODM_SUPPORT_TYPE & (ODM_AP|ODM_ADSL))
  2309. prtl8192cd_priv priv = pDM_Odm->priv;
  2310. if (!((priv->up_time > 5) && (priv->up_time % 2)) )
  2311. {
  2312. ODM_RT_TRACE(pDM_Odm,ODM_COMP_DIG, ODM_DBG_LOUD, ("odm_DIG() Return: Not In DIG Operation Period \n"));
  2313. return;
  2314. }
  2315. #endif
  2316. ODM_RT_TRACE(pDM_Odm,ODM_COMP_DIG, ODM_DBG_LOUD, ("odm_DIG()==>\n"));
  2317. //if(!(pDM_Odm->SupportAbility & (ODM_BB_DIG|ODM_BB_FA_CNT)))
  2318. if((!(pDM_Odm->SupportAbility&ODM_BB_DIG)) ||(!(pDM_Odm->SupportAbility&ODM_BB_FA_CNT)))
  2319. {
  2320. #if 0
  2321. if(pDM_Odm->SupportPlatform & (ODM_AP|ODM_ADSL))
  2322. {
  2323. if ((pDM_Odm->SupportICType == ODM_RTL8192C) && (pDM_Odm->ExtLNA == 1))
  2324. CurrentIGI = 0x30; //pDM_DigTable->CurIGValue = 0x30;
  2325. else
  2326. CurrentIGI = 0x20; //pDM_DigTable->CurIGValue = 0x20;
  2327. ODM_Write_DIG(pDM_Odm, CurrentIGI);//ODM_Write_DIG(pDM_Odm, pDM_DigTable->CurIGValue);
  2328. }
  2329. #endif
  2330. ODM_RT_TRACE(pDM_Odm,ODM_COMP_DIG, ODM_DBG_LOUD, ("odm_DIG() Return: SupportAbility ODM_BB_DIG or ODM_BB_FA_CNT is disabled\n"));
  2331. return;
  2332. }
  2333. if(*(pDM_Odm->pbScanInProcess))
  2334. {
  2335. ODM_RT_TRACE(pDM_Odm,ODM_COMP_DIG, ODM_DBG_LOUD, ("odm_DIG() Return: In Scan Progress \n"));
  2336. return;
  2337. }
  2338. //add by Neil Chen to avoid PSD is processing
  2339. if(pDM_Odm->SupportICType==ODM_RTL8723A)
  2340. {
  2341. if(pDM_Odm->bDMInitialGainEnable == FALSE)
  2342. {
  2343. ODM_RT_TRACE(pDM_Odm,ODM_COMP_DIG, ODM_DBG_LOUD, ("odm_DIG() Return: PSD is Processing \n"));
  2344. return;
  2345. }
  2346. }
  2347. if(pDM_Odm->SupportICType == ODM_RTL8192D)
  2348. {
  2349. if(*(pDM_Odm->pMacPhyMode) == ODM_DMSP)
  2350. {
  2351. if(*(pDM_Odm->pbMasterOfDMSP))
  2352. {
  2353. DIG_Dynamic_MIN = pDM_DigTable->DIG_Dynamic_MIN_0;
  2354. FirstConnect = (pDM_Odm->bLinked) && (pDM_DigTable->bMediaConnect_0 == FALSE);
  2355. FirstDisConnect = (!pDM_Odm->bLinked) && (pDM_DigTable->bMediaConnect_0 == TRUE);
  2356. }
  2357. else
  2358. {
  2359. DIG_Dynamic_MIN = pDM_DigTable->DIG_Dynamic_MIN_1;
  2360. FirstConnect = (pDM_Odm->bLinked) && (pDM_DigTable->bMediaConnect_1 == FALSE);
  2361. FirstDisConnect = (!pDM_Odm->bLinked) && (pDM_DigTable->bMediaConnect_1 == TRUE);
  2362. }
  2363. }
  2364. else
  2365. {
  2366. if(*(pDM_Odm->pBandType) == ODM_BAND_5G)
  2367. {
  2368. DIG_Dynamic_MIN = pDM_DigTable->DIG_Dynamic_MIN_0;
  2369. FirstConnect = (pDM_Odm->bLinked) && (pDM_DigTable->bMediaConnect_0 == FALSE);
  2370. FirstDisConnect = (!pDM_Odm->bLinked) && (pDM_DigTable->bMediaConnect_0 == TRUE);
  2371. }
  2372. else
  2373. {
  2374. DIG_Dynamic_MIN = pDM_DigTable->DIG_Dynamic_MIN_1;
  2375. FirstConnect = (pDM_Odm->bLinked) && (pDM_DigTable->bMediaConnect_1 == FALSE);
  2376. FirstDisConnect = (!pDM_Odm->bLinked) && (pDM_DigTable->bMediaConnect_1 == TRUE);
  2377. }
  2378. }
  2379. }
  2380. else
  2381. {
  2382. DIG_Dynamic_MIN = pDM_DigTable->DIG_Dynamic_MIN_0;
  2383. FirstConnect = (pDM_Odm->bLinked) && (pDM_DigTable->bMediaConnect_0 == FALSE);
  2384. FirstDisConnect = (!pDM_Odm->bLinked) && (pDM_DigTable->bMediaConnect_0 == TRUE);
  2385. }
  2386. //1 Boundary Decision
  2387. if(pDM_Odm->SupportICType & (ODM_RTL8192C) &&(pDM_Odm->BoardType & (ODM_BOARD_EXT_LNA | ODM_BOARD_EXT_PA)))
  2388. {
  2389. if(pDM_Odm->SupportPlatform & (ODM_AP|ODM_ADSL))
  2390. {
  2391. dm_dig_max = DM_DIG_MAX_AP_HP;
  2392. dm_dig_min = DM_DIG_MIN_AP_HP;
  2393. }
  2394. else
  2395. {
  2396. dm_dig_max = DM_DIG_MAX_NIC_HP;
  2397. dm_dig_min = DM_DIG_MIN_NIC_HP;
  2398. }
  2399. DIG_MaxOfMin = DM_DIG_MAX_AP_HP;
  2400. }
  2401. else
  2402. {
  2403. if(pDM_Odm->SupportPlatform & (ODM_AP|ODM_ADSL))
  2404. {
  2405. #if (DM_ODM_SUPPORT_TYPE & (ODM_AP|ODM_ADSL))
  2406. #ifdef DFS
  2407. if (!priv->pmib->dot11DFSEntry.disable_DFS &&
  2408. (OPMODE & WIFI_AP_STATE) &&
  2409. (((pDM_Odm->ControlChannel >= 52) &&
  2410. (pDM_Odm->ControlChannel <= 64)) ||
  2411. ((pDM_Odm->ControlChannel >= 100) &&
  2412. (pDM_Odm->ControlChannel <= 140))))
  2413. dm_dig_max = 0x24;
  2414. else
  2415. #endif
  2416. if (priv->pmib->dot11RFEntry.tx2path) {
  2417. if (*(pDM_Odm->pWirelessMode) == ODM_WM_B)//(priv->pmib->dot11BssType.net_work_type == WIRELESS_11B)
  2418. dm_dig_max = 0x2A;
  2419. else
  2420. dm_dig_max = 0x32;
  2421. }
  2422. else
  2423. #endif
  2424. dm_dig_max = DM_DIG_MAX_AP;
  2425. dm_dig_min = DM_DIG_MIN_AP;
  2426. DIG_MaxOfMin = dm_dig_max;
  2427. }
  2428. else
  2429. {
  2430. if((pDM_Odm->SupportICType >= ODM_RTL8188E) && (pDM_Odm->SupportPlatform & (ODM_WIN|ODM_CE)))
  2431. dm_dig_max = 0x5A;
  2432. else
  2433. dm_dig_max = DM_DIG_MAX_NIC;
  2434. if(pDM_Odm->SupportICType != ODM_RTL8821)
  2435. dm_dig_min = DM_DIG_MIN_NIC;
  2436. else
  2437. dm_dig_min = 0x1C;
  2438. DIG_MaxOfMin = DM_DIG_MAX_AP;
  2439. }
  2440. }
  2441. if(pDM_Odm->bLinked)
  2442. {
  2443. if(pDM_Odm->SupportICType&(ODM_RTL8723A/*|ODM_RTL8821*/))
  2444. {
  2445. //2 Upper Bound
  2446. if(( pDM_Odm->RSSI_Min + 10) > DM_DIG_MAX_NIC )
  2447. pDM_DigTable->rx_gain_range_max = DM_DIG_MAX_NIC;
  2448. else if(( pDM_Odm->RSSI_Min + 10) < DM_DIG_MIN_NIC )
  2449. pDM_DigTable->rx_gain_range_max = DM_DIG_MIN_NIC;
  2450. else
  2451. pDM_DigTable->rx_gain_range_max = pDM_Odm->RSSI_Min + 10;
  2452. //BT is Concurrent
  2453. if(pDM_Odm->bBtLimitedDig)
  2454. {
  2455. if(pDM_Odm->RSSI_Min>10)
  2456. {
  2457. if((pDM_Odm->RSSI_Min - 10) > DM_DIG_MAX_NIC)
  2458. DIG_Dynamic_MIN = DM_DIG_MAX_NIC;
  2459. else if((pDM_Odm->RSSI_Min - 10) < DM_DIG_MIN_NIC)
  2460. DIG_Dynamic_MIN = DM_DIG_MIN_NIC;
  2461. else
  2462. DIG_Dynamic_MIN = pDM_Odm->RSSI_Min - 10;
  2463. }
  2464. else
  2465. DIG_Dynamic_MIN=DM_DIG_MIN_NIC;
  2466. }
  2467. else
  2468. {
  2469. if((pDM_Odm->RSSI_Min + 20) > dm_dig_max )
  2470. pDM_DigTable->rx_gain_range_max = dm_dig_max;
  2471. else if((pDM_Odm->RSSI_Min + 20) < dm_dig_min )
  2472. pDM_DigTable->rx_gain_range_max = dm_dig_min;
  2473. else
  2474. pDM_DigTable->rx_gain_range_max = pDM_Odm->RSSI_Min + 20;
  2475. }
  2476. }
  2477. else
  2478. {
  2479. if((pDM_Odm->SupportICType & (ODM_RTL8192E|ODM_RTL8723B|ODM_RTL8812|ODM_RTL8821)) && (pDM_Odm->bBtLimitedDig==1)){
  2480. //2 Modify DIG upper bound for 92E, 8723B, 8821 & 8812 BT
  2481. if((pDM_Odm->RSSI_Min + 10) > dm_dig_max )
  2482. pDM_DigTable->rx_gain_range_max = dm_dig_max;
  2483. else if((pDM_Odm->RSSI_Min + 10) < dm_dig_min )
  2484. pDM_DigTable->rx_gain_range_max = dm_dig_min;
  2485. else
  2486. pDM_DigTable->rx_gain_range_max = pDM_Odm->RSSI_Min + 10;
  2487. }
  2488. else{
  2489. //2 Modify DIG upper bound
  2490. //2013.03.19 Luke: Modified upper bound for Netgear rental house test
  2491. if(pDM_Odm->SupportICType != ODM_RTL8821)
  2492. offset = 20;
  2493. else
  2494. offset = 10;
  2495. if((pDM_Odm->RSSI_Min + offset) > dm_dig_max )
  2496. pDM_DigTable->rx_gain_range_max = dm_dig_max;
  2497. else if((pDM_Odm->RSSI_Min + offset) < dm_dig_min )
  2498. pDM_DigTable->rx_gain_range_max = dm_dig_min;
  2499. else
  2500. pDM_DigTable->rx_gain_range_max = pDM_Odm->RSSI_Min + offset;
  2501. }
  2502. //2 Modify DIG lower bound
  2503. /*
  2504. if((pFalseAlmCnt->Cnt_all > 500)&&(DIG_Dynamic_MIN < 0x25))
  2505. DIG_Dynamic_MIN++;
  2506. else if(((pFalseAlmCnt->Cnt_all < 500)||(pDM_Odm->RSSI_Min < 8))&&(DIG_Dynamic_MIN > dm_dig_min))
  2507. DIG_Dynamic_MIN--;
  2508. */
  2509. if(pDM_Odm->bOneEntryOnly)
  2510. {
  2511. if(pDM_Odm->RSSI_Min < dm_dig_min)
  2512. DIG_Dynamic_MIN = dm_dig_min;
  2513. else if (pDM_Odm->RSSI_Min > DIG_MaxOfMin)
  2514. DIG_Dynamic_MIN = DIG_MaxOfMin;
  2515. else
  2516. DIG_Dynamic_MIN = pDM_Odm->RSSI_Min;
  2517. ODM_RT_TRACE(pDM_Odm,ODM_COMP_DIG, ODM_DBG_LOUD, ("odm_DIG() : bOneEntryOnly=TRUE, DIG_Dynamic_MIN=0x%x\n",DIG_Dynamic_MIN));
  2518. ODM_RT_TRACE(pDM_Odm,ODM_COMP_DIG, ODM_DBG_LOUD, ("odm_DIG() : pDM_Odm->RSSI_Min=%d\n",pDM_Odm->RSSI_Min));
  2519. }
  2520. //1 Lower Bound for 88E AntDiv
  2521. #if (RTL8188E_SUPPORT == 1)
  2522. else if((pDM_Odm->SupportICType == ODM_RTL8188E)&&(pDM_Odm->SupportAbility & ODM_BB_ANT_DIV))
  2523. {
  2524. if((pDM_Odm->AntDivType == CG_TRX_HW_ANTDIV) ||(pDM_Odm->AntDivType == CGCS_RX_HW_ANTDIV))
  2525. {
  2526. DIG_Dynamic_MIN = (u1Byte) pDM_DigTable->AntDiv_RSSI_max;
  2527. ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("odm_DIG(): pDM_DigTable->AntDiv_RSSI_max=%d \n",pDM_DigTable->AntDiv_RSSI_max));
  2528. }
  2529. }
  2530. #endif
  2531. else
  2532. {
  2533. DIG_Dynamic_MIN=dm_dig_min;
  2534. }
  2535. }
  2536. }
  2537. else
  2538. {
  2539. pDM_DigTable->rx_gain_range_max = dm_dig_max;
  2540. DIG_Dynamic_MIN = dm_dig_min;
  2541. ODM_RT_TRACE(pDM_Odm,ODM_COMP_DIG, ODM_DBG_LOUD, ("odm_DIG() : No Link\n"));
  2542. }
  2543. //1 Modify DIG lower bound, deal with abnorally large false alarm
  2544. if(pFalseAlmCnt->Cnt_all > 10000)
  2545. {
  2546. ODM_RT_TRACE(pDM_Odm,ODM_COMP_DIG, ODM_DBG_LOUD, ("dm_DIG(): Abnornally false alarm case. \n"));
  2547. if(pDM_DigTable->LargeFAHit != 3)
  2548. pDM_DigTable->LargeFAHit++;
  2549. if(pDM_DigTable->ForbiddenIGI < CurrentIGI)//if(pDM_DigTable->ForbiddenIGI < pDM_DigTable->CurIGValue)
  2550. {
  2551. pDM_DigTable->ForbiddenIGI = (u1Byte)CurrentIGI;//pDM_DigTable->ForbiddenIGI = pDM_DigTable->CurIGValue;
  2552. pDM_DigTable->LargeFAHit = 1;
  2553. }
  2554. if(pDM_DigTable->LargeFAHit >= 3)
  2555. {
  2556. if((pDM_DigTable->ForbiddenIGI+1) >pDM_DigTable->rx_gain_range_max)
  2557. pDM_DigTable->rx_gain_range_min = pDM_DigTable->rx_gain_range_max;
  2558. else
  2559. pDM_DigTable->rx_gain_range_min = (pDM_DigTable->ForbiddenIGI + 1);
  2560. pDM_DigTable->Recover_cnt = 3600; //3600=2hr
  2561. }
  2562. }
  2563. else
  2564. {
  2565. //Recovery mechanism for IGI lower bound
  2566. if(pDM_DigTable->Recover_cnt != 0)
  2567. pDM_DigTable->Recover_cnt --;
  2568. else
  2569. {
  2570. if(pDM_DigTable->LargeFAHit < 3)
  2571. {
  2572. if((pDM_DigTable->ForbiddenIGI -1) < DIG_Dynamic_MIN) //DM_DIG_MIN)
  2573. {
  2574. pDM_DigTable->ForbiddenIGI = DIG_Dynamic_MIN; //DM_DIG_MIN;
  2575. pDM_DigTable->rx_gain_range_min = DIG_Dynamic_MIN; //DM_DIG_MIN;
  2576. ODM_RT_TRACE(pDM_Odm, ODM_COMP_DIG, ODM_DBG_LOUD, ("odm_DIG(): Normal Case: At Lower Bound\n"));
  2577. }
  2578. else
  2579. {
  2580. pDM_DigTable->ForbiddenIGI --;
  2581. pDM_DigTable->rx_gain_range_min = (pDM_DigTable->ForbiddenIGI + 1);
  2582. ODM_RT_TRACE(pDM_Odm, ODM_COMP_DIG, ODM_DBG_LOUD, ("odm_DIG(): Normal Case: Approach Lower Bound\n"));
  2583. }
  2584. }
  2585. else
  2586. {
  2587. pDM_DigTable->LargeFAHit = 0;
  2588. }
  2589. }
  2590. }
  2591. ODM_RT_TRACE(pDM_Odm, ODM_COMP_DIG, ODM_DBG_LOUD, ("odm_DIG(): pDM_DigTable->LargeFAHit=%d\n",pDM_DigTable->LargeFAHit));
  2592. if((pDM_Odm->SupportPlatform&(ODM_WIN|ODM_CE))&&(pDM_Odm->PhyDbgInfo.NumQryBeaconPkt < 10))
  2593. pDM_DigTable->rx_gain_range_min = dm_dig_min;
  2594. if(pDM_DigTable->rx_gain_range_min > pDM_DigTable->rx_gain_range_max)
  2595. pDM_DigTable->rx_gain_range_min = pDM_DigTable->rx_gain_range_max;
  2596. //1 Adjust initial gain by false alarm
  2597. if(pDM_Odm->bLinked)
  2598. {
  2599. ODM_RT_TRACE(pDM_Odm, ODM_COMP_DIG, ODM_DBG_LOUD, ("odm_DIG(): DIG AfterLink\n"));
  2600. if(FirstConnect)
  2601. {
  2602. if(pDM_Odm->RSSI_Min <= DIG_MaxOfMin)
  2603. CurrentIGI = pDM_Odm->RSSI_Min;
  2604. else
  2605. CurrentIGI = DIG_MaxOfMin;
  2606. ODM_RT_TRACE(pDM_Odm, ODM_COMP_DIG, ODM_DBG_LOUD, ("DIG: First Connect\n"));
  2607. }
  2608. else
  2609. {
  2610. if(pDM_Odm->SupportICType == ODM_RTL8192D)
  2611. {
  2612. if(pFalseAlmCnt->Cnt_all > DM_DIG_FA_TH2_92D)
  2613. CurrentIGI = CurrentIGI + 4;//pDM_DigTable->CurIGValue = pDM_DigTable->PreIGValue+2;
  2614. else if (pFalseAlmCnt->Cnt_all > DM_DIG_FA_TH1_92D)
  2615. CurrentIGI = CurrentIGI + 2; //pDM_DigTable->CurIGValue = pDM_DigTable->PreIGValue+1;
  2616. else if(pFalseAlmCnt->Cnt_all < DM_DIG_FA_TH0_92D)
  2617. CurrentIGI = CurrentIGI - 2;//pDM_DigTable->CurIGValue =pDM_DigTable->PreIGValue-1;
  2618. }
  2619. else
  2620. {
  2621. //FA for Combo IC--NeilChen--2012--09--28
  2622. if(pDM_Odm->SupportICType == ODM_RTL8723A)
  2623. {
  2624. //WLAN and BT ConCurrent
  2625. if(pDM_Odm->bBtLimitedDig)
  2626. {
  2627. if(pFalseAlmCnt->Cnt_all > 0x300)
  2628. CurrentIGI = CurrentIGI + 4;
  2629. else if (pFalseAlmCnt->Cnt_all > 0x250)
  2630. CurrentIGI = CurrentIGI + 2;
  2631. else if(pFalseAlmCnt->Cnt_all < DM_DIG_FA_TH0)
  2632. CurrentIGI = CurrentIGI -2;
  2633. }
  2634. else //Not Concurrent
  2635. {
  2636. if(pFalseAlmCnt->Cnt_all > DM_DIG_FA_TH2)
  2637. CurrentIGI = CurrentIGI + 4;//pDM_DigTable->CurIGValue = pDM_DigTable->PreIGValue+2;
  2638. else if (pFalseAlmCnt->Cnt_all > DM_DIG_FA_TH1)
  2639. CurrentIGI = CurrentIGI + 2;//pDM_DigTable->CurIGValue = pDM_DigTable->PreIGValue+1;
  2640. else if(pFalseAlmCnt->Cnt_all < DM_DIG_FA_TH0)
  2641. CurrentIGI = CurrentIGI - 2;//pDM_DigTable->CurIGValue =pDM_DigTable->PreIGValue-1;
  2642. }
  2643. }
  2644. else
  2645. {
  2646. if(pFalseAlmCnt->Cnt_all > DM_DIG_FA_TH2)
  2647. CurrentIGI = CurrentIGI + 4;//pDM_DigTable->CurIGValue = pDM_DigTable->PreIGValue+2;
  2648. else if (pFalseAlmCnt->Cnt_all > DM_DIG_FA_TH1)
  2649. CurrentIGI = CurrentIGI + 2;//pDM_DigTable->CurIGValue = pDM_DigTable->PreIGValue+1;
  2650. else if(pFalseAlmCnt->Cnt_all < DM_DIG_FA_TH0)
  2651. CurrentIGI = CurrentIGI - 2;//pDM_DigTable->CurIGValue =pDM_DigTable->PreIGValue-1;
  2652. if((pDM_Odm->SupportPlatform&(ODM_WIN|ODM_CE))&&(pDM_Odm->PhyDbgInfo.NumQryBeaconPkt < 10)
  2653. &&(pFalseAlmCnt->Cnt_all < DM_DIG_FA_TH1))
  2654. CurrentIGI = pDM_DigTable->rx_gain_range_min;
  2655. }
  2656. }
  2657. }
  2658. }
  2659. else
  2660. {
  2661. //CurrentIGI = pDM_DigTable->rx_gain_range_min;//pDM_DigTable->CurIGValue = pDM_DigTable->rx_gain_range_min
  2662. ODM_RT_TRACE(pDM_Odm, ODM_COMP_DIG, ODM_DBG_LOUD, ("odm_DIG(): DIG BeforeLink\n"));
  2663. if(FirstDisConnect)
  2664. {
  2665. CurrentIGI = pDM_DigTable->rx_gain_range_min;
  2666. ODM_RT_TRACE(pDM_Odm, ODM_COMP_DIG, ODM_DBG_LOUD, ("odm_DIG(): First DisConnect \n"));
  2667. }
  2668. else
  2669. {
  2670. //2012.03.30 LukeLee: enable DIG before link but with very high thresholds
  2671. if(pFalseAlmCnt->Cnt_all > 10000)
  2672. CurrentIGI = CurrentIGI + 4;
  2673. else if (pFalseAlmCnt->Cnt_all > 8000)
  2674. CurrentIGI = CurrentIGI + 2;
  2675. else if(pFalseAlmCnt->Cnt_all < 500)
  2676. CurrentIGI = CurrentIGI - 2;
  2677. ODM_RT_TRACE(pDM_Odm, ODM_COMP_DIG, ODM_DBG_LOUD, ("odm_DIG(): England DIG \n"));
  2678. }
  2679. }
  2680. ODM_RT_TRACE(pDM_Odm, ODM_COMP_DIG, ODM_DBG_LOUD, ("odm_DIG(): DIG End Adjust IGI\n"));
  2681. //1 Check initial gain by upper/lower bound
  2682. if(CurrentIGI > pDM_DigTable->rx_gain_range_max)
  2683. CurrentIGI = pDM_DigTable->rx_gain_range_max;
  2684. if(CurrentIGI < pDM_DigTable->rx_gain_range_min)
  2685. CurrentIGI = pDM_DigTable->rx_gain_range_min;
  2686. if(pDM_Odm->SupportAbility & ODM_BB_ADAPTIVITY)
  2687. {
  2688. if(CurrentIGI > (pDM_Odm->IGI_target + 4))
  2689. CurrentIGI = (u1Byte)pDM_Odm->IGI_target + 4;
  2690. }
  2691. ODM_RT_TRACE(pDM_Odm, ODM_COMP_DIG, ODM_DBG_LOUD, ("odm_DIG(): rx_gain_range_max=0x%x, rx_gain_range_min=0x%x\n",
  2692. pDM_DigTable->rx_gain_range_max, pDM_DigTable->rx_gain_range_min));
  2693. ODM_RT_TRACE(pDM_Odm, ODM_COMP_DIG, ODM_DBG_LOUD, ("odm_DIG(): TotalFA=%d\n", pFalseAlmCnt->Cnt_all));
  2694. ODM_RT_TRACE(pDM_Odm, ODM_COMP_DIG, ODM_DBG_LOUD, ("odm_DIG(): CurIGValue=0x%x\n", CurrentIGI));
  2695. //2 High power RSSI threshold
  2696. #if (DM_ODM_SUPPORT_TYPE & ODM_WIN)
  2697. {
  2698. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(pDM_Odm->Adapter);
  2699. //PMGNT_INFO pMgntInfo = &(pAdapter->MgntInfo);
  2700. // for LC issue to dymanic modify DIG lower bound----------LC Mocca Issue
  2701. u8Byte curTxOkCnt=0, curRxOkCnt=0;
  2702. static u8Byte lastTxOkCnt=0, lastRxOkCnt=0;
  2703. //u8Byte OKCntAll=0;
  2704. //static u8Byte TXByteCnt_A=0, TXByteCnt_B=0, RXByteCnt_A=0, RXByteCnt_B=0;
  2705. //u8Byte CurByteCnt=0, PreByteCnt=0;
  2706. curTxOkCnt = pAdapter->TxStats.NumTxBytesUnicast - lastTxOkCnt;
  2707. curRxOkCnt =pAdapter->RxStats.NumRxBytesUnicast - lastRxOkCnt;
  2708. lastTxOkCnt = pAdapter->TxStats.NumTxBytesUnicast;
  2709. lastRxOkCnt = pAdapter->RxStats.NumRxBytesUnicast;
  2710. //----------------------------------------------------------end for LC Mocca issue
  2711. if((pDM_Odm->SupportICType == ODM_RTL8723A)&& (pHalData->UndecoratedSmoothedPWDB > DM_DIG_HIGH_PWR_THRESHOLD))
  2712. {
  2713. // High power IGI lower bound
  2714. ODM_RT_TRACE(pDM_Odm, ODM_COMP_DIG, ODM_DBG_LOUD, ("odm_DIG(): UndecoratedSmoothedPWDB(%#x)\n", pHalData->UndecoratedSmoothedPWDB));
  2715. if(CurrentIGI < DM_DIG_HIGH_PWR_IGI_LOWER_BOUND)
  2716. {
  2717. ODM_RT_TRACE(pDM_Odm, ODM_COMP_DIG, ODM_DBG_LOUD, ("odm_DIG(): CurIGValue(%#x)\n", pDM_DigTable->CurIGValue));
  2718. //pDM_DigTable->CurIGValue = DM_DIG_HIGH_PWR_IGI_LOWER_BOUND;
  2719. CurrentIGI=DM_DIG_HIGH_PWR_IGI_LOWER_BOUND;
  2720. }
  2721. }
  2722. if((pDM_Odm->SupportICType & ODM_RTL8723A) &&
  2723. IS_WIRELESS_MODE_G(pAdapter))
  2724. {
  2725. if(pHalData->UndecoratedSmoothedPWDB > 0x28)
  2726. {
  2727. if(CurrentIGI < DM_DIG_Gmode_HIGH_PWR_IGI_LOWER_BOUND)
  2728. {
  2729. //pDM_DigTable->CurIGValue = DM_DIG_Gmode_HIGH_PWR_IGI_LOWER_BOUND;
  2730. CurrentIGI = DM_DIG_Gmode_HIGH_PWR_IGI_LOWER_BOUND;
  2731. }
  2732. }
  2733. }
  2734. #if 0
  2735. if((pDM_Odm->SupportICType & ODM_RTL8723A)&&(pMgntInfo->CustomerID = RT_CID_LENOVO_CHINA))
  2736. {
  2737. OKCntAll = (curTxOkCnt+curRxOkCnt);
  2738. ODM_RT_TRACE(pDM_Odm, ODM_COMP_DIG, ODM_DBG_LOUD, ("odm_DIG(): CurIGValue(%#x)\n", CurrentIGI));
  2739. ODM_RT_TRACE(pDM_Odm, ODM_COMP_DIG, ODM_DBG_LOUD, ("odm_DIG(): UndecoratedSmoothedPWDB(%#x)\n", pHalData->UndecoratedSmoothedPWDB));
  2740. ODM_RT_TRACE(pDM_Odm, ODM_COMP_DIG, ODM_DBG_LOUD, ("odm_DIG(): OKCntAll(%#x)\n", OKCntAll));
  2741. //8723AS_VAU
  2742. if(pDM_Odm->SupportInterface==ODM_ITRF_USB)
  2743. {
  2744. if(pHalData->UndecoratedSmoothedPWDB < 12)
  2745. {
  2746. if(CurrentIGI > DM_DIG_MIN_NIC)
  2747. {
  2748. if(OKCntAll >= 1500000) // >=6Mbps
  2749. CurrentIGI=0x1B;
  2750. else if(OKCntAll >= 1000000) //4Mbps
  2751. CurrentIGI=0x1A;
  2752. else if(OKCntAll >= 500000) //2Mbps
  2753. CurrentIGI=0x19;
  2754. else if(OKCntAll >= 250000) //1Mbps
  2755. CurrentIGI=0x18;
  2756. else
  2757. {
  2758. CurrentIGI=0x17; //SCAN mode
  2759. }
  2760. }
  2761. ODM_RT_TRACE(pDM_Odm, ODM_COMP_DIG, ODM_DBG_LOUD, ("Modify---->CurIGValue(%#x)\n", CurrentIGI));
  2762. }
  2763. }
  2764. }
  2765. #endif
  2766. }
  2767. #endif
  2768. #if (RTL8192D_SUPPORT==1)
  2769. if(pDM_Odm->SupportICType == ODM_RTL8192D)
  2770. {
  2771. //sherry delete DualMacSmartConncurrent 20110517
  2772. if(*(pDM_Odm->pMacPhyMode) == ODM_DMSP)
  2773. {
  2774. ODM_Write_DIG_DMSP(pDM_Odm, (u1Byte)CurrentIGI);//ODM_Write_DIG_DMSP(pDM_Odm, pDM_DigTable->CurIGValue);
  2775. if(*(pDM_Odm->pbMasterOfDMSP))
  2776. {
  2777. pDM_DigTable->bMediaConnect_0 = pDM_Odm->bLinked;
  2778. pDM_DigTable->DIG_Dynamic_MIN_0 = DIG_Dynamic_MIN;
  2779. }
  2780. else
  2781. {
  2782. pDM_DigTable->bMediaConnect_1 = pDM_Odm->bLinked;
  2783. pDM_DigTable->DIG_Dynamic_MIN_1 = DIG_Dynamic_MIN;
  2784. }
  2785. }
  2786. else
  2787. {
  2788. ODM_Write_DIG(pDM_Odm, CurrentIGI);//ODM_Write_DIG(pDM_Odm, pDM_DigTable->CurIGValue);
  2789. if(*(pDM_Odm->pBandType) == ODM_BAND_5G)
  2790. {
  2791. pDM_DigTable->bMediaConnect_0 = pDM_Odm->bLinked;
  2792. pDM_DigTable->DIG_Dynamic_MIN_0 = DIG_Dynamic_MIN;
  2793. }
  2794. else
  2795. {
  2796. pDM_DigTable->bMediaConnect_1 = pDM_Odm->bLinked;
  2797. pDM_DigTable->DIG_Dynamic_MIN_1 = DIG_Dynamic_MIN;
  2798. }
  2799. }
  2800. }
  2801. else
  2802. #endif
  2803. {
  2804. if(pDM_Odm->bBtHsOperation)
  2805. {
  2806. if(pDM_Odm->bLinked)
  2807. {
  2808. if(pDM_DigTable->BT30_CurIGI > (CurrentIGI))
  2809. {
  2810. ODM_Write_DIG(pDM_Odm, CurrentIGI);
  2811. }
  2812. else
  2813. {
  2814. ODM_Write_DIG(pDM_Odm, pDM_DigTable->BT30_CurIGI);
  2815. }
  2816. pDM_DigTable->bMediaConnect_0 = pDM_Odm->bLinked;
  2817. pDM_DigTable->DIG_Dynamic_MIN_0 = DIG_Dynamic_MIN;
  2818. }
  2819. else
  2820. {
  2821. if(pDM_Odm->bLinkInProcess)
  2822. {
  2823. ODM_Write_DIG(pDM_Odm, 0x1c);
  2824. }
  2825. else if(pDM_Odm->bBtConnectProcess)
  2826. {
  2827. ODM_Write_DIG(pDM_Odm, 0x28);
  2828. }
  2829. else
  2830. {
  2831. ODM_Write_DIG(pDM_Odm, pDM_DigTable->BT30_CurIGI);//ODM_Write_DIG(pDM_Odm, pDM_DigTable->CurIGValue);
  2832. }
  2833. }
  2834. }
  2835. else // BT is not using
  2836. {
  2837. ODM_Write_DIG(pDM_Odm, CurrentIGI);//ODM_Write_DIG(pDM_Odm, pDM_DigTable->CurIGValue);
  2838. pDM_DigTable->bMediaConnect_0 = pDM_Odm->bLinked;
  2839. pDM_DigTable->DIG_Dynamic_MIN_0 = DIG_Dynamic_MIN;
  2840. }
  2841. }
  2842. }
  2843. BOOLEAN
  2844. odm_DigAbort(
  2845. IN PDM_ODM_T pDM_Odm
  2846. )
  2847. {
  2848. #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
  2849. // This should be moved out of OUTSRC
  2850. PADAPTER pAdapter = pDM_Odm->Adapter;
  2851. pRXHP_T pRX_HP_Table = &pDM_Odm->DM_RXHP_Table;
  2852. #if OS_WIN_FROM_WIN7(OS_VERSION)
  2853. if(IsAPModeExist( pAdapter) && pAdapter->bInHctTest)
  2854. {
  2855. ODM_RT_TRACE(pDM_Odm,ODM_COMP_DIG, ODM_DBG_LOUD, ("odm_DIG() Return: Is AP mode or In HCT Test \n"));
  2856. return TRUE;
  2857. }
  2858. #endif
  2859. if(pRX_HP_Table->RXHP_flag == 1)
  2860. {
  2861. ODM_RT_TRACE(pDM_Odm,ODM_COMP_DIG, ODM_DBG_LOUD, ("odm_DIG() Return: In RXHP Operation \n"));
  2862. return TRUE;
  2863. }
  2864. return FALSE;
  2865. #else // For Other team any special case for DIG?
  2866. return FALSE;
  2867. #endif
  2868. }
  2869. //3============================================================
  2870. //3 FASLE ALARM CHECK
  2871. //3============================================================
  2872. VOID
  2873. odm_FalseAlarmCounterStatistics(
  2874. IN PDM_ODM_T pDM_Odm
  2875. )
  2876. {
  2877. u4Byte ret_value;
  2878. PFALSE_ALARM_STATISTICS FalseAlmCnt = &(pDM_Odm->FalseAlmCnt);
  2879. #if (DM_ODM_SUPPORT_TYPE == ODM_AP)
  2880. prtl8192cd_priv priv = pDM_Odm->priv;
  2881. if( (priv->auto_channel != 0) && (priv->auto_channel != 2) )
  2882. return;
  2883. #endif
  2884. #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
  2885. if((pDM_Odm->SupportICType == ODM_RTL8192D) &&
  2886. (*(pDM_Odm->pMacPhyMode)==ODM_DMSP)&& ////modify by Guo.Mingzhi 2011-12-29
  2887. (!(*(pDM_Odm->pbMasterOfDMSP))))
  2888. {
  2889. odm_FalseAlarmCounterStatistics_ForSlaveOfDMSP(pDM_Odm);
  2890. return;
  2891. }
  2892. #endif
  2893. if(!(pDM_Odm->SupportAbility & ODM_BB_FA_CNT))
  2894. return;
  2895. if(pDM_Odm->SupportICType & ODM_IC_11N_SERIES)
  2896. {
  2897. //hold ofdm counter
  2898. ODM_SetBBReg(pDM_Odm, ODM_REG_OFDM_FA_HOLDC_11N, BIT31, 1); //hold page C counter
  2899. ODM_SetBBReg(pDM_Odm, ODM_REG_OFDM_FA_RSTD_11N, BIT31, 1); //hold page D counter
  2900. ret_value = ODM_GetBBReg(pDM_Odm, ODM_REG_OFDM_FA_TYPE1_11N, bMaskDWord);
  2901. FalseAlmCnt->Cnt_Fast_Fsync = (ret_value&0xffff);
  2902. FalseAlmCnt->Cnt_SB_Search_fail = ((ret_value&0xffff0000)>>16);
  2903. ret_value = ODM_GetBBReg(pDM_Odm, ODM_REG_OFDM_FA_TYPE2_11N, bMaskDWord);
  2904. FalseAlmCnt->Cnt_OFDM_CCA = (ret_value&0xffff);
  2905. FalseAlmCnt->Cnt_Parity_Fail = ((ret_value&0xffff0000)>>16);
  2906. ret_value = ODM_GetBBReg(pDM_Odm, ODM_REG_OFDM_FA_TYPE3_11N, bMaskDWord);
  2907. FalseAlmCnt->Cnt_Rate_Illegal = (ret_value&0xffff);
  2908. FalseAlmCnt->Cnt_Crc8_fail = ((ret_value&0xffff0000)>>16);
  2909. ret_value = ODM_GetBBReg(pDM_Odm, ODM_REG_OFDM_FA_TYPE4_11N, bMaskDWord);
  2910. FalseAlmCnt->Cnt_Mcs_fail = (ret_value&0xffff);
  2911. FalseAlmCnt->Cnt_Ofdm_fail = FalseAlmCnt->Cnt_Parity_Fail + FalseAlmCnt->Cnt_Rate_Illegal +
  2912. FalseAlmCnt->Cnt_Crc8_fail + FalseAlmCnt->Cnt_Mcs_fail +
  2913. FalseAlmCnt->Cnt_Fast_Fsync + FalseAlmCnt->Cnt_SB_Search_fail;
  2914. #if (RTL8188E_SUPPORT==1)
  2915. if((pDM_Odm->SupportICType == ODM_RTL8188E)||(pDM_Odm->SupportICType == ODM_RTL8192E))
  2916. {
  2917. ret_value = ODM_GetBBReg(pDM_Odm, ODM_REG_SC_CNT_11N, bMaskDWord);
  2918. FalseAlmCnt->Cnt_BW_LSC = (ret_value&0xffff);
  2919. FalseAlmCnt->Cnt_BW_USC = ((ret_value&0xffff0000)>>16);
  2920. }
  2921. #endif
  2922. #if (RTL8192D_SUPPORT==1)
  2923. if(pDM_Odm->SupportICType == ODM_RTL8192D)
  2924. {
  2925. odm_GetCCKFalseAlarm_92D(pDM_Odm);
  2926. }
  2927. else
  2928. #endif
  2929. {
  2930. //hold cck counter
  2931. ODM_SetBBReg(pDM_Odm, ODM_REG_CCK_FA_RST_11N, BIT12, 1);
  2932. ODM_SetBBReg(pDM_Odm, ODM_REG_CCK_FA_RST_11N, BIT14, 1);
  2933. ret_value = ODM_GetBBReg(pDM_Odm, ODM_REG_CCK_FA_LSB_11N, bMaskByte0);
  2934. FalseAlmCnt->Cnt_Cck_fail = ret_value;
  2935. ret_value = ODM_GetBBReg(pDM_Odm, ODM_REG_CCK_FA_MSB_11N, bMaskByte3);
  2936. FalseAlmCnt->Cnt_Cck_fail += (ret_value& 0xff)<<8;
  2937. ret_value = ODM_GetBBReg(pDM_Odm, ODM_REG_CCK_CCA_CNT_11N, bMaskDWord);
  2938. FalseAlmCnt->Cnt_CCK_CCA = ((ret_value&0xFF)<<8) |((ret_value&0xFF00)>>8);
  2939. }
  2940. FalseAlmCnt->Cnt_all = ( FalseAlmCnt->Cnt_Fast_Fsync +
  2941. FalseAlmCnt->Cnt_SB_Search_fail +
  2942. FalseAlmCnt->Cnt_Parity_Fail +
  2943. FalseAlmCnt->Cnt_Rate_Illegal +
  2944. FalseAlmCnt->Cnt_Crc8_fail +
  2945. FalseAlmCnt->Cnt_Mcs_fail +
  2946. FalseAlmCnt->Cnt_Cck_fail);
  2947. FalseAlmCnt->Cnt_CCA_all = FalseAlmCnt->Cnt_OFDM_CCA + FalseAlmCnt->Cnt_CCK_CCA;
  2948. #if (RTL8192C_SUPPORT==1)
  2949. if(pDM_Odm->SupportICType == ODM_RTL8192C)
  2950. odm_ResetFACounter_92C(pDM_Odm);
  2951. #endif
  2952. #if (RTL8192D_SUPPORT==1)
  2953. if(pDM_Odm->SupportICType == ODM_RTL8192D)
  2954. odm_ResetFACounter_92D(pDM_Odm);
  2955. #endif
  2956. if(pDM_Odm->SupportICType >=ODM_RTL8723A)
  2957. {
  2958. //reset false alarm counter registers
  2959. ODM_SetBBReg(pDM_Odm, ODM_REG_OFDM_FA_RSTC_11N, BIT31, 1);
  2960. ODM_SetBBReg(pDM_Odm, ODM_REG_OFDM_FA_RSTC_11N, BIT31, 0);
  2961. ODM_SetBBReg(pDM_Odm, ODM_REG_OFDM_FA_RSTD_11N, BIT27, 1);
  2962. ODM_SetBBReg(pDM_Odm, ODM_REG_OFDM_FA_RSTD_11N, BIT27, 0);
  2963. //update ofdm counter
  2964. ODM_SetBBReg(pDM_Odm, ODM_REG_OFDM_FA_HOLDC_11N, BIT31, 0); //update page C counter
  2965. ODM_SetBBReg(pDM_Odm, ODM_REG_OFDM_FA_RSTD_11N, BIT31, 0); //update page D counter
  2966. //reset CCK CCA counter
  2967. ODM_SetBBReg(pDM_Odm, ODM_REG_CCK_FA_RST_11N, BIT13|BIT12, 0);
  2968. ODM_SetBBReg(pDM_Odm, ODM_REG_CCK_FA_RST_11N, BIT13|BIT12, 2);
  2969. //reset CCK FA counter
  2970. ODM_SetBBReg(pDM_Odm, ODM_REG_CCK_FA_RST_11N, BIT15|BIT14, 0);
  2971. ODM_SetBBReg(pDM_Odm, ODM_REG_CCK_FA_RST_11N, BIT15|BIT14, 2);
  2972. }
  2973. ODM_RT_TRACE(pDM_Odm,ODM_COMP_FA_CNT, ODM_DBG_LOUD, ("Enter odm_FalseAlarmCounterStatistics\n"));
  2974. ODM_RT_TRACE(pDM_Odm,ODM_COMP_FA_CNT, ODM_DBG_LOUD, ("Cnt_Fast_Fsync=%d, Cnt_SB_Search_fail=%d\n",
  2975. FalseAlmCnt->Cnt_Fast_Fsync, FalseAlmCnt->Cnt_SB_Search_fail));
  2976. ODM_RT_TRACE(pDM_Odm,ODM_COMP_FA_CNT, ODM_DBG_LOUD, ("Cnt_Parity_Fail=%d, Cnt_Rate_Illegal=%d\n",
  2977. FalseAlmCnt->Cnt_Parity_Fail, FalseAlmCnt->Cnt_Rate_Illegal));
  2978. ODM_RT_TRACE(pDM_Odm,ODM_COMP_FA_CNT, ODM_DBG_LOUD, ("Cnt_Crc8_fail=%d, Cnt_Mcs_fail=%d\n",
  2979. FalseAlmCnt->Cnt_Crc8_fail, FalseAlmCnt->Cnt_Mcs_fail));
  2980. }
  2981. else if(pDM_Odm->SupportICType & ODM_IC_11AC_SERIES)
  2982. {
  2983. u4Byte CCKenable;
  2984. //read OFDM FA counter
  2985. FalseAlmCnt->Cnt_Ofdm_fail = ODM_GetBBReg(pDM_Odm, ODM_REG_OFDM_FA_11AC, bMaskLWord);
  2986. FalseAlmCnt->Cnt_Cck_fail = ODM_GetBBReg(pDM_Odm, ODM_REG_CCK_FA_11AC, bMaskLWord);
  2987. CCKenable = ODM_GetBBReg(pDM_Odm, ODM_REG_BB_RX_PATH_11AC, BIT28);
  2988. if(CCKenable)//if(*pDM_Odm->pBandType == ODM_BAND_2_4G)
  2989. FalseAlmCnt->Cnt_all = FalseAlmCnt->Cnt_Ofdm_fail + FalseAlmCnt->Cnt_Cck_fail;
  2990. else
  2991. FalseAlmCnt->Cnt_all = FalseAlmCnt->Cnt_Ofdm_fail;
  2992. // reset OFDM FA coutner
  2993. ODM_SetBBReg(pDM_Odm, ODM_REG_OFDM_FA_RST_11AC, BIT17, 1);
  2994. ODM_SetBBReg(pDM_Odm, ODM_REG_OFDM_FA_RST_11AC, BIT17, 0);
  2995. // reset CCK FA counter
  2996. ODM_SetBBReg(pDM_Odm, ODM_REG_CCK_FA_RST_11AC, BIT15, 0);
  2997. ODM_SetBBReg(pDM_Odm, ODM_REG_CCK_FA_RST_11AC, BIT15, 1);
  2998. }
  2999. ODM_RT_TRACE(pDM_Odm,ODM_COMP_FA_CNT, ODM_DBG_LOUD, ("Cnt_Cck_fail=%d\n", FalseAlmCnt->Cnt_Cck_fail));
  3000. ODM_RT_TRACE(pDM_Odm,ODM_COMP_FA_CNT, ODM_DBG_LOUD, ("Cnt_Ofdm_fail=%d\n", FalseAlmCnt->Cnt_Ofdm_fail));
  3001. ODM_RT_TRACE(pDM_Odm,ODM_COMP_FA_CNT, ODM_DBG_LOUD, ("Total False Alarm=%d\n", FalseAlmCnt->Cnt_all));
  3002. }
  3003. //3============================================================
  3004. //3 CCK Packet Detect Threshold
  3005. //3============================================================
  3006. VOID
  3007. odm_CCKPacketDetectionThresh(
  3008. IN PDM_ODM_T pDM_Odm
  3009. )
  3010. {
  3011. u1Byte CurCCK_CCAThres;
  3012. PFALSE_ALARM_STATISTICS FalseAlmCnt = &(pDM_Odm->FalseAlmCnt);
  3013. #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
  3014. //modify by Guo.Mingzhi 2011-12-29
  3015. if (pDM_Odm->bDualMacSmartConcurrent == TRUE)
  3016. // if (pDM_Odm->bDualMacSmartConcurrent == FALSE)
  3017. return;
  3018. if(pDM_Odm->bBtHsOperation)
  3019. {
  3020. ODM_RT_TRACE(pDM_Odm,ODM_COMP_DIG, ODM_DBG_LOUD, ("odm_CCKPacketDetectionThresh() write 0xcd for BT HS mode!!\n"));
  3021. ODM_Write_CCK_CCA_Thres(pDM_Odm, 0xcd);
  3022. return;
  3023. }
  3024. #endif
  3025. if(!(pDM_Odm->SupportAbility & (ODM_BB_CCK_PD|ODM_BB_FA_CNT)))
  3026. return;
  3027. if(pDM_Odm->ExtLNA)
  3028. return;
  3029. if(pDM_Odm->bLinked)
  3030. {
  3031. if(pDM_Odm->RSSI_Min > 25)
  3032. CurCCK_CCAThres = 0xcd;
  3033. else if((pDM_Odm->RSSI_Min <= 25) && (pDM_Odm->RSSI_Min > 10))
  3034. CurCCK_CCAThres = 0x83;
  3035. else
  3036. {
  3037. if(FalseAlmCnt->Cnt_Cck_fail > 1000)
  3038. CurCCK_CCAThres = 0x83;
  3039. else
  3040. CurCCK_CCAThres = 0x40;
  3041. }
  3042. }
  3043. else
  3044. {
  3045. if(FalseAlmCnt->Cnt_Cck_fail > 1000)
  3046. CurCCK_CCAThres = 0x83;
  3047. else
  3048. CurCCK_CCAThres = 0x40;
  3049. }
  3050. #if (RTL8192D_SUPPORT==1)
  3051. if((pDM_Odm->SupportICType == ODM_RTL8192D)&&(*pDM_Odm->pBandType == ODM_BAND_2_4G))
  3052. ODM_Write_CCK_CCA_Thres_92D(pDM_Odm, CurCCK_CCAThres);
  3053. else
  3054. #endif
  3055. ODM_Write_CCK_CCA_Thres(pDM_Odm, CurCCK_CCAThres);
  3056. }
  3057. VOID
  3058. ODM_Write_CCK_CCA_Thres(
  3059. IN PDM_ODM_T pDM_Odm,
  3060. IN u1Byte CurCCK_CCAThres
  3061. )
  3062. {
  3063. pDIG_T pDM_DigTable = &pDM_Odm->DM_DigTable;
  3064. if(pDM_DigTable->CurCCK_CCAThres!=CurCCK_CCAThres) //modify by Guo.Mingzhi 2012-01-03
  3065. {
  3066. ODM_Write1Byte(pDM_Odm, ODM_REG(CCK_CCA,pDM_Odm), CurCCK_CCAThres);
  3067. }
  3068. pDM_DigTable->PreCCK_CCAThres = pDM_DigTable->CurCCK_CCAThres;
  3069. pDM_DigTable->CurCCK_CCAThres = CurCCK_CCAThres;
  3070. }
  3071. //3============================================================
  3072. //3 BB Power Save
  3073. //3============================================================
  3074. VOID
  3075. odm_DynamicBBPowerSavingInit(
  3076. IN PDM_ODM_T pDM_Odm
  3077. )
  3078. {
  3079. pPS_T pDM_PSTable = &pDM_Odm->DM_PSTable;
  3080. pDM_PSTable->PreCCAState = CCA_MAX;
  3081. pDM_PSTable->CurCCAState = CCA_MAX;
  3082. pDM_PSTable->PreRFState = RF_MAX;
  3083. pDM_PSTable->CurRFState = RF_MAX;
  3084. pDM_PSTable->Rssi_val_min = 0;
  3085. pDM_PSTable->initialize = 0;
  3086. }
  3087. VOID
  3088. odm_DynamicBBPowerSaving(
  3089. IN PDM_ODM_T pDM_Odm
  3090. )
  3091. {
  3092. #if (DM_ODM_SUPPORT_TYPE & (ODM_WIN|ODM_CE))
  3093. if (pDM_Odm->SupportICType != ODM_RTL8723A)
  3094. return;
  3095. if(!(pDM_Odm->SupportAbility & ODM_BB_PWR_SAVE))
  3096. return;
  3097. if(!(pDM_Odm->SupportPlatform & (ODM_WIN|ODM_CE)))
  3098. return;
  3099. //1 2.Power Saving for 92C
  3100. if((pDM_Odm->SupportICType == ODM_RTL8192C) &&(pDM_Odm->RFType == ODM_2T2R))
  3101. {
  3102. odm_1R_CCA(pDM_Odm);
  3103. }
  3104. // 20100628 Joseph: Turn off BB power save for 88CE because it makesthroughput unstable.
  3105. // 20100831 Joseph: Turn ON BB power save again after modifying AGC delay from 900ns ot 600ns.
  3106. //1 3.Power Saving for 88C
  3107. else
  3108. {
  3109. ODM_RF_Saving(pDM_Odm, FALSE);
  3110. }
  3111. #endif // #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
  3112. }
  3113. VOID
  3114. odm_1R_CCA(
  3115. IN PDM_ODM_T pDM_Odm
  3116. )
  3117. {
  3118. pPS_T pDM_PSTable = &pDM_Odm->DM_PSTable;
  3119. if(pDM_Odm->RSSI_Min!= 0xFF)
  3120. {
  3121. if(pDM_PSTable->PreCCAState == CCA_2R)
  3122. {
  3123. if(pDM_Odm->RSSI_Min >= 35)
  3124. pDM_PSTable->CurCCAState = CCA_1R;
  3125. else
  3126. pDM_PSTable->CurCCAState = CCA_2R;
  3127. }
  3128. else{
  3129. if(pDM_Odm->RSSI_Min <= 30)
  3130. pDM_PSTable->CurCCAState = CCA_2R;
  3131. else
  3132. pDM_PSTable->CurCCAState = CCA_1R;
  3133. }
  3134. }
  3135. else{
  3136. pDM_PSTable->CurCCAState=CCA_MAX;
  3137. }
  3138. if(pDM_PSTable->PreCCAState != pDM_PSTable->CurCCAState)
  3139. {
  3140. if(pDM_PSTable->CurCCAState == CCA_1R)
  3141. {
  3142. if( pDM_Odm->RFType ==ODM_2T2R )
  3143. {
  3144. ODM_SetBBReg(pDM_Odm, 0xc04 , bMaskByte0, 0x13);
  3145. //PHY_SetBBReg(pAdapter, 0xe70, bMaskByte3, 0x20);
  3146. }
  3147. else
  3148. {
  3149. ODM_SetBBReg(pDM_Odm, 0xc04 , bMaskByte0, 0x23);
  3150. //PHY_SetBBReg(pAdapter, 0xe70, 0x7fc00000, 0x10c); // Set RegE70[30:22] = 9b'100001100
  3151. }
  3152. }
  3153. else
  3154. {
  3155. ODM_SetBBReg(pDM_Odm, 0xc04 , bMaskByte0, 0x33);
  3156. //PHY_SetBBReg(pAdapter,0xe70, bMaskByte3, 0x63);
  3157. }
  3158. pDM_PSTable->PreCCAState = pDM_PSTable->CurCCAState;
  3159. }
  3160. //ODM_RT_TRACE(pDM_Odm, COMP_BB_POWERSAVING, DBG_LOUD, ("CCAStage = %s\n",(pDM_PSTable->CurCCAState==0)?"1RCCA":"2RCCA"));
  3161. }
  3162. void
  3163. ODM_RF_Saving(
  3164. IN PDM_ODM_T pDM_Odm,
  3165. IN u1Byte bForceInNormal
  3166. )
  3167. {
  3168. #if (DM_ODM_SUPPORT_TYPE != ODM_AP)
  3169. pPS_T pDM_PSTable = &pDM_Odm->DM_PSTable;
  3170. u1Byte Rssi_Up_bound = 30 ;
  3171. u1Byte Rssi_Low_bound = 25;
  3172. #if (DM_ODM_SUPPORT_TYPE == ODM_CE)
  3173. if(pDM_Odm->PatchID == 40 ) //RT_CID_819x_FUNAI_TV
  3174. {
  3175. Rssi_Up_bound = 50 ;
  3176. Rssi_Low_bound = 45;
  3177. }
  3178. #endif
  3179. if(pDM_PSTable->initialize == 0){
  3180. pDM_PSTable->Reg874 = (ODM_GetBBReg(pDM_Odm, 0x874, bMaskDWord)&0x1CC000)>>14;
  3181. pDM_PSTable->RegC70 = (ODM_GetBBReg(pDM_Odm, 0xc70, bMaskDWord)&BIT3)>>3;
  3182. pDM_PSTable->Reg85C = (ODM_GetBBReg(pDM_Odm, 0x85c, bMaskDWord)&0xFF000000)>>24;
  3183. pDM_PSTable->RegA74 = (ODM_GetBBReg(pDM_Odm, 0xa74, bMaskDWord)&0xF000)>>12;
  3184. //Reg818 = PHY_QueryBBReg(pAdapter, 0x818, bMaskDWord);
  3185. pDM_PSTable->initialize = 1;
  3186. }
  3187. if(!bForceInNormal)
  3188. {
  3189. if(pDM_Odm->RSSI_Min != 0xFF)
  3190. {
  3191. if(pDM_PSTable->PreRFState == RF_Normal)
  3192. {
  3193. if(pDM_Odm->RSSI_Min >= Rssi_Up_bound)
  3194. pDM_PSTable->CurRFState = RF_Save;
  3195. else
  3196. pDM_PSTable->CurRFState = RF_Normal;
  3197. }
  3198. else{
  3199. if(pDM_Odm->RSSI_Min <= Rssi_Low_bound)
  3200. pDM_PSTable->CurRFState = RF_Normal;
  3201. else
  3202. pDM_PSTable->CurRFState = RF_Save;
  3203. }
  3204. }
  3205. else
  3206. pDM_PSTable->CurRFState=RF_MAX;
  3207. }
  3208. else
  3209. {
  3210. pDM_PSTable->CurRFState = RF_Normal;
  3211. }
  3212. if(pDM_PSTable->PreRFState != pDM_PSTable->CurRFState)
  3213. {
  3214. if(pDM_PSTable->CurRFState == RF_Save)
  3215. {
  3216. // <tynli_note> 8723 RSSI report will be wrong. Set 0x874[5]=1 when enter BB power saving mode.
  3217. // Suggested by SD3 Yu-Nan. 2011.01.20.
  3218. if(pDM_Odm->SupportICType == ODM_RTL8723A)
  3219. {
  3220. ODM_SetBBReg(pDM_Odm, 0x874 , BIT5, 0x1); //Reg874[5]=1b'1
  3221. }
  3222. ODM_SetBBReg(pDM_Odm, 0x874 , 0x1C0000, 0x2); //Reg874[20:18]=3'b010
  3223. ODM_SetBBReg(pDM_Odm, 0xc70, BIT3, 0); //RegC70[3]=1'b0
  3224. ODM_SetBBReg(pDM_Odm, 0x85c, 0xFF000000, 0x63); //Reg85C[31:24]=0x63
  3225. ODM_SetBBReg(pDM_Odm, 0x874, 0xC000, 0x2); //Reg874[15:14]=2'b10
  3226. ODM_SetBBReg(pDM_Odm, 0xa74, 0xF000, 0x3); //RegA75[7:4]=0x3
  3227. ODM_SetBBReg(pDM_Odm, 0x818, BIT28, 0x0); //Reg818[28]=1'b0
  3228. ODM_SetBBReg(pDM_Odm, 0x818, BIT28, 0x1); //Reg818[28]=1'b1
  3229. //ODM_RT_TRACE(pDM_Odm, COMP_BB_POWERSAVING, DBG_LOUD, (" RF_Save"));
  3230. }
  3231. else
  3232. {
  3233. ODM_SetBBReg(pDM_Odm, 0x874 , 0x1CC000, pDM_PSTable->Reg874);
  3234. ODM_SetBBReg(pDM_Odm, 0xc70, BIT3, pDM_PSTable->RegC70);
  3235. ODM_SetBBReg(pDM_Odm, 0x85c, 0xFF000000, pDM_PSTable->Reg85C);
  3236. ODM_SetBBReg(pDM_Odm, 0xa74, 0xF000, pDM_PSTable->RegA74);
  3237. ODM_SetBBReg(pDM_Odm,0x818, BIT28, 0x0);
  3238. if(pDM_Odm->SupportICType == ODM_RTL8723A)
  3239. {
  3240. ODM_SetBBReg(pDM_Odm,0x874 , BIT5, 0x0); //Reg874[5]=1b'0
  3241. }
  3242. //ODM_RT_TRACE(pDM_Odm, COMP_BB_POWERSAVING, DBG_LOUD, (" RF_Normal"));
  3243. }
  3244. pDM_PSTable->PreRFState =pDM_PSTable->CurRFState;
  3245. }
  3246. #endif
  3247. }
  3248. //3============================================================
  3249. //3 RATR MASK
  3250. //3============================================================
  3251. //3============================================================
  3252. //3 Rate Adaptive
  3253. //3============================================================
  3254. VOID
  3255. odm_RateAdaptiveMaskInit(
  3256. IN PDM_ODM_T pDM_Odm
  3257. )
  3258. {
  3259. PODM_RATE_ADAPTIVE pOdmRA = &pDM_Odm->RateAdaptive;
  3260. #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
  3261. PMGNT_INFO pMgntInfo = &pDM_Odm->Adapter->MgntInfo;
  3262. pMgntInfo->Ratr_State = DM_RATR_STA_INIT;
  3263. if (pMgntInfo->DM_Type == DM_Type_ByDriver)
  3264. pMgntInfo->bUseRAMask = TRUE;
  3265. else
  3266. pMgntInfo->bUseRAMask = FALSE;
  3267. #elif (DM_ODM_SUPPORT_TYPE == ODM_CE)
  3268. pOdmRA->Type = DM_Type_ByDriver;
  3269. if (pOdmRA->Type == DM_Type_ByDriver)
  3270. pDM_Odm->bUseRAMask = _TRUE;
  3271. else
  3272. pDM_Odm->bUseRAMask = _FALSE;
  3273. #endif
  3274. pOdmRA->RATRState = DM_RATR_STA_INIT;
  3275. pOdmRA->LdpcThres = 35;
  3276. pOdmRA->bUseLdpc = FALSE;
  3277. pOdmRA->HighRSSIThresh = 50;
  3278. pOdmRA->LowRSSIThresh = 20;
  3279. }
  3280. #if (DM_ODM_SUPPORT_TYPE & ODM_WIN)
  3281. VOID
  3282. ODM_RateAdaptiveStateApInit(
  3283. IN PADAPTER Adapter ,
  3284. IN PRT_WLAN_STA pEntry
  3285. )
  3286. {
  3287. pEntry->Ratr_State = DM_RATR_STA_INIT;
  3288. }
  3289. #endif
  3290. #if (DM_ODM_SUPPORT_TYPE == ODM_CE)
  3291. u4Byte ODM_Get_Rate_Bitmap(
  3292. IN PDM_ODM_T pDM_Odm,
  3293. IN u4Byte macid,
  3294. IN u4Byte ra_mask,
  3295. IN u1Byte rssi_level)
  3296. {
  3297. PSTA_INFO_T pEntry;
  3298. u4Byte rate_bitmap = 0;
  3299. u1Byte WirelessMode;
  3300. //u1Byte WirelessMode =*(pDM_Odm->pWirelessMode);
  3301. pEntry = pDM_Odm->pODM_StaInfo[macid];
  3302. if(!IS_STA_VALID(pEntry))
  3303. return ra_mask;
  3304. WirelessMode = pEntry->wireless_mode;
  3305. switch(WirelessMode)
  3306. {
  3307. case ODM_WM_B:
  3308. if(ra_mask & 0x0000000c) //11M or 5.5M enable
  3309. rate_bitmap = 0x0000000d;
  3310. else
  3311. rate_bitmap = 0x0000000f;
  3312. break;
  3313. case (ODM_WM_G):
  3314. case (ODM_WM_A):
  3315. if(rssi_level == DM_RATR_STA_HIGH)
  3316. rate_bitmap = 0x00000f00;
  3317. else
  3318. rate_bitmap = 0x00000ff0;
  3319. break;
  3320. case (ODM_WM_B|ODM_WM_G):
  3321. if(rssi_level == DM_RATR_STA_HIGH)
  3322. rate_bitmap = 0x00000f00;
  3323. else if(rssi_level == DM_RATR_STA_MIDDLE)
  3324. rate_bitmap = 0x00000ff0;
  3325. else
  3326. rate_bitmap = 0x00000ff5;
  3327. break;
  3328. case (ODM_WM_B|ODM_WM_G|ODM_WM_N24G) :
  3329. case (ODM_WM_B|ODM_WM_N24G) :
  3330. case (ODM_WM_A|ODM_WM_N5G) :
  3331. {
  3332. if ( pDM_Odm->RFType == ODM_1T2R ||pDM_Odm->RFType == ODM_1T1R)
  3333. {
  3334. if(rssi_level == DM_RATR_STA_HIGH)
  3335. {
  3336. rate_bitmap = 0x000f0000;
  3337. }
  3338. else if(rssi_level == DM_RATR_STA_MIDDLE)
  3339. {
  3340. rate_bitmap = 0x000ff000;
  3341. }
  3342. else{
  3343. if (*(pDM_Odm->pBandWidth) == ODM_BW40M)
  3344. rate_bitmap = 0x000ff015;
  3345. else
  3346. rate_bitmap = 0x000ff005;
  3347. }
  3348. }
  3349. else
  3350. {
  3351. if(rssi_level == DM_RATR_STA_HIGH)
  3352. {
  3353. rate_bitmap = 0x0f8f0000;
  3354. }
  3355. else if(rssi_level == DM_RATR_STA_MIDDLE)
  3356. {
  3357. rate_bitmap = 0x0f8ff000;
  3358. }
  3359. else
  3360. {
  3361. if (*(pDM_Odm->pBandWidth) == ODM_BW40M)
  3362. rate_bitmap = 0x0f8ff015;
  3363. else
  3364. rate_bitmap = 0x0f8ff005;
  3365. }
  3366. }
  3367. }
  3368. break;
  3369. case (ODM_WM_AC|ODM_WM_A):
  3370. case (ODM_WM_AC|ODM_WM_G):
  3371. if (pDM_Odm->RFType == RF_1T1R)
  3372. {
  3373. if( (pDM_Odm->SupportICType == ODM_RTL8821)||
  3374. (pDM_Odm->SupportICType == ODM_RTL8812 && pDM_Odm->bIsMPChip))
  3375. {
  3376. if( (pDM_Odm->SupportICType == ODM_RTL8821)
  3377. && (pDM_Odm->SupportInterface == ODM_ITRF_USB)
  3378. && (*(pDM_Odm->pChannel) >= 149))
  3379. {
  3380. if(rssi_level == 1) // add by Gary for ac-series
  3381. rate_bitmap = 0x001f8000;
  3382. else if (rssi_level == 2)
  3383. rate_bitmap = 0x001ff000;
  3384. else
  3385. rate_bitmap = 0x001ff010;
  3386. }
  3387. else
  3388. {
  3389. if(rssi_level == 1) // add by Gary for ac-series
  3390. rate_bitmap = 0x003f8000;
  3391. else if (rssi_level == 2)
  3392. rate_bitmap = 0x003ff000;
  3393. else
  3394. rate_bitmap = 0x003ff010;
  3395. }
  3396. }
  3397. else{
  3398. rate_bitmap = 0x000ff010;
  3399. }
  3400. }
  3401. else
  3402. {
  3403. if(pDM_Odm->bIsMPChip)
  3404. {
  3405. if(rssi_level == 1) // add by Gary for ac-series
  3406. rate_bitmap = 0xfe3f8000; // VHT 2SS MCS3~9
  3407. else if (rssi_level == 2)
  3408. rate_bitmap = 0xfffff000; // VHT 2SS MCS0~9
  3409. else
  3410. rate_bitmap = 0xfffff010; // All
  3411. }
  3412. else
  3413. rate_bitmap = 0x3fcff010;
  3414. }
  3415. break;
  3416. default:
  3417. if(pDM_Odm->RFType == RF_1T2R)
  3418. rate_bitmap = 0x000fffff;
  3419. else
  3420. rate_bitmap = 0x0fffffff;
  3421. break;
  3422. }
  3423. //printk("%s ==> rssi_level:0x%02x, WirelessMode:0x%02x, rate_bitmap:0x%08x \n",__FUNCTION__,rssi_level,WirelessMode,rate_bitmap);
  3424. ODM_RT_TRACE(pDM_Odm, ODM_COMP_RA_MASK, ODM_DBG_LOUD, (" ==> rssi_level:0x%02x, WirelessMode:0x%02x, rate_bitmap:0x%08x \n",rssi_level,WirelessMode,rate_bitmap));
  3425. return (ra_mask&rate_bitmap);
  3426. }
  3427. #endif
  3428. VOID
  3429. odm_RefreshBasicRateMask(
  3430. IN PDM_ODM_T pDM_Odm
  3431. )
  3432. {
  3433. #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
  3434. PADAPTER Adapter = pDM_Odm->Adapter;
  3435. static u1Byte Stage = 0;
  3436. u1Byte CurStage = 0;
  3437. OCTET_STRING osRateSet;
  3438. PMGNT_INFO pMgntInfo = GetDefaultMgntInfo(Adapter);
  3439. u1Byte RateSet[5] = {MGN_1M, MGN_2M, MGN_5_5M, MGN_11M, MGN_6M};
  3440. if(pDM_Odm->SupportICType != ODM_RTL8812 && pDM_Odm->SupportICType != ODM_RTL8821 )
  3441. return;
  3442. if(pDM_Odm->bLinked == FALSE) // unlink Default port information
  3443. CurStage = 0;
  3444. else if(pDM_Odm->RSSI_Min < 25) // link RSSI < 25%
  3445. CurStage = 1;
  3446. else if(pDM_Odm->RSSI_Min > 30) // link RSSI > 30%
  3447. CurStage = 3;
  3448. else
  3449. CurStage = 2; // link 25% <= RSSI <= 30%
  3450. if(CurStage != Stage)
  3451. {
  3452. if(CurStage == 1)
  3453. {
  3454. FillOctetString(osRateSet, RateSet, 5);
  3455. FilterSupportRate(pMgntInfo->mBrates, &osRateSet, FALSE);
  3456. Adapter->HalFunc.SetHwRegHandler(Adapter, HW_VAR_BASIC_RATE, (pu1Byte)&osRateSet);
  3457. }
  3458. else if(CurStage == 3 && (Stage == 1 || Stage == 2))
  3459. {
  3460. Adapter->HalFunc.SetHwRegHandler( Adapter, HW_VAR_BASIC_RATE, (pu1Byte)(&pMgntInfo->mBrates) );
  3461. }
  3462. }
  3463. Stage = CurStage;
  3464. #endif
  3465. }
  3466. /*-----------------------------------------------------------------------------
  3467. * Function: odm_RefreshRateAdaptiveMask()
  3468. *
  3469. * Overview: Update rate table mask according to rssi
  3470. *
  3471. * Input: NONE
  3472. *
  3473. * Output: NONE
  3474. *
  3475. * Return: NONE
  3476. *
  3477. * Revised History:
  3478. * When Who Remark
  3479. * 05/27/2009 hpfan Create Version 0.
  3480. *
  3481. *---------------------------------------------------------------------------*/
  3482. VOID
  3483. odm_RefreshRateAdaptiveMask(
  3484. IN PDM_ODM_T pDM_Odm
  3485. )
  3486. {
  3487. ODM_RT_TRACE(pDM_Odm, ODM_COMP_RA_MASK, ODM_DBG_TRACE, ("odm_RefreshRateAdaptiveMask()---------->\n"));
  3488. if (!(pDM_Odm->SupportAbility & ODM_BB_RA_MASK))
  3489. {
  3490. ODM_RT_TRACE(pDM_Odm, ODM_COMP_RA_MASK, ODM_DBG_TRACE, ("odm_RefreshRateAdaptiveMask(): Return cos not supported\n"));
  3491. return;
  3492. }
  3493. //
  3494. // 2011/09/29 MH In HW integration first stage, we provide 4 different handle to operate
  3495. // at the same time. In the stage2/3, we need to prive universal interface and merge all
  3496. // HW dynamic mechanism.
  3497. //
  3498. switch (pDM_Odm->SupportPlatform)
  3499. {
  3500. case ODM_WIN:
  3501. odm_RefreshRateAdaptiveMaskMP(pDM_Odm);
  3502. break;
  3503. case ODM_CE:
  3504. odm_RefreshRateAdaptiveMaskCE(pDM_Odm);
  3505. break;
  3506. case ODM_AP:
  3507. case ODM_ADSL:
  3508. odm_RefreshRateAdaptiveMaskAPADSL(pDM_Odm);
  3509. break;
  3510. }
  3511. }
  3512. VOID
  3513. odm_RefreshRateAdaptiveMaskMP(
  3514. IN PDM_ODM_T pDM_Odm
  3515. )
  3516. {
  3517. #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
  3518. PADAPTER pAdapter = pDM_Odm->Adapter;
  3519. PADAPTER pTargetAdapter = NULL;
  3520. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(pAdapter);
  3521. PMGNT_INFO pMgntInfo = GetDefaultMgntInfo(pAdapter);
  3522. PODM_RATE_ADAPTIVE pRA = &pDM_Odm->RateAdaptive;
  3523. if(pAdapter->bDriverStopped)
  3524. {
  3525. ODM_RT_TRACE(pDM_Odm, ODM_COMP_RA_MASK, ODM_DBG_TRACE, ("<---- odm_RefreshRateAdaptiveMask(): driver is going to unload\n"));
  3526. return;
  3527. }
  3528. if(!pMgntInfo->bUseRAMask)
  3529. {
  3530. ODM_RT_TRACE(pDM_Odm, ODM_COMP_RA_MASK, ODM_DBG_LOUD, ("<---- odm_RefreshRateAdaptiveMask(): driver does not control rate adaptive mask\n"));
  3531. return;
  3532. }
  3533. // if default port is connected, update RA table for default port (infrastructure mode only)
  3534. if(pMgntInfo->mAssoc && (!ACTING_AS_AP(pAdapter)))
  3535. {
  3536. if(pHalData->UndecoratedSmoothedPWDB < pRA->LdpcThres)
  3537. {
  3538. pRA->bUseLdpc = TRUE;
  3539. pRA->bLowerRtsRate = TRUE;
  3540. Set_RA_LDPC_8812(pAdapter,0,TRUE);
  3541. //DbgPrint("RSSI=%d, bUseLdpc = TRUE\n", pHalData->UndecoratedSmoothedPWDB);
  3542. }
  3543. else if(pHalData->UndecoratedSmoothedPWDB > (pRA->LdpcThres-5))
  3544. {
  3545. pRA->bUseLdpc = FALSE;
  3546. pRA->bLowerRtsRate = FALSE;
  3547. Set_RA_LDPC_8812(pAdapter,0,FALSE);
  3548. //DbgPrint("RSSI=%d, bUseLdpc = FALSE\n", pHalData->UndecoratedSmoothedPWDB);
  3549. }
  3550. ODM_RT_TRACE(pDM_Odm, ODM_COMP_RA_MASK, ODM_DBG_LOUD, ("odm_RefreshRateAdaptiveMask(): Infrasture Mode\n"));
  3551. if( ODM_RAStateCheck(pDM_Odm, pHalData->UndecoratedSmoothedPWDB, pMgntInfo->bSetTXPowerTrainingByOid, &pMgntInfo->Ratr_State) )
  3552. {
  3553. ODM_PRINT_ADDR(pDM_Odm, ODM_COMP_RA_MASK, ODM_DBG_LOUD, ("Target AP addr : "), pMgntInfo->Bssid);
  3554. ODM_RT_TRACE(pDM_Odm, ODM_COMP_RA_MASK, ODM_DBG_LOUD, ("RSSI:%d, RSSI_LEVEL:%d\n", pHalData->UndecoratedSmoothedPWDB, pMgntInfo->Ratr_State));
  3555. pAdapter->HalFunc.UpdateHalRAMaskHandler(
  3556. pAdapter,
  3557. FALSE,
  3558. pMgntInfo->mMacId,
  3559. NULL,
  3560. NULL,
  3561. pMgntInfo->Ratr_State,
  3562. RAMask_Normal);
  3563. }
  3564. }
  3565. //
  3566. // The following part configure AP/VWifi/IBSS rate adaptive mask.
  3567. //
  3568. if(pMgntInfo->mIbss) // Target: AP/IBSS peer.
  3569. pTargetAdapter = GetDefaultAdapter(pAdapter);
  3570. else
  3571. pTargetAdapter = GetFirstAPAdapter(pAdapter);
  3572. // if extension port (softap) is started, updaet RA table for more than one clients associate
  3573. if(pTargetAdapter != NULL)
  3574. {
  3575. int i;
  3576. PRT_WLAN_STA pEntry;
  3577. for(i = 0; i < ODM_ASSOCIATE_ENTRY_NUM; i++)
  3578. {
  3579. pEntry = AsocEntry_EnumStation(pTargetAdapter, i);
  3580. if(NULL != pEntry)
  3581. {
  3582. if(pEntry->bAssociated)
  3583. {
  3584. if(ODM_RAStateCheck(pDM_Odm, pEntry->rssi_stat.UndecoratedSmoothedPWDB, pMgntInfo->bSetTXPowerTrainingByOid, &pEntry->Ratr_State) )
  3585. {
  3586. ODM_PRINT_ADDR(pDM_Odm, ODM_COMP_RA_MASK, ODM_DBG_LOUD, ("Target STA addr : "), pEntry->MacAddr);
  3587. ODM_RT_TRACE(pDM_Odm, ODM_COMP_RA_MASK, ODM_DBG_LOUD, ("RSSI:%d, RSSI_LEVEL:%d\n", pEntry->rssi_stat.UndecoratedSmoothedPWDB, pEntry->Ratr_State));
  3588. pAdapter->HalFunc.UpdateHalRAMaskHandler(
  3589. pTargetAdapter,
  3590. FALSE,
  3591. pEntry->AssociatedMacId,
  3592. pEntry->MacAddr,
  3593. pEntry,
  3594. pEntry->Ratr_State,
  3595. RAMask_Normal);
  3596. }
  3597. }
  3598. }
  3599. }
  3600. }
  3601. if(pMgntInfo->bSetTXPowerTrainingByOid)
  3602. pMgntInfo->bSetTXPowerTrainingByOid = FALSE;
  3603. #endif // #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
  3604. }
  3605. VOID
  3606. odm_RefreshRateAdaptiveMaskCE(
  3607. IN PDM_ODM_T pDM_Odm
  3608. )
  3609. {
  3610. #if (DM_ODM_SUPPORT_TYPE == ODM_CE)
  3611. u1Byte i;
  3612. PADAPTER pAdapter = pDM_Odm->Adapter;
  3613. PODM_RATE_ADAPTIVE pRA = &pDM_Odm->RateAdaptive;
  3614. if(pAdapter->bDriverStopped)
  3615. {
  3616. ODM_RT_TRACE(pDM_Odm, ODM_COMP_RA_MASK, ODM_DBG_TRACE, ("<---- odm_RefreshRateAdaptiveMask(): driver is going to unload\n"));
  3617. return;
  3618. }
  3619. if(!pDM_Odm->bUseRAMask)
  3620. {
  3621. ODM_RT_TRACE(pDM_Odm, ODM_COMP_RA_MASK, ODM_DBG_LOUD, ("<---- odm_RefreshRateAdaptiveMask(): driver does not control rate adaptive mask\n"));
  3622. return;
  3623. }
  3624. //printk("==> %s \n",__FUNCTION__);
  3625. for(i=0; i<ODM_ASSOCIATE_ENTRY_NUM; i++){
  3626. PSTA_INFO_T pstat = pDM_Odm->pODM_StaInfo[i];
  3627. if(IS_STA_VALID(pstat) ) {
  3628. #if((RTL8812A_SUPPORT==1)||(RTL8821A_SUPPORT==1))
  3629. if((pDM_Odm->SupportICType == ODM_RTL8812)||(pDM_Odm->SupportICType == ODM_RTL8821))
  3630. {
  3631. if(pstat->rssi_stat.UndecoratedSmoothedPWDB < pRA->LdpcThres)
  3632. {
  3633. pRA->bUseLdpc = TRUE;
  3634. pRA->bLowerRtsRate = TRUE;
  3635. Set_RA_LDPC_8812(pstat, TRUE);
  3636. //DbgPrint("RSSI=%d, bUseLdpc = TRUE\n", pHalData->UndecoratedSmoothedPWDB);
  3637. }
  3638. else if(pstat->rssi_stat.UndecoratedSmoothedPWDB > (pRA->LdpcThres-5))
  3639. {
  3640. pRA->bUseLdpc = FALSE;
  3641. pRA->bLowerRtsRate = FALSE;
  3642. Set_RA_LDPC_8812(pstat, FALSE);
  3643. //DbgPrint("RSSI=%d, bUseLdpc = FALSE\n", pHalData->UndecoratedSmoothedPWDB);
  3644. }
  3645. }
  3646. #endif
  3647. if( TRUE == ODM_RAStateCheck(pDM_Odm, pstat->rssi_stat.UndecoratedSmoothedPWDB, FALSE , &pstat->rssi_level) )
  3648. {
  3649. ODM_RT_TRACE(pDM_Odm, ODM_COMP_RA_MASK, ODM_DBG_LOUD, ("RSSI:%d, RSSI_LEVEL:%d\n", pstat->rssi_stat.UndecoratedSmoothedPWDB, pstat->rssi_level));
  3650. //printk("RSSI:%d, RSSI_LEVEL:%d\n", pstat->rssi_stat.UndecoratedSmoothedPWDB, pstat->rssi_level);
  3651. rtw_hal_update_ra_mask(pstat, pstat->rssi_level);
  3652. }
  3653. }
  3654. }
  3655. #endif
  3656. }
  3657. VOID
  3658. odm_RefreshRateAdaptiveMaskAPADSL(
  3659. IN PDM_ODM_T pDM_Odm
  3660. )
  3661. {
  3662. #if (DM_ODM_SUPPORT_TYPE & (ODM_AP|ODM_ADSL))
  3663. struct rtl8192cd_priv *priv = pDM_Odm->priv;
  3664. struct stat_info *pstat;
  3665. if (!priv->pmib->dot11StationConfigEntry.autoRate)
  3666. return;
  3667. if (list_empty(&priv->asoc_list))
  3668. return;
  3669. list_for_each_entry(pstat, &priv->asoc_list, asoc_list) {
  3670. if(ODM_RAStateCheck(pDM_Odm, (s4Byte)pstat->rssi, FALSE, &pstat->rssi_level) ) {
  3671. ODM_PRINT_ADDR(pDM_Odm, ODM_COMP_RA_MASK, ODM_DBG_LOUD, ("Target STA addr : "), pstat->hwaddr);
  3672. ODM_RT_TRACE(pDM_Odm, ODM_COMP_RA_MASK, ODM_DBG_LOUD, ("RSSI:%d, RSSI_LEVEL:%d\n", pstat->rssi, pstat->rssi_level));
  3673. #ifdef CONFIG_RTL_88E_SUPPORT
  3674. if (GET_CHIP_VER(priv)==VERSION_8188E) {
  3675. #ifdef TXREPORT
  3676. add_RATid(priv, pstat);
  3677. #endif
  3678. } else
  3679. #endif
  3680. {
  3681. #if defined(CONFIG_RTL_92D_SUPPORT) || defined(CONFIG_RTL_92C_SUPPORT)
  3682. add_update_RATid(priv, pstat);
  3683. #endif
  3684. }
  3685. }
  3686. }
  3687. #endif
  3688. }
  3689. // Return Value: BOOLEAN
  3690. // - TRUE: RATRState is changed.
  3691. BOOLEAN
  3692. ODM_RAStateCheck(
  3693. IN PDM_ODM_T pDM_Odm,
  3694. IN s4Byte RSSI,
  3695. IN BOOLEAN bForceUpdate,
  3696. OUT pu1Byte pRATRState
  3697. )
  3698. {
  3699. PODM_RATE_ADAPTIVE pRA = &pDM_Odm->RateAdaptive;
  3700. const u1Byte GoUpGap = 5;
  3701. u1Byte HighRSSIThreshForRA = pRA->HighRSSIThresh;
  3702. u1Byte LowRSSIThreshForRA = pRA->LowRSSIThresh;
  3703. u1Byte RATRState;
  3704. // Threshold Adjustment:
  3705. // when RSSI state trends to go up one or two levels, make sure RSSI is high enough.
  3706. // Here GoUpGap is added to solve the boundary's level alternation issue.
  3707. switch (*pRATRState)
  3708. {
  3709. case DM_RATR_STA_INIT:
  3710. case DM_RATR_STA_HIGH:
  3711. break;
  3712. case DM_RATR_STA_MIDDLE:
  3713. HighRSSIThreshForRA += GoUpGap;
  3714. break;
  3715. case DM_RATR_STA_LOW:
  3716. HighRSSIThreshForRA += GoUpGap;
  3717. LowRSSIThreshForRA += GoUpGap;
  3718. break;
  3719. default:
  3720. ODM_RT_ASSERT(pDM_Odm, FALSE, ("wrong rssi level setting %d !", *pRATRState) );
  3721. break;
  3722. }
  3723. // Decide RATRState by RSSI.
  3724. if(RSSI > HighRSSIThreshForRA)
  3725. RATRState = DM_RATR_STA_HIGH;
  3726. else if(RSSI > LowRSSIThreshForRA)
  3727. RATRState = DM_RATR_STA_MIDDLE;
  3728. else
  3729. RATRState = DM_RATR_STA_LOW;
  3730. //printk("==>%s,RATRState:0x%02x ,RSSI:%d \n",__FUNCTION__,RATRState,RSSI);
  3731. if( *pRATRState!=RATRState || bForceUpdate)
  3732. {
  3733. ODM_RT_TRACE( pDM_Odm, ODM_COMP_RA_MASK, ODM_DBG_LOUD, ("RSSI Level %d -> %d\n", *pRATRState, RATRState) );
  3734. *pRATRState = RATRState;
  3735. return TRUE;
  3736. }
  3737. return FALSE;
  3738. }
  3739. //============================================================
  3740. //3============================================================
  3741. //3 Dynamic Tx Power
  3742. //3============================================================
  3743. VOID
  3744. odm_DynamicTxPowerInit(
  3745. IN PDM_ODM_T pDM_Odm
  3746. )
  3747. {
  3748. #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
  3749. PADAPTER Adapter = pDM_Odm->Adapter;
  3750. PMGNT_INFO pMgntInfo = &Adapter->MgntInfo;
  3751. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  3752. #if DEV_BUS_TYPE==RT_USB_INTERFACE
  3753. if(RT_GetInterfaceSelection(Adapter) == INTF_SEL1_USB_High_Power)
  3754. {
  3755. odm_DynamicTxPowerSavePowerIndex(pDM_Odm);
  3756. pMgntInfo->bDynamicTxPowerEnable = TRUE;
  3757. }
  3758. else
  3759. #else
  3760. //so 92c pci do not need dynamic tx power? vivi check it later
  3761. if(IS_HARDWARE_TYPE_8192D(Adapter))
  3762. pMgntInfo->bDynamicTxPowerEnable = TRUE;
  3763. else
  3764. pMgntInfo->bDynamicTxPowerEnable = FALSE;
  3765. #endif
  3766. pHalData->LastDTPLvl = TxHighPwrLevel_Normal;
  3767. pHalData->DynamicTxHighPowerLvl = TxHighPwrLevel_Normal;
  3768. #elif (DM_ODM_SUPPORT_TYPE == ODM_CE)
  3769. PADAPTER Adapter = pDM_Odm->Adapter;
  3770. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  3771. struct dm_priv *pdmpriv = &pHalData->dmpriv;
  3772. pdmpriv->bDynamicTxPowerEnable = _FALSE;
  3773. #if (RTL8192C_SUPPORT==1)
  3774. #ifdef CONFIG_USB_HCI
  3775. #ifdef CONFIG_INTEL_PROXIM
  3776. if((pHalData->BoardType == BOARD_USB_High_PA)||(Adapter->proximity.proxim_support==_TRUE))
  3777. #else
  3778. if(pHalData->BoardType == BOARD_USB_High_PA)
  3779. #endif
  3780. {
  3781. //odm_SavePowerIndex(Adapter);
  3782. odm_DynamicTxPowerSavePowerIndex(pDM_Odm);
  3783. pdmpriv->bDynamicTxPowerEnable = _TRUE;
  3784. }
  3785. else
  3786. #else
  3787. pdmpriv->bDynamicTxPowerEnable = _FALSE;
  3788. #endif
  3789. #endif
  3790. pdmpriv->LastDTPLvl = TxHighPwrLevel_Normal;
  3791. pdmpriv->DynamicTxHighPowerLvl = TxHighPwrLevel_Normal;
  3792. #endif
  3793. }
  3794. VOID
  3795. odm_DynamicTxPowerSavePowerIndex(
  3796. IN PDM_ODM_T pDM_Odm
  3797. )
  3798. {
  3799. u1Byte index;
  3800. u4Byte Power_Index_REG[6] = {0xc90, 0xc91, 0xc92, 0xc98, 0xc99, 0xc9a};
  3801. #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
  3802. PADAPTER Adapter = pDM_Odm->Adapter;
  3803. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  3804. for(index = 0; index< 6; index++)
  3805. pHalData->PowerIndex_backup[index] = PlatformEFIORead1Byte(Adapter, Power_Index_REG[index]);
  3806. #elif (DM_ODM_SUPPORT_TYPE == ODM_CE)
  3807. PADAPTER Adapter = pDM_Odm->Adapter;
  3808. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  3809. struct dm_priv *pdmpriv = &pHalData->dmpriv;
  3810. for(index = 0; index< 6; index++)
  3811. pdmpriv->PowerIndex_backup[index] = rtw_read8(Adapter, Power_Index_REG[index]);
  3812. #endif
  3813. }
  3814. VOID
  3815. odm_DynamicTxPowerRestorePowerIndex(
  3816. IN PDM_ODM_T pDM_Odm
  3817. )
  3818. {
  3819. u1Byte index;
  3820. PADAPTER Adapter = pDM_Odm->Adapter;
  3821. #if (DM_ODM_SUPPORT_TYPE & (ODM_CE|ODM_WIN))
  3822. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  3823. u4Byte Power_Index_REG[6] = {0xc90, 0xc91, 0xc92, 0xc98, 0xc99, 0xc9a};
  3824. #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
  3825. for(index = 0; index< 6; index++)
  3826. PlatformEFIOWrite1Byte(Adapter, Power_Index_REG[index], pHalData->PowerIndex_backup[index]);
  3827. #elif(DM_ODM_SUPPORT_TYPE == ODM_CE)
  3828. struct dm_priv *pdmpriv = &pHalData->dmpriv;
  3829. for(index = 0; index< 6; index++)
  3830. rtw_write8(Adapter, Power_Index_REG[index], pdmpriv->PowerIndex_backup[index]);
  3831. #endif
  3832. #endif
  3833. }
  3834. VOID
  3835. odm_DynamicTxPowerWritePowerIndex(
  3836. IN PDM_ODM_T pDM_Odm,
  3837. IN u1Byte Value)
  3838. {
  3839. u1Byte index;
  3840. u4Byte Power_Index_REG[6] = {0xc90, 0xc91, 0xc92, 0xc98, 0xc99, 0xc9a};
  3841. for(index = 0; index< 6; index++)
  3842. //PlatformEFIOWrite1Byte(Adapter, Power_Index_REG[index], Value);
  3843. ODM_Write1Byte(pDM_Odm, Power_Index_REG[index], Value);
  3844. }
  3845. VOID
  3846. odm_DynamicTxPower(
  3847. IN PDM_ODM_T pDM_Odm
  3848. )
  3849. {
  3850. //
  3851. // For AP/ADSL use prtl8192cd_priv
  3852. // For CE/NIC use PADAPTER
  3853. //
  3854. //PADAPTER pAdapter = pDM_Odm->Adapter;
  3855. // prtl8192cd_priv priv = pDM_Odm->priv;
  3856. if (!(pDM_Odm->SupportAbility & ODM_BB_DYNAMIC_TXPWR))
  3857. return;
  3858. // 2012/01/12 MH According to Luke's suggestion, only high power will support the feature.
  3859. if (pDM_Odm->ExtPA == FALSE)
  3860. return;
  3861. //
  3862. // 2011/09/29 MH In HW integration first stage, we provide 4 different handle to operate
  3863. // at the same time. In the stage2/3, we need to prive universal interface and merge all
  3864. // HW dynamic mechanism.
  3865. //
  3866. switch (pDM_Odm->SupportPlatform)
  3867. {
  3868. case ODM_WIN:
  3869. case ODM_CE:
  3870. odm_DynamicTxPowerNIC(pDM_Odm);
  3871. break;
  3872. case ODM_AP:
  3873. odm_DynamicTxPowerAP(pDM_Odm);
  3874. break;
  3875. case ODM_ADSL:
  3876. //odm_DIGAP(pDM_Odm);
  3877. break;
  3878. }
  3879. }
  3880. VOID
  3881. odm_DynamicTxPowerNIC(
  3882. IN PDM_ODM_T pDM_Odm
  3883. )
  3884. {
  3885. if (!(pDM_Odm->SupportAbility & ODM_BB_DYNAMIC_TXPWR))
  3886. return;
  3887. #if (DM_ODM_SUPPORT_TYPE & (ODM_WIN|ODM_CE))
  3888. if(pDM_Odm->SupportICType == ODM_RTL8192C)
  3889. {
  3890. odm_DynamicTxPower_92C(pDM_Odm);
  3891. }
  3892. else if(pDM_Odm->SupportICType == ODM_RTL8192D)
  3893. {
  3894. odm_DynamicTxPower_92D(pDM_Odm);
  3895. }
  3896. else if (pDM_Odm->SupportICType & ODM_RTL8188E)
  3897. {
  3898. // Add Later.
  3899. }
  3900. else if (pDM_Odm->SupportICType == ODM_RTL8188E)
  3901. {
  3902. // ???
  3903. // This part need to be redefined.
  3904. }
  3905. #endif
  3906. }
  3907. VOID
  3908. odm_DynamicTxPowerAP(
  3909. IN PDM_ODM_T pDM_Odm
  3910. )
  3911. {
  3912. #if (DM_ODM_SUPPORT_TYPE == ODM_AP)
  3913. prtl8192cd_priv priv = pDM_Odm->priv;
  3914. s4Byte i;
  3915. if(!priv->pshare->rf_ft_var.tx_pwr_ctrl)
  3916. return;
  3917. #ifdef HIGH_POWER_EXT_PA
  3918. if(pDM_Odm->ExtPA)
  3919. tx_power_control(priv);
  3920. #endif
  3921. /*
  3922. * Check if station is near by to use lower tx power
  3923. */
  3924. if ((priv->up_time % 3) == 0 ) {
  3925. for(i=0; i<ODM_ASSOCIATE_ENTRY_NUM; i++){
  3926. PSTA_INFO_T pstat = pDM_Odm->pODM_StaInfo[i];
  3927. if(IS_STA_VALID(pstat) ) {
  3928. if ((pstat->hp_level == 0) && (pstat->rssi > TX_POWER_NEAR_FIELD_THRESH_AP+4))
  3929. pstat->hp_level = 1;
  3930. else if ((pstat->hp_level == 1) && (pstat->rssi < TX_POWER_NEAR_FIELD_THRESH_AP))
  3931. pstat->hp_level = 0;
  3932. }
  3933. }
  3934. }
  3935. #endif
  3936. }
  3937. VOID
  3938. odm_DynamicTxPower_92C(
  3939. IN PDM_ODM_T pDM_Odm
  3940. )
  3941. {
  3942. #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
  3943. PADAPTER Adapter = pDM_Odm->Adapter;
  3944. PMGNT_INFO pMgntInfo = &Adapter->MgntInfo;
  3945. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  3946. s4Byte UndecoratedSmoothedPWDB;
  3947. // STA not connected and AP not connected
  3948. if((!pMgntInfo->bMediaConnect) &&
  3949. (pHalData->EntryMinUndecoratedSmoothedPWDB == 0))
  3950. {
  3951. ODM_RT_TRACE(pDM_Odm,COMP_HIPWR, DBG_LOUD, ("Not connected to any \n"));
  3952. pHalData->DynamicTxHighPowerLvl = TxHighPwrLevel_Normal;
  3953. //the LastDTPlvl should reset when disconnect,
  3954. //otherwise the tx power level wouldn't change when disconnect and connect again.
  3955. // Maddest 20091220.
  3956. pHalData->LastDTPLvl=TxHighPwrLevel_Normal;
  3957. return;
  3958. }
  3959. #if (INTEL_PROXIMITY_SUPPORT == 1)
  3960. // Intel set fixed tx power
  3961. if(pMgntInfo->IntelProximityModeInfo.PowerOutput > 0)
  3962. {
  3963. switch(pMgntInfo->IntelProximityModeInfo.PowerOutput){
  3964. case 1:
  3965. pHalData->DynamicTxHighPowerLvl = TxHighPwrLevel_100;
  3966. ODM_RT_TRACE(pDM_Odm,COMP_HIPWR, DBG_LOUD, ("TxHighPwrLevel_100\n"));
  3967. break;
  3968. case 2:
  3969. pHalData->DynamicTxHighPowerLvl = TxHighPwrLevel_70;
  3970. ODM_RT_TRACE(pDM_Odm,COMP_HIPWR, DBG_LOUD, ("TxHighPwrLevel_70\n"));
  3971. break;
  3972. case 3:
  3973. pHalData->DynamicTxHighPowerLvl = TxHighPwrLevel_50;
  3974. ODM_RT_TRACE(pDM_Odm,COMP_HIPWR, DBG_LOUD, ("TxHighPwrLevel_50\n"));
  3975. break;
  3976. case 4:
  3977. pHalData->DynamicTxHighPowerLvl = TxHighPwrLevel_35;
  3978. ODM_RT_TRACE(pDM_Odm,COMP_HIPWR, DBG_LOUD, ("TxHighPwrLevel_35\n"));
  3979. break;
  3980. case 5:
  3981. pHalData->DynamicTxHighPowerLvl = TxHighPwrLevel_15;
  3982. ODM_RT_TRACE(pDM_Odm,COMP_HIPWR, DBG_LOUD, ("TxHighPwrLevel_15\n"));
  3983. break;
  3984. default:
  3985. pHalData->DynamicTxHighPowerLvl = TxHighPwrLevel_100;
  3986. ODM_RT_TRACE(pDM_Odm,COMP_HIPWR, DBG_LOUD, ("TxHighPwrLevel_100\n"));
  3987. break;
  3988. }
  3989. }
  3990. else
  3991. #endif
  3992. {
  3993. if( (pMgntInfo->bDynamicTxPowerEnable != TRUE) ||
  3994. (pHalData->DMFlag & HAL_DM_HIPWR_DISABLE) ||
  3995. pMgntInfo->IOTAction & HT_IOT_ACT_DISABLE_HIGH_POWER)
  3996. {
  3997. pHalData->DynamicTxHighPowerLvl = TxHighPwrLevel_Normal;
  3998. }
  3999. else
  4000. {
  4001. if(pMgntInfo->bMediaConnect) // Default port
  4002. {
  4003. if(ACTING_AS_AP(Adapter) || ACTING_AS_IBSS(Adapter))
  4004. {
  4005. UndecoratedSmoothedPWDB = pHalData->EntryMinUndecoratedSmoothedPWDB;
  4006. ODM_RT_TRACE(pDM_Odm,COMP_HIPWR, DBG_LOUD, ("AP Client PWDB = 0x%x \n", UndecoratedSmoothedPWDB));
  4007. }
  4008. else
  4009. {
  4010. UndecoratedSmoothedPWDB = pHalData->UndecoratedSmoothedPWDB;
  4011. ODM_RT_TRACE(pDM_Odm,COMP_HIPWR, DBG_LOUD, ("STA Default Port PWDB = 0x%x \n", UndecoratedSmoothedPWDB));
  4012. }
  4013. }
  4014. else // associated entry pwdb
  4015. {
  4016. UndecoratedSmoothedPWDB = pHalData->EntryMinUndecoratedSmoothedPWDB;
  4017. ODM_RT_TRACE(pDM_Odm,COMP_HIPWR, DBG_LOUD, ("AP Ext Port PWDB = 0x%x \n", UndecoratedSmoothedPWDB));
  4018. }
  4019. if(UndecoratedSmoothedPWDB >= TX_POWER_NEAR_FIELD_THRESH_LVL2)
  4020. {
  4021. pHalData->DynamicTxHighPowerLvl = TxHighPwrLevel_Level2;
  4022. ODM_RT_TRACE(pDM_Odm,COMP_HIPWR, DBG_LOUD, ("TxHighPwrLevel_Level1 (TxPwr=0x0)\n"));
  4023. }
  4024. else if((UndecoratedSmoothedPWDB < (TX_POWER_NEAR_FIELD_THRESH_LVL2-3)) &&
  4025. (UndecoratedSmoothedPWDB >= TX_POWER_NEAR_FIELD_THRESH_LVL1) )
  4026. {
  4027. pHalData->DynamicTxHighPowerLvl = TxHighPwrLevel_Level1;
  4028. ODM_RT_TRACE(pDM_Odm,COMP_HIPWR, DBG_LOUD, ("TxHighPwrLevel_Level1 (TxPwr=0x10)\n"));
  4029. }
  4030. else if(UndecoratedSmoothedPWDB < (TX_POWER_NEAR_FIELD_THRESH_LVL1-5))
  4031. {
  4032. pHalData->DynamicTxHighPowerLvl = TxHighPwrLevel_Normal;
  4033. ODM_RT_TRACE(pDM_Odm,COMP_HIPWR, DBG_LOUD, ("TxHighPwrLevel_Normal\n"));
  4034. }
  4035. }
  4036. }
  4037. if( pHalData->DynamicTxHighPowerLvl != pHalData->LastDTPLvl )
  4038. {
  4039. ODM_RT_TRACE(pDM_Odm,COMP_HIPWR, DBG_LOUD, ("PHY_SetTxPowerLevel8192C() Channel = %d \n" , pHalData->CurrentChannel));
  4040. PHY_SetTxPowerLevel8192C(Adapter, pHalData->CurrentChannel);
  4041. if( (pHalData->DynamicTxHighPowerLvl == TxHighPwrLevel_Normal) &&
  4042. (pHalData->LastDTPLvl == TxHighPwrLevel_Level1 || pHalData->LastDTPLvl == TxHighPwrLevel_Level2)) //TxHighPwrLevel_Normal
  4043. odm_DynamicTxPowerRestorePowerIndex(pDM_Odm);
  4044. else if(pHalData->DynamicTxHighPowerLvl == TxHighPwrLevel_Level1)
  4045. odm_DynamicTxPowerWritePowerIndex(pDM_Odm, 0x14);
  4046. else if(pHalData->DynamicTxHighPowerLvl == TxHighPwrLevel_Level2)
  4047. odm_DynamicTxPowerWritePowerIndex(pDM_Odm, 0x10);
  4048. }
  4049. pHalData->LastDTPLvl = pHalData->DynamicTxHighPowerLvl;
  4050. #elif (DM_ODM_SUPPORT_TYPE == ODM_CE)
  4051. #if (RTL8192C_SUPPORT==1)
  4052. PADAPTER Adapter = pDM_Odm->Adapter;
  4053. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  4054. struct dm_priv *pdmpriv = &pHalData->dmpriv;
  4055. struct mlme_priv *pmlmepriv = &(Adapter->mlmepriv);
  4056. struct mlme_ext_priv *pmlmeext = &Adapter->mlmeextpriv;
  4057. int UndecoratedSmoothedPWDB;
  4058. if(!pdmpriv->bDynamicTxPowerEnable)
  4059. return;
  4060. #ifdef CONFIG_INTEL_PROXIM
  4061. if(Adapter->proximity.proxim_on== _TRUE){
  4062. struct proximity_priv *prox_priv=Adapter->proximity.proximity_priv;
  4063. // Intel set fixed tx power
  4064. printk("\n %s Adapter->proximity.proxim_on=%d prox_priv->proxim_modeinfo->power_output=%d \n",__FUNCTION__,Adapter->proximity.proxim_on,prox_priv->proxim_modeinfo->power_output);
  4065. if(prox_priv!=NULL){
  4066. if(prox_priv->proxim_modeinfo->power_output> 0)
  4067. {
  4068. switch(prox_priv->proxim_modeinfo->power_output)
  4069. {
  4070. case 1:
  4071. pdmpriv->DynamicTxHighPowerLvl = TxHighPwrLevel_100;
  4072. printk("TxHighPwrLevel_100\n");
  4073. break;
  4074. case 2:
  4075. pdmpriv->DynamicTxHighPowerLvl = TxHighPwrLevel_70;
  4076. printk("TxHighPwrLevel_70\n");
  4077. break;
  4078. case 3:
  4079. pdmpriv->DynamicTxHighPowerLvl = TxHighPwrLevel_50;
  4080. printk("TxHighPwrLevel_50\n");
  4081. break;
  4082. case 4:
  4083. pdmpriv->DynamicTxHighPowerLvl = TxHighPwrLevel_35;
  4084. printk("TxHighPwrLevel_35\n");
  4085. break;
  4086. case 5:
  4087. pdmpriv->DynamicTxHighPowerLvl = TxHighPwrLevel_15;
  4088. printk("TxHighPwrLevel_15\n");
  4089. break;
  4090. default:
  4091. pdmpriv->DynamicTxHighPowerLvl = TxHighPwrLevel_100;
  4092. printk("TxHighPwrLevel_100\n");
  4093. break;
  4094. }
  4095. }
  4096. }
  4097. }
  4098. else
  4099. #endif
  4100. {
  4101. // STA not connected and AP not connected
  4102. if((check_fwstate(pmlmepriv, _FW_LINKED) != _TRUE) &&
  4103. (pdmpriv->EntryMinUndecoratedSmoothedPWDB == 0))
  4104. {
  4105. //ODM_RT_TRACE(pDM_Odm,COMP_HIPWR, DBG_LOUD, ("Not connected to any \n"));
  4106. pdmpriv->DynamicTxHighPowerLvl = TxHighPwrLevel_Normal;
  4107. //the LastDTPlvl should reset when disconnect,
  4108. //otherwise the tx power level wouldn't change when disconnect and connect again.
  4109. // Maddest 20091220.
  4110. pdmpriv->LastDTPLvl=TxHighPwrLevel_Normal;
  4111. return;
  4112. }
  4113. if(check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE) // Default port
  4114. {
  4115. #if 0
  4116. //todo: AP Mode
  4117. if ((check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == _TRUE) ||
  4118. (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) == _TRUE))
  4119. {
  4120. UndecoratedSmoothedPWDB = pdmpriv->EntryMinUndecoratedSmoothedPWDB;
  4121. //ODM_RT_TRACE(pDM_Odm,COMP_HIPWR, DBG_LOUD, ("AP Client PWDB = 0x%x \n", UndecoratedSmoothedPWDB));
  4122. }
  4123. else
  4124. {
  4125. UndecoratedSmoothedPWDB = pdmpriv->UndecoratedSmoothedPWDB;
  4126. //ODM_RT_TRACE(pDM_Odm,COMP_HIPWR, DBG_LOUD, ("STA Default Port PWDB = 0x%x \n", UndecoratedSmoothedPWDB));
  4127. }
  4128. #else
  4129. UndecoratedSmoothedPWDB = pdmpriv->EntryMinUndecoratedSmoothedPWDB;
  4130. #endif
  4131. }
  4132. else // associated entry pwdb
  4133. {
  4134. UndecoratedSmoothedPWDB = pdmpriv->EntryMinUndecoratedSmoothedPWDB;
  4135. //ODM_RT_TRACE(pDM_Odm,COMP_HIPWR, DBG_LOUD, ("AP Ext Port PWDB = 0x%x \n", UndecoratedSmoothedPWDB));
  4136. }
  4137. if(UndecoratedSmoothedPWDB >= TX_POWER_NEAR_FIELD_THRESH_LVL2)
  4138. {
  4139. pdmpriv->DynamicTxHighPowerLvl = TxHighPwrLevel_Level2;
  4140. //ODM_RT_TRACE(pDM_Odm,COMP_HIPWR, DBG_LOUD, ("TxHighPwrLevel_Level1 (TxPwr=0x0)\n"));
  4141. }
  4142. else if((UndecoratedSmoothedPWDB < (TX_POWER_NEAR_FIELD_THRESH_LVL2-3)) &&
  4143. (UndecoratedSmoothedPWDB >= TX_POWER_NEAR_FIELD_THRESH_LVL1) )
  4144. {
  4145. pdmpriv->DynamicTxHighPowerLvl = TxHighPwrLevel_Level1;
  4146. //ODM_RT_TRACE(pDM_Odm,COMP_HIPWR, DBG_LOUD, ("TxHighPwrLevel_Level1 (TxPwr=0x10)\n"));
  4147. }
  4148. else if(UndecoratedSmoothedPWDB < (TX_POWER_NEAR_FIELD_THRESH_LVL1-5))
  4149. {
  4150. pdmpriv->DynamicTxHighPowerLvl = TxHighPwrLevel_Normal;
  4151. //ODM_RT_TRACE(pDM_Odm,COMP_HIPWR, DBG_LOUD, ("TxHighPwrLevel_Normal\n"));
  4152. }
  4153. }
  4154. if( (pdmpriv->DynamicTxHighPowerLvl != pdmpriv->LastDTPLvl) )
  4155. {
  4156. PHY_SetTxPowerLevel8192C(Adapter, pHalData->CurrentChannel);
  4157. if(pdmpriv->DynamicTxHighPowerLvl == TxHighPwrLevel_Normal) // HP1 -> Normal or HP2 -> Normal
  4158. odm_DynamicTxPowerRestorePowerIndex(pDM_Odm);
  4159. else if(pdmpriv->DynamicTxHighPowerLvl == TxHighPwrLevel_Level1)
  4160. odm_DynamicTxPowerWritePowerIndex(pDM_Odm, 0x14);
  4161. else if(pdmpriv->DynamicTxHighPowerLvl == TxHighPwrLevel_Level2)
  4162. odm_DynamicTxPowerWritePowerIndex(pDM_Odm, 0x10);
  4163. }
  4164. pdmpriv->LastDTPLvl = pdmpriv->DynamicTxHighPowerLvl;
  4165. #endif
  4166. #endif // #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
  4167. }
  4168. VOID
  4169. odm_DynamicTxPower_92D(
  4170. IN PDM_ODM_T pDM_Odm
  4171. )
  4172. {
  4173. #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
  4174. PADAPTER Adapter = pDM_Odm->Adapter;
  4175. PMGNT_INFO pMgntInfo = &Adapter->MgntInfo;
  4176. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  4177. s4Byte UndecoratedSmoothedPWDB;
  4178. PADAPTER BuddyAdapter = Adapter->BuddyAdapter;
  4179. BOOLEAN bGetValueFromBuddyAdapter = dm_DualMacGetParameterFromBuddyAdapter(Adapter);
  4180. u1Byte HighPowerLvlBackForMac0 = TxHighPwrLevel_Level1;
  4181. // If dynamic high power is disabled.
  4182. if( (pMgntInfo->bDynamicTxPowerEnable != TRUE) ||
  4183. (pHalData->DMFlag & HAL_DM_HIPWR_DISABLE) ||
  4184. pMgntInfo->IOTAction & HT_IOT_ACT_DISABLE_HIGH_POWER)
  4185. {
  4186. pHalData->DynamicTxHighPowerLvl = TxHighPwrLevel_Normal;
  4187. return;
  4188. }
  4189. // STA not connected and AP not connected
  4190. if((!pMgntInfo->bMediaConnect) &&
  4191. (pHalData->EntryMinUndecoratedSmoothedPWDB == 0))
  4192. {
  4193. ODM_RT_TRACE(pDM_Odm,COMP_HIPWR, DBG_LOUD, ("Not connected to any \n"));
  4194. pHalData->DynamicTxHighPowerLvl = TxHighPwrLevel_Normal;
  4195. //the LastDTPlvl should reset when disconnect,
  4196. //otherwise the tx power level wouldn't change when disconnect and connect again.
  4197. // Maddest 20091220.
  4198. pHalData->LastDTPLvl=TxHighPwrLevel_Normal;
  4199. return;
  4200. }
  4201. if(pMgntInfo->bMediaConnect) // Default port
  4202. {
  4203. if(ACTING_AS_AP(Adapter) || pMgntInfo->mIbss)
  4204. {
  4205. UndecoratedSmoothedPWDB = pHalData->EntryMinUndecoratedSmoothedPWDB;
  4206. ODM_RT_TRACE(pDM_Odm,COMP_HIPWR, DBG_LOUD, ("AP Client PWDB = 0x%x \n", UndecoratedSmoothedPWDB));
  4207. }
  4208. else
  4209. {
  4210. UndecoratedSmoothedPWDB = pHalData->UndecoratedSmoothedPWDB;
  4211. ODM_RT_TRACE(pDM_Odm,COMP_HIPWR, DBG_LOUD, ("STA Default Port PWDB = 0x%x \n", UndecoratedSmoothedPWDB));
  4212. }
  4213. }
  4214. else // associated entry pwdb
  4215. {
  4216. UndecoratedSmoothedPWDB = pHalData->EntryMinUndecoratedSmoothedPWDB;
  4217. ODM_RT_TRACE(pDM_Odm,COMP_HIPWR, DBG_LOUD, ("AP Ext Port PWDB = 0x%x \n", UndecoratedSmoothedPWDB));
  4218. }
  4219. if(IS_HARDWARE_TYPE_8192D(Adapter) && GET_HAL_DATA(Adapter)->CurrentBandType == 1){
  4220. if(UndecoratedSmoothedPWDB >= 0x33)
  4221. {
  4222. pHalData->DynamicTxHighPowerLvl = TxHighPwrLevel_Level2;
  4223. ODM_RT_TRACE(pDM_Odm,COMP_HIPWR, DBG_LOUD, ("5G:TxHighPwrLevel_Level2 (TxPwr=0x0)\n"));
  4224. }
  4225. else if((UndecoratedSmoothedPWDB <0x33) &&
  4226. (UndecoratedSmoothedPWDB >= 0x2b) )
  4227. {
  4228. pHalData->DynamicTxHighPowerLvl = TxHighPwrLevel_Level1;
  4229. ODM_RT_TRACE(pDM_Odm,COMP_HIPWR, DBG_LOUD, ("5G:TxHighPwrLevel_Level1 (TxPwr=0x10)\n"));
  4230. }
  4231. else if(UndecoratedSmoothedPWDB < 0x2b)
  4232. {
  4233. pHalData->DynamicTxHighPowerLvl = TxHighPwrLevel_Normal;
  4234. ODM_RT_TRACE(pDM_Odm,COMP_HIPWR, DBG_LOUD, ("5G:TxHighPwrLevel_Normal\n"));
  4235. }
  4236. }
  4237. else
  4238. {
  4239. if(UndecoratedSmoothedPWDB >= TX_POWER_NEAR_FIELD_THRESH_LVL2)
  4240. {
  4241. pHalData->DynamicTxHighPowerLvl = TxHighPwrLevel_Level1;
  4242. ODM_RT_TRACE(pDM_Odm,COMP_HIPWR, DBG_LOUD, ("TxHighPwrLevel_Level1 (TxPwr=0x0)\n"));
  4243. }
  4244. else if((UndecoratedSmoothedPWDB < (TX_POWER_NEAR_FIELD_THRESH_LVL2-3)) &&
  4245. (UndecoratedSmoothedPWDB >= TX_POWER_NEAR_FIELD_THRESH_LVL1) )
  4246. {
  4247. pHalData->DynamicTxHighPowerLvl = TxHighPwrLevel_Level1;
  4248. ODM_RT_TRACE(pDM_Odm,COMP_HIPWR, DBG_LOUD, ("TxHighPwrLevel_Level1 (TxPwr=0x10)\n"));
  4249. }
  4250. else if(UndecoratedSmoothedPWDB < (TX_POWER_NEAR_FIELD_THRESH_LVL1-5))
  4251. {
  4252. pHalData->DynamicTxHighPowerLvl = TxHighPwrLevel_Normal;
  4253. ODM_RT_TRACE(pDM_Odm,COMP_HIPWR, DBG_LOUD, ("TxHighPwrLevel_Normal\n"));
  4254. }
  4255. }
  4256. //sherry delete flag 20110517
  4257. if(bGetValueFromBuddyAdapter)
  4258. {
  4259. ODM_RT_TRACE(pDM_Odm,COMP_MLME,DBG_LOUD,("dm_DynamicTxPower() mac 0 for mac 1 \n"));
  4260. if(Adapter->DualMacDMSPControl.bChangeTxHighPowerLvlForAnotherMacOfDMSP)
  4261. {
  4262. ODM_RT_TRACE(pDM_Odm,COMP_MLME,DBG_LOUD,("dm_DynamicTxPower() change value \n"));
  4263. HighPowerLvlBackForMac0 = pHalData->DynamicTxHighPowerLvl;
  4264. pHalData->DynamicTxHighPowerLvl = Adapter->DualMacDMSPControl.CurTxHighLvlForAnotherMacOfDMSP;
  4265. PHY_SetTxPowerLevel8192C(Adapter, pHalData->CurrentChannel);
  4266. pHalData->DynamicTxHighPowerLvl = HighPowerLvlBackForMac0;
  4267. Adapter->DualMacDMSPControl.bChangeTxHighPowerLvlForAnotherMacOfDMSP = FALSE;
  4268. }
  4269. }
  4270. if( (pHalData->DynamicTxHighPowerLvl != pHalData->LastDTPLvl) )
  4271. {
  4272. ODM_RT_TRACE(pDM_Odm,COMP_HIPWR, DBG_LOUD, ("PHY_SetTxPowerLevel8192S() Channel = %d \n" , pHalData->CurrentChannel));
  4273. if(Adapter->DualMacSmartConcurrent == TRUE)
  4274. {
  4275. if(BuddyAdapter == NULL)
  4276. {
  4277. ODM_RT_TRACE(pDM_Odm,COMP_MLME,DBG_LOUD,("dm_DynamicTxPower() BuddyAdapter == NULL case \n"));
  4278. if(!Adapter->bSlaveOfDMSP)
  4279. {
  4280. PHY_SetTxPowerLevel8192C(Adapter, pHalData->CurrentChannel);
  4281. }
  4282. }
  4283. else
  4284. {
  4285. if(pHalData->MacPhyMode92D == DUALMAC_SINGLEPHY)
  4286. {
  4287. ODM_RT_TRACE(pDM_Odm,COMP_MLME,DBG_LOUD,("dm_DynamicTxPower() BuddyAdapter DMSP \n"));
  4288. if(Adapter->bSlaveOfDMSP)
  4289. {
  4290. ODM_RT_TRACE(pDM_Odm,COMP_MLME,DBG_LOUD,("dm_DynamicTxPower() bslave case \n"));
  4291. BuddyAdapter->DualMacDMSPControl.bChangeTxHighPowerLvlForAnotherMacOfDMSP = TRUE;
  4292. BuddyAdapter->DualMacDMSPControl.CurTxHighLvlForAnotherMacOfDMSP = pHalData->DynamicTxHighPowerLvl;
  4293. }
  4294. else
  4295. {
  4296. ODM_RT_TRACE(pDM_Odm,COMP_MLME,DBG_LOUD,("dm_DynamicTxPower() master case \n"));
  4297. if(!bGetValueFromBuddyAdapter)
  4298. {
  4299. ODM_RT_TRACE(pDM_Odm,COMP_MLME,DBG_LOUD,("dm_DynamicTxPower() mac 0 for mac 0 \n"));
  4300. PHY_SetTxPowerLevel8192C(Adapter, pHalData->CurrentChannel);
  4301. }
  4302. }
  4303. }
  4304. else
  4305. {
  4306. ODM_RT_TRACE(pDM_Odm,COMP_MLME,DBG_LOUD,("dm_DynamicTxPower() BuddyAdapter DMDP\n"));
  4307. PHY_SetTxPowerLevel8192C(Adapter, pHalData->CurrentChannel);
  4308. }
  4309. }
  4310. }
  4311. else
  4312. {
  4313. PHY_SetTxPowerLevel8192C(Adapter, pHalData->CurrentChannel);
  4314. }
  4315. }
  4316. pHalData->LastDTPLvl = pHalData->DynamicTxHighPowerLvl;
  4317. #elif (DM_ODM_SUPPORT_TYPE == ODM_CE)
  4318. #if (RTL8192D_SUPPORT==1)
  4319. PADAPTER Adapter = pDM_Odm->Adapter;
  4320. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  4321. struct mlme_priv *pmlmepriv = &(Adapter->mlmepriv);
  4322. struct dm_priv *pdmpriv = &pHalData->dmpriv;
  4323. DM_ODM_T *podmpriv = &pHalData->odmpriv;
  4324. int UndecoratedSmoothedPWDB;
  4325. #if (RTL8192D_EASY_SMART_CONCURRENT == 1)
  4326. PADAPTER BuddyAdapter = Adapter->BuddyAdapter;
  4327. BOOLEAN bGetValueFromBuddyAdapter = DualMacGetParameterFromBuddyAdapter(Adapter);
  4328. u8 HighPowerLvlBackForMac0 = TxHighPwrLevel_Level1;
  4329. #endif
  4330. // If dynamic high power is disabled.
  4331. if( (pdmpriv->bDynamicTxPowerEnable != _TRUE) ||
  4332. (!(podmpriv->SupportAbility& ODM_BB_DYNAMIC_TXPWR)) )
  4333. {
  4334. pdmpriv->DynamicTxHighPowerLvl = TxHighPwrLevel_Normal;
  4335. return;
  4336. }
  4337. // STA not connected and AP not connected
  4338. if((check_fwstate(pmlmepriv, _FW_LINKED) != _TRUE) &&
  4339. (pdmpriv->EntryMinUndecoratedSmoothedPWDB == 0))
  4340. {
  4341. //ODM_RT_TRACE(pDM_Odm,COMP_HIPWR, DBG_LOUD, ("Not connected to any \n"));
  4342. pdmpriv->DynamicTxHighPowerLvl = TxHighPwrLevel_Normal;
  4343. //the LastDTPlvl should reset when disconnect,
  4344. //otherwise the tx power level wouldn't change when disconnect and connect again.
  4345. // Maddest 20091220.
  4346. pdmpriv->LastDTPLvl=TxHighPwrLevel_Normal;
  4347. return;
  4348. }
  4349. if(check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE) // Default port
  4350. {
  4351. #if 0
  4352. //todo: AP Mode
  4353. if ((check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == _TRUE) ||
  4354. (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) == _TRUE))
  4355. {
  4356. UndecoratedSmoothedPWDB = pdmpriv->EntryMinUndecoratedSmoothedPWDB;
  4357. //ODM_RT_TRACE(pDM_Odm,COMP_HIPWR, DBG_LOUD, ("AP Client PWDB = 0x%x \n", UndecoratedSmoothedPWDB));
  4358. }
  4359. else
  4360. {
  4361. UndecoratedSmoothedPWDB = pdmpriv->UndecoratedSmoothedPWDB;
  4362. //ODM_RT_TRACE(pDM_Odm,COMP_HIPWR, DBG_LOUD, ("STA Default Port PWDB = 0x%x \n", UndecoratedSmoothedPWDB));
  4363. }
  4364. #else
  4365. UndecoratedSmoothedPWDB = pdmpriv->EntryMinUndecoratedSmoothedPWDB;
  4366. #endif
  4367. }
  4368. else // associated entry pwdb
  4369. {
  4370. UndecoratedSmoothedPWDB = pdmpriv->EntryMinUndecoratedSmoothedPWDB;
  4371. //ODM_RT_TRACE(pDM_Odm,COMP_HIPWR, DBG_LOUD, ("AP Ext Port PWDB = 0x%x \n", UndecoratedSmoothedPWDB));
  4372. }
  4373. #if TX_POWER_FOR_5G_BAND == 1
  4374. if(pHalData->CurrentBandType92D == BAND_ON_5G){
  4375. if(UndecoratedSmoothedPWDB >= 0x33)
  4376. {
  4377. pdmpriv->DynamicTxHighPowerLvl = TxHighPwrLevel_Level2;
  4378. //ODM_RT_TRACE(pDM_Odm,COMP_HIPWR, DBG_LOUD, ("5G:TxHighPwrLevel_Level2 (TxPwr=0x0)\n"));
  4379. }
  4380. else if((UndecoratedSmoothedPWDB <0x33) &&
  4381. (UndecoratedSmoothedPWDB >= 0x2b) )
  4382. {
  4383. pdmpriv->DynamicTxHighPowerLvl = TxHighPwrLevel_Level1;
  4384. //ODM_RT_TRACE(pDM_Odm,COMP_HIPWR, DBG_LOUD, ("5G:TxHighPwrLevel_Level1 (TxPwr=0x10)\n"));
  4385. }
  4386. else if(UndecoratedSmoothedPWDB < 0x2b)
  4387. {
  4388. pdmpriv->DynamicTxHighPowerLvl = TxHighPwrLevel_Normal;
  4389. //ODM_RT_TRACE(pDM_Odm,COMP_HIPWR, DBG_LOUD, ("5G:TxHighPwrLevel_Normal\n"));
  4390. }
  4391. }
  4392. else
  4393. #endif
  4394. {
  4395. if(UndecoratedSmoothedPWDB >= TX_POWER_NEAR_FIELD_THRESH_LVL2)
  4396. {
  4397. pdmpriv->DynamicTxHighPowerLvl = TxHighPwrLevel_Level2;
  4398. //ODM_RT_TRACE(pDM_Odm,COMP_HIPWR, DBG_LOUD, ("TxHighPwrLevel_Level1 (TxPwr=0x0)\n"));
  4399. }
  4400. else if((UndecoratedSmoothedPWDB < (TX_POWER_NEAR_FIELD_THRESH_LVL2-3)) &&
  4401. (UndecoratedSmoothedPWDB >= TX_POWER_NEAR_FIELD_THRESH_LVL1) )
  4402. {
  4403. pdmpriv->DynamicTxHighPowerLvl = TxHighPwrLevel_Level1;
  4404. //ODM_RT_TRACE(pDM_Odm,COMP_HIPWR, DBG_LOUD, ("TxHighPwrLevel_Level1 (TxPwr=0x10)\n"));
  4405. }
  4406. else if(UndecoratedSmoothedPWDB < (TX_POWER_NEAR_FIELD_THRESH_LVL1-5))
  4407. {
  4408. pdmpriv->DynamicTxHighPowerLvl = TxHighPwrLevel_Normal;
  4409. //ODM_RT_TRACE(pDM_Odm,COMP_HIPWR, DBG_LOUD, ("TxHighPwrLevel_Normal\n"));
  4410. }
  4411. }
  4412. #if (RTL8192D_EASY_SMART_CONCURRENT == 1)
  4413. if(bGetValueFromBuddyAdapter)
  4414. {
  4415. //ODM_RT_TRACE(pDM_Odm,COMP_MLME,DBG_LOUD,("dm_DynamicTxPower() mac 0 for mac 1 \n"));
  4416. if(Adapter->DualMacDMSPControl.bChangeTxHighPowerLvlForAnotherMacOfDMSP)
  4417. {
  4418. //ODM_RT_TRACE(pDM_Odm,COMP_MLME,DBG_LOUD,("dm_DynamicTxPower() change value \n"));
  4419. HighPowerLvlBackForMac0 = pHalData->DynamicTxHighPowerLvl;
  4420. pHalData->DynamicTxHighPowerLvl = Adapter->DualMacDMSPControl.CurTxHighLvlForAnotherMacOfDMSP;
  4421. PHY_SetTxPowerLevel8192D(Adapter, pHalData->CurrentChannel);
  4422. pHalData->DynamicTxHighPowerLvl = HighPowerLvlBackForMac0;
  4423. Adapter->DualMacDMSPControl.bChangeTxHighPowerLvlForAnotherMacOfDMSP = _FALSE;
  4424. }
  4425. }
  4426. #endif
  4427. if( (pdmpriv->DynamicTxHighPowerLvl != pdmpriv->LastDTPLvl) )
  4428. {
  4429. //ODM_RT_TRACE(pDM_Odm,COMP_HIPWR, DBG_LOUD, ("PHY_SetTxPowerLevel8192S() Channel = %d \n" , pHalData->CurrentChannel));
  4430. #if (RTL8192D_EASY_SMART_CONCURRENT == 1)
  4431. if(BuddyAdapter == NULL)
  4432. {
  4433. //ODM_RT_TRACE(pDM_Odm,COMP_MLME,DBG_LOUD,("dm_DynamicTxPower() BuddyAdapter == NULL case \n"));
  4434. if(!Adapter->bSlaveOfDMSP)
  4435. {
  4436. PHY_SetTxPowerLevel8192D(Adapter, pHalData->CurrentChannel);
  4437. }
  4438. }
  4439. else
  4440. {
  4441. if(pHalData->MacPhyMode92D == DUALMAC_SINGLEPHY)
  4442. {
  4443. //ODM_RT_TRACE(pDM_Odm,COMP_MLME,DBG_LOUD,("dm_DynamicTxPower() BuddyAdapter DMSP \n"));
  4444. if(Adapter->bSlaveOfDMSP)
  4445. {
  4446. //ODM_RT_TRACE(pDM_Odm,COMP_MLME,DBG_LOUD,("dm_DynamicTxPower() bslave case \n"));
  4447. BuddyAdapter->DualMacDMSPControl.bChangeTxHighPowerLvlForAnotherMacOfDMSP = _TRUE;
  4448. BuddyAdapter->DualMacDMSPControl.CurTxHighLvlForAnotherMacOfDMSP = pHalData->DynamicTxHighPowerLvl;
  4449. }
  4450. else
  4451. {
  4452. //ODM_RT_TRACE(pDM_Odm,COMP_MLME,DBG_LOUD,("dm_DynamicTxPower() master case \n"));
  4453. if(!bGetValueFromBuddyAdapter)
  4454. {
  4455. //ODM_RT_TRACE(pDM_Odm,COMP_MLME,DBG_LOUD,("dm_DynamicTxPower() mac 0 for mac 0 \n"));
  4456. PHY_SetTxPowerLevel8192D(Adapter, pHalData->CurrentChannel);
  4457. }
  4458. }
  4459. }
  4460. else
  4461. {
  4462. //ODM_RT_TRACE(pDM_Odm,COMP_MLME,DBG_LOUD,("dm_DynamicTxPower() BuddyAdapter DMDP\n"));
  4463. PHY_SetTxPowerLevel8192D(Adapter, pHalData->CurrentChannel);
  4464. }
  4465. }
  4466. #else
  4467. PHY_SetTxPowerLevel8192D(Adapter, pHalData->CurrentChannel);
  4468. #endif
  4469. }
  4470. pdmpriv->LastDTPLvl = pdmpriv->DynamicTxHighPowerLvl;
  4471. #endif
  4472. #endif // #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
  4473. }
  4474. //3============================================================
  4475. //3 RSSI Monitor
  4476. //3============================================================
  4477. VOID
  4478. odm_RSSIDumpToRegister(
  4479. IN PDM_ODM_T pDM_Odm
  4480. )
  4481. {
  4482. #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
  4483. PADAPTER Adapter = pDM_Odm->Adapter;
  4484. if(pDM_Odm->SupportICType == ODM_RTL8812)
  4485. {
  4486. PlatformEFIOWrite1Byte(Adapter, rA_RSSIDump_Jaguar, Adapter->RxStats.RxRSSIPercentage[0]);
  4487. PlatformEFIOWrite1Byte(Adapter, rB_RSSIDump_Jaguar, Adapter->RxStats.RxRSSIPercentage[1]);
  4488. // Rx EVM
  4489. PlatformEFIOWrite1Byte(Adapter, rS1_RXevmDump_Jaguar, Adapter->RxStats.RxEVMdbm[0]);
  4490. PlatformEFIOWrite1Byte(Adapter, rS2_RXevmDump_Jaguar, Adapter->RxStats.RxEVMdbm[1]);
  4491. // Rx SNR
  4492. PlatformEFIOWrite1Byte(Adapter, rA_RXsnrDump_Jaguar, (u1Byte)(Adapter->RxStats.RxSNRdB[0]));
  4493. PlatformEFIOWrite1Byte(Adapter, rB_RXsnrDump_Jaguar, (u1Byte)(Adapter->RxStats.RxSNRdB[1]));
  4494. // Rx Cfo_Short
  4495. PlatformEFIOWrite2Byte(Adapter, rA_CfoShortDump_Jaguar, Adapter->RxStats.RxCfoShort[0]);
  4496. PlatformEFIOWrite2Byte(Adapter, rB_CfoShortDump_Jaguar, Adapter->RxStats.RxCfoShort[1]);
  4497. // Rx Cfo_Tail
  4498. PlatformEFIOWrite2Byte(Adapter, rA_CfoLongDump_Jaguar, Adapter->RxStats.RxCfoTail[0]);
  4499. PlatformEFIOWrite2Byte(Adapter, rB_CfoLongDump_Jaguar, Adapter->RxStats.RxCfoTail[1]);
  4500. }
  4501. else if(pDM_Odm->SupportICType == ODM_RTL8192E)
  4502. {
  4503. PlatformEFIOWrite1Byte(Adapter, rA_RSSIDump_92E, Adapter->RxStats.RxRSSIPercentage[0]);
  4504. PlatformEFIOWrite1Byte(Adapter, rB_RSSIDump_92E, Adapter->RxStats.RxRSSIPercentage[1]);
  4505. // Rx EVM
  4506. PlatformEFIOWrite1Byte(Adapter, rS1_RXevmDump_92E, Adapter->RxStats.RxEVMdbm[0]);
  4507. PlatformEFIOWrite1Byte(Adapter, rS2_RXevmDump_92E, Adapter->RxStats.RxEVMdbm[1]);
  4508. // Rx SNR
  4509. PlatformEFIOWrite1Byte(Adapter, rA_RXsnrDump_92E, (u1Byte)(Adapter->RxStats.RxSNRdB[0]));
  4510. PlatformEFIOWrite1Byte(Adapter, rB_RXsnrDump_92E, (u1Byte)(Adapter->RxStats.RxSNRdB[1]));
  4511. // Rx Cfo_Short
  4512. PlatformEFIOWrite2Byte(Adapter, rA_CfoShortDump_92E, Adapter->RxStats.RxCfoShort[0]);
  4513. PlatformEFIOWrite2Byte(Adapter, rB_CfoShortDump_92E, Adapter->RxStats.RxCfoShort[1]);
  4514. // Rx Cfo_Tail
  4515. PlatformEFIOWrite2Byte(Adapter, rA_CfoLongDump_92E, Adapter->RxStats.RxCfoTail[0]);
  4516. PlatformEFIOWrite2Byte(Adapter, rB_CfoLongDump_92E, Adapter->RxStats.RxCfoTail[1]);
  4517. }
  4518. #endif
  4519. }
  4520. VOID
  4521. odm_RSSIMonitorInit(
  4522. IN PDM_ODM_T pDM_Odm
  4523. )
  4524. {
  4525. }
  4526. VOID
  4527. odm_RSSIMonitorCheck(
  4528. IN PDM_ODM_T pDM_Odm
  4529. )
  4530. {
  4531. //
  4532. // For AP/ADSL use prtl8192cd_priv
  4533. // For CE/NIC use PADAPTER
  4534. //
  4535. if (!(pDM_Odm->SupportAbility & ODM_BB_RSSI_MONITOR))
  4536. return;
  4537. //
  4538. // 2011/09/29 MH In HW integration first stage, we provide 4 different handle to operate
  4539. // at the same time. In the stage2/3, we need to prive universal interface and merge all
  4540. // HW dynamic mechanism.
  4541. //
  4542. switch (pDM_Odm->SupportPlatform)
  4543. {
  4544. case ODM_WIN:
  4545. odm_RSSIMonitorCheckMP(pDM_Odm);
  4546. break;
  4547. case ODM_CE:
  4548. odm_RSSIMonitorCheckCE(pDM_Odm);
  4549. break;
  4550. case ODM_AP:
  4551. odm_RSSIMonitorCheckAP(pDM_Odm);
  4552. break;
  4553. case ODM_ADSL:
  4554. //odm_DIGAP(pDM_Odm);
  4555. break;
  4556. }
  4557. } // odm_RSSIMonitorCheck
  4558. VOID
  4559. odm_RSSIMonitorCheckMP(
  4560. IN PDM_ODM_T pDM_Odm
  4561. )
  4562. {
  4563. #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
  4564. PADAPTER Adapter = pDM_Odm->Adapter;
  4565. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  4566. PRT_WLAN_STA pEntry;
  4567. u1Byte i;
  4568. s4Byte tmpEntryMaxPWDB=0, tmpEntryMinPWDB=0xff;
  4569. u1Byte H2C_Parameter[4] ={0};
  4570. PMGNT_INFO pMgntInfo = &Adapter->MgntInfo;
  4571. u8Byte curTxOkCnt = 0;
  4572. u8Byte curRxOkCnt = 0;
  4573. BEAMFORMING_CAP Beamform_cap = BEAMFORMING_CAP_NONE;
  4574. u1Byte TxBF_EN = 0;
  4575. RT_DISP(FDM, DM_PWDB, ("pHalData->UndecoratedSmoothedPWDB = 0x%x( %d)\n",
  4576. pHalData->UndecoratedSmoothedPWDB,
  4577. pHalData->UndecoratedSmoothedPWDB));
  4578. curTxOkCnt = Adapter->TxStats.NumTxBytesUnicast - pMgntInfo->lastTxOkCnt;
  4579. curRxOkCnt = Adapter->RxStats.NumRxBytesUnicast - pMgntInfo->lastRxOkCnt;
  4580. pMgntInfo->lastTxOkCnt = curTxOkCnt;
  4581. pMgntInfo->lastRxOkCnt = curRxOkCnt;
  4582. RT_DISP(FDM, DM_PWDB, ("Tx = %d Rx = %d\n", curTxOkCnt, curRxOkCnt));
  4583. if(pDM_Odm->SupportICType == ODM_RTL8188E && (pMgntInfo->CustomerID==RT_CID_819x_HP))
  4584. {
  4585. if(curRxOkCnt >(curTxOkCnt*6))
  4586. {
  4587. PlatformEFIOWrite4Byte(Adapter, REG_ARFR0, 0x8f015);
  4588. }
  4589. else
  4590. {
  4591. PlatformEFIOWrite4Byte(Adapter, REG_ARFR0, 0xff015);
  4592. }
  4593. }
  4594. if((pDM_Odm->SupportICType == ODM_RTL8812) || pDM_Odm->SupportICType == ODM_RTL8821)
  4595. {
  4596. if(curRxOkCnt >(curTxOkCnt*6))
  4597. H2C_Parameter[3]=0x01;
  4598. else
  4599. H2C_Parameter[3]=0x00;
  4600. }
  4601. if(pDM_Odm->SupportICType == ODM_RTL8192E || pDM_Odm->SupportICType == ODM_RTL8812)
  4602. {
  4603. u1Byte STBC_TX = 0;
  4604. PRT_HIGH_THROUGHPUT pHTInfo = GET_HT_INFO(pMgntInfo);
  4605. PRT_VERY_HIGH_THROUGHPUT pVHTInfo = GET_VHT_INFO(pMgntInfo);
  4606. if(IS_WIRELESS_MODE_AC_5G(Adapter))
  4607. STBC_TX = TEST_FLAG(pVHTInfo->VhtCurStbc, STBC_VHT_ENABLE_TX);
  4608. else
  4609. STBC_TX = TEST_FLAG(pHTInfo->HtCurStbc, STBC_HT_ENABLE_TX);
  4610. H2C_Parameter[3] |= STBC_TX<<1;
  4611. }
  4612. for(i = 0; i < ODM_ASSOCIATE_ENTRY_NUM; i++)
  4613. {
  4614. if(IsAPModeExist(Adapter) && GetFirstExtAdapter(Adapter) != NULL)
  4615. {
  4616. pEntry = AsocEntry_EnumStation(GetFirstExtAdapter(Adapter), i);
  4617. }
  4618. else
  4619. {
  4620. pEntry = AsocEntry_EnumStation(GetDefaultAdapter(Adapter), i);
  4621. }
  4622. if(pEntry!=NULL)
  4623. {
  4624. if(pEntry->bAssociated)
  4625. {
  4626. RT_DISP_ADDR(FDM, DM_PWDB, ("pEntry->MacAddr ="), pEntry->MacAddr);
  4627. RT_DISP(FDM, DM_PWDB, ("pEntry->rssi = 0x%x(%d)\n",
  4628. pEntry->rssi_stat.UndecoratedSmoothedPWDB,
  4629. pEntry->rssi_stat.UndecoratedSmoothedPWDB));
  4630. if(pDM_Odm->SupportICType == ODM_RTL8192E)
  4631. {
  4632. Beamform_cap = Beamforming_GetEntryBeamCapByMacId(pMgntInfo, pEntry->AssociatedMacId);
  4633. if(Beamform_cap == BEAMFORMER_CAP_HT_EXPLICIT || Beamform_cap == BEAMFORMER_CAP_VHT_SU ||
  4634. Beamform_cap == (BEAMFORMER_CAP_HT_EXPLICIT|BEAMFORMEE_CAP_HT_EXPLICIT) ||
  4635. Beamform_cap == (BEAMFORMER_CAP_VHT_SU|BEAMFORMEE_CAP_VHT_SU))
  4636. TxBF_EN = 1;
  4637. H2C_Parameter[3] |= TxBF_EN << 6;
  4638. }
  4639. if(pEntry->rssi_stat.UndecoratedSmoothedPWDB < tmpEntryMinPWDB)
  4640. tmpEntryMinPWDB = pEntry->rssi_stat.UndecoratedSmoothedPWDB;
  4641. if(pEntry->rssi_stat.UndecoratedSmoothedPWDB > tmpEntryMaxPWDB)
  4642. tmpEntryMaxPWDB = pEntry->rssi_stat.UndecoratedSmoothedPWDB;
  4643. H2C_Parameter[2] = (u1Byte)(pEntry->rssi_stat.UndecoratedSmoothedPWDB & 0xFF);
  4644. H2C_Parameter[1] = 0x20; // fw v12 cmdid 5:use max macid ,for nic ,default macid is 0 ,max macid is 1
  4645. H2C_Parameter[0] = (pEntry->AssociatedMacId);
  4646. if(pDM_Odm->SupportICType == ODM_RTL8812)
  4647. ODM_FillH2CCmd(Adapter, ODM_H2C_RSSI_REPORT, 4, H2C_Parameter);
  4648. else if(pDM_Odm->SupportICType == ODM_RTL8192E)
  4649. ODM_FillH2CCmd(Adapter, ODM_H2C_RSSI_REPORT, 4, H2C_Parameter);
  4650. else
  4651. ODM_FillH2CCmd(Adapter, ODM_H2C_RSSI_REPORT, 3, H2C_Parameter);
  4652. }
  4653. }
  4654. else
  4655. {
  4656. break;
  4657. }
  4658. }
  4659. if(tmpEntryMaxPWDB != 0) // If associated entry is found
  4660. {
  4661. pHalData->EntryMaxUndecoratedSmoothedPWDB = tmpEntryMaxPWDB;
  4662. RT_DISP(FDM, DM_PWDB, ("EntryMaxPWDB = 0x%x(%d)\n", tmpEntryMaxPWDB, tmpEntryMaxPWDB));
  4663. }
  4664. else
  4665. {
  4666. pHalData->EntryMaxUndecoratedSmoothedPWDB = 0;
  4667. }
  4668. if(tmpEntryMinPWDB != 0xff) // If associated entry is found
  4669. {
  4670. pHalData->EntryMinUndecoratedSmoothedPWDB = tmpEntryMinPWDB;
  4671. RT_DISP(FDM, DM_PWDB, ("EntryMinPWDB = 0x%x(%d)\n", tmpEntryMinPWDB, tmpEntryMinPWDB));
  4672. }
  4673. else
  4674. {
  4675. pHalData->EntryMinUndecoratedSmoothedPWDB = 0;
  4676. }
  4677. // Indicate Rx signal strength to FW.
  4678. if(pMgntInfo->bUseRAMask)
  4679. {
  4680. if(pDM_Odm->SupportICType == ODM_RTL8192E)
  4681. {
  4682. Beamform_cap = Beamforming_GetEntryBeamCapByMacId(pMgntInfo, pMgntInfo->mMacId);
  4683. if(Beamform_cap == BEAMFORMER_CAP_HT_EXPLICIT || Beamform_cap == BEAMFORMER_CAP_VHT_SU ||
  4684. Beamform_cap == (BEAMFORMER_CAP_HT_EXPLICIT|BEAMFORMEE_CAP_HT_EXPLICIT) ||
  4685. Beamform_cap == (BEAMFORMER_CAP_VHT_SU|BEAMFORMEE_CAP_VHT_SU))
  4686. TxBF_EN = 1;
  4687. H2C_Parameter[3] |= TxBF_EN << 6;
  4688. }
  4689. H2C_Parameter[2] = (u1Byte)(pHalData->UndecoratedSmoothedPWDB & 0xFF);
  4690. H2C_Parameter[1] = 0x20; // fw v12 cmdid 5:use max macid ,for nic ,default macid is 0 ,max macid is 1
  4691. H2C_Parameter[0] = 0; // fw v12 cmdid 5:use max macid ,for nic ,default macid is 0 ,max macid is 1
  4692. if(pDM_Odm->SupportICType == ODM_RTL8812)
  4693. ODM_FillH2CCmd(Adapter, ODM_H2C_RSSI_REPORT, 4, H2C_Parameter);
  4694. else if(pDM_Odm->SupportICType == ODM_RTL8192E)
  4695. ODM_FillH2CCmd(Adapter, ODM_H2C_RSSI_REPORT, 4, H2C_Parameter);
  4696. else
  4697. ODM_FillH2CCmd(Adapter, ODM_H2C_RSSI_REPORT, 3, H2C_Parameter);
  4698. }
  4699. else
  4700. {
  4701. PlatformEFIOWrite1Byte(Adapter, 0x4fe, (u1Byte)pHalData->UndecoratedSmoothedPWDB);
  4702. //DbgPrint("0x4fe write %x %d\n", pHalData->UndecoratedSmoothedPWDB, pHalData->UndecoratedSmoothedPWDB);
  4703. }
  4704. if((pDM_Odm->SupportICType == ODM_RTL8812)||(pDM_Odm->SupportICType == ODM_RTL8192E))
  4705. odm_RSSIDumpToRegister(pDM_Odm);
  4706. odm_FindMinimumRSSI(Adapter);
  4707. ODM_CmnInfoUpdate(&pHalData->DM_OutSrc ,ODM_CMNINFO_LINK, (u8Byte)pHalData->bLinked);
  4708. ODM_CmnInfoUpdate(&pHalData->DM_OutSrc ,ODM_CMNINFO_RSSI_MIN, (u8Byte)pHalData->MinUndecoratedPWDBForDM);
  4709. #endif // #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
  4710. }
  4711. #if (DM_ODM_SUPPORT_TYPE == ODM_CE)
  4712. //
  4713. //sherry move from DUSC to here 20110517
  4714. //
  4715. static VOID
  4716. FindMinimumRSSI_Dmsp(
  4717. IN PADAPTER pAdapter
  4718. )
  4719. {
  4720. #if 0
  4721. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(pAdapter);
  4722. struct dm_priv *pdmpriv = &pHalData->dmpriv;
  4723. s32 Rssi_val_min_back_for_mac0;
  4724. BOOLEAN bGetValueFromBuddyAdapter = dm_DualMacGetParameterFromBuddyAdapter(pAdapter);
  4725. BOOLEAN bRestoreRssi = _FALSE;
  4726. PADAPTER BuddyAdapter = pAdapter->BuddyAdapter;
  4727. if(pHalData->MacPhyMode92D == DUALMAC_SINGLEPHY)
  4728. {
  4729. if(BuddyAdapter!= NULL)
  4730. {
  4731. if(pHalData->bSlaveOfDMSP)
  4732. {
  4733. //ODM_RT_TRACE(pDM_Odm,COMP_EASY_CONCURRENT,DBG_LOUD,("bSlavecase of dmsp\n"));
  4734. BuddyAdapter->DualMacDMSPControl.RssiValMinForAnotherMacOfDMSP = pdmpriv->MinUndecoratedPWDBForDM;
  4735. }
  4736. else
  4737. {
  4738. if(bGetValueFromBuddyAdapter)
  4739. {
  4740. //ODM_RT_TRACE(pDM_Odm,COMP_EASY_CONCURRENT,DBG_LOUD,("get new RSSI\n"));
  4741. bRestoreRssi = _TRUE;
  4742. Rssi_val_min_back_for_mac0 = pdmpriv->MinUndecoratedPWDBForDM;
  4743. pdmpriv->MinUndecoratedPWDBForDM = pAdapter->DualMacDMSPControl.RssiValMinForAnotherMacOfDMSP;
  4744. }
  4745. }
  4746. }
  4747. }
  4748. if(bRestoreRssi)
  4749. {
  4750. bRestoreRssi = _FALSE;
  4751. pdmpriv->MinUndecoratedPWDBForDM = Rssi_val_min_back_for_mac0;
  4752. }
  4753. #endif
  4754. }
  4755. static void
  4756. FindMinimumRSSI(
  4757. IN PADAPTER pAdapter
  4758. )
  4759. {
  4760. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(pAdapter);
  4761. struct dm_priv *pdmpriv = &pHalData->dmpriv;
  4762. PDM_ODM_T pDM_Odm = &(pHalData->odmpriv);
  4763. //1 1.Determine the minimum RSSI
  4764. if((pDM_Odm->bLinked != _TRUE) &&
  4765. (pdmpriv->EntryMinUndecoratedSmoothedPWDB == 0))
  4766. {
  4767. pdmpriv->MinUndecoratedPWDBForDM = 0;
  4768. //ODM_RT_TRACE(pDM_Odm,COMP_BB_POWERSAVING, DBG_LOUD, ("Not connected to any \n"));
  4769. }
  4770. else
  4771. {
  4772. pdmpriv->MinUndecoratedPWDBForDM = pdmpriv->EntryMinUndecoratedSmoothedPWDB;
  4773. }
  4774. //DBG_8192C("%s=>MinUndecoratedPWDBForDM(%d)\n",__FUNCTION__,pdmpriv->MinUndecoratedPWDBForDM);
  4775. //ODM_RT_TRACE(pDM_Odm,COMP_DIG, DBG_LOUD, ("MinUndecoratedPWDBForDM =%d\n",pHalData->MinUndecoratedPWDBForDM));
  4776. }
  4777. #endif
  4778. VOID
  4779. odm_RSSIMonitorCheckCE(
  4780. IN PDM_ODM_T pDM_Odm
  4781. )
  4782. {
  4783. #if (DM_ODM_SUPPORT_TYPE == ODM_CE)
  4784. PADAPTER Adapter = pDM_Odm->Adapter;
  4785. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  4786. struct dm_priv *pdmpriv = &pHalData->dmpriv;
  4787. int i;
  4788. int tmpEntryMaxPWDB=0, tmpEntryMinPWDB=0xff;
  4789. u8 sta_cnt=0;
  4790. u8 UL_DL_STATE = 0;// for 8812 use
  4791. u32 PWDB_rssi[NUM_STA]={0};//[0~15]:MACID, [16~31]:PWDB_rssi
  4792. if(pDM_Odm->bLinked != _TRUE)
  4793. return;
  4794. #if((RTL8812A_SUPPORT==1)||(RTL8821A_SUPPORT==1))
  4795. if((pDM_Odm->SupportICType == ODM_RTL8812)||(pDM_Odm->SupportICType == ODM_RTL8821))
  4796. {
  4797. u64 curTxOkCnt = Adapter->xmitpriv.tx_bytes - Adapter->xmitpriv.last_tx_bytes;
  4798. u64 curRxOkCnt = Adapter->recvpriv.rx_bytes - Adapter->recvpriv.last_rx_bytes;
  4799. if(curRxOkCnt >(curTxOkCnt*6))
  4800. UL_DL_STATE = 1;
  4801. else
  4802. UL_DL_STATE = 0;
  4803. }
  4804. #endif
  4805. #if(RTL8192E_SUPPORT==1)
  4806. /*
  4807. if(pDM_Odm->SupportICType == ODM_RTL8192E)
  4808. {
  4809. STBC_TX = ((pMgntInfo->pHTInfo->HtCurStbc)&0x02)>>1;
  4810. H2C_Parameter[4] = STBC_TX;
  4811. }
  4812. */
  4813. #endif
  4814. //if(check_fwstate(&Adapter->mlmepriv, WIFI_AP_STATE|WIFI_ADHOC_STATE|WIFI_ADHOC_MASTER_STATE) == _TRUE)
  4815. {
  4816. #if 1
  4817. struct sta_info *psta;
  4818. for(i=0; i<ODM_ASSOCIATE_ENTRY_NUM; i++) {
  4819. if (IS_STA_VALID(psta = pDM_Odm->pODM_StaInfo[i]))
  4820. {
  4821. if(psta->rssi_stat.UndecoratedSmoothedPWDB < tmpEntryMinPWDB)
  4822. tmpEntryMinPWDB = psta->rssi_stat.UndecoratedSmoothedPWDB;
  4823. if(psta->rssi_stat.UndecoratedSmoothedPWDB > tmpEntryMaxPWDB)
  4824. tmpEntryMaxPWDB = psta->rssi_stat.UndecoratedSmoothedPWDB;
  4825. #if 0
  4826. DBG_871X("%s mac_id:%u, mac:"MAC_FMT", rssi:%d\n", __func__,
  4827. psta->mac_id, MAC_ARG(psta->hwaddr), psta->rssi_stat.UndecoratedSmoothedPWDB);
  4828. #endif
  4829. if(psta->rssi_stat.UndecoratedSmoothedPWDB != (-1)) {
  4830. if(pDM_Odm->SupportICType == ODM_RTL8192D)
  4831. PWDB_rssi[sta_cnt++] = (psta->mac_id | (psta->rssi_stat.UndecoratedSmoothedPWDB<<16) | ((Adapter->stapriv.asoc_sta_count+1) << 8));
  4832. else if ((pDM_Odm->SupportICType == ODM_RTL8192E)||(pDM_Odm->SupportICType == ODM_RTL8812)||(pDM_Odm->SupportICType == ODM_RTL8821))
  4833. PWDB_rssi[sta_cnt++] = (((u8)(psta->mac_id&0xFF)) | ((psta->rssi_stat.UndecoratedSmoothedPWDB&0x7F)<<16) );
  4834. else
  4835. PWDB_rssi[sta_cnt++] = (psta->mac_id | (psta->rssi_stat.UndecoratedSmoothedPWDB<<16) );
  4836. }
  4837. }
  4838. }
  4839. #else
  4840. _irqL irqL;
  4841. _list *plist, *phead;
  4842. struct sta_info *psta;
  4843. struct sta_priv *pstapriv = &Adapter->stapriv;
  4844. u8 bcast_addr[ETH_ALEN]= {0xff,0xff,0xff,0xff,0xff,0xff};
  4845. _enter_critical_bh(&pstapriv->sta_hash_lock, &irqL);
  4846. for(i=0; i< NUM_STA; i++)
  4847. {
  4848. phead = &(pstapriv->sta_hash[i]);
  4849. plist = get_next(phead);
  4850. while ((rtw_end_of_queue_search(phead, plist)) == _FALSE)
  4851. {
  4852. psta = LIST_CONTAINOR(plist, struct sta_info, hash_list);
  4853. plist = get_next(plist);
  4854. if(_rtw_memcmp(psta->hwaddr, bcast_addr, ETH_ALEN) ||
  4855. _rtw_memcmp(psta->hwaddr, myid(&Adapter->eeprompriv), ETH_ALEN))
  4856. continue;
  4857. if(psta->state & WIFI_ASOC_STATE)
  4858. {
  4859. if(psta->rssi_stat.UndecoratedSmoothedPWDB < tmpEntryMinPWDB)
  4860. tmpEntryMinPWDB = psta->rssi_stat.UndecoratedSmoothedPWDB;
  4861. if(psta->rssi_stat.UndecoratedSmoothedPWDB > tmpEntryMaxPWDB)
  4862. tmpEntryMaxPWDB = psta->rssi_stat.UndecoratedSmoothedPWDB;
  4863. if(psta->rssi_stat.UndecoratedSmoothedPWDB != (-1)){
  4864. //printk("%s==> mac_id(%d),rssi(%d)\n",__FUNCTION__,psta->mac_id,psta->rssi_stat.UndecoratedSmoothedPWDB);
  4865. #if(RTL8192D_SUPPORT==1)
  4866. PWDB_rssi[sta_cnt++] = (psta->mac_id | (psta->rssi_stat.UndecoratedSmoothedPWDB<<16) | ((Adapter->stapriv.asoc_sta_count+1) << 8));
  4867. #else
  4868. PWDB_rssi[sta_cnt++] = (psta->mac_id | (psta->rssi_stat.UndecoratedSmoothedPWDB<<16) );
  4869. #endif
  4870. }
  4871. }
  4872. }
  4873. }
  4874. _exit_critical_bh(&pstapriv->sta_hash_lock, &irqL);
  4875. #endif
  4876. //printk("%s==> sta_cnt(%d)\n",__FUNCTION__,sta_cnt);
  4877. for(i=0; i< sta_cnt; i++)
  4878. {
  4879. if(PWDB_rssi[i] != (0)){
  4880. if(pHalData->fw_ractrl == _TRUE)// Report every sta's RSSI to FW
  4881. {
  4882. #if(RTL8192D_SUPPORT==1)
  4883. if(pDM_Odm->SupportICType == ODM_RTL8192D){
  4884. FillH2CCmd92D(Adapter, H2C_RSSI_REPORT, 3, (u8 *)(&PWDB_rssi[i]));
  4885. }
  4886. #endif
  4887. #if((RTL8192C_SUPPORT==1)||(RTL8723A_SUPPORT==1))
  4888. if((pDM_Odm->SupportICType == ODM_RTL8192C)||(pDM_Odm->SupportICType == ODM_RTL8723A)){
  4889. rtl8192c_set_rssi_cmd(Adapter, (u8*)&PWDB_rssi[i]);
  4890. }
  4891. #endif
  4892. #if((RTL8812A_SUPPORT==1)||(RTL8821A_SUPPORT==1))
  4893. if((pDM_Odm->SupportICType == ODM_RTL8812)||(pDM_Odm->SupportICType == ODM_RTL8821)){
  4894. PWDB_rssi[i] |= (UL_DL_STATE << 24);
  4895. rtl8812_set_rssi_cmd(Adapter, (u8 *)(&PWDB_rssi[i]));
  4896. }
  4897. #endif
  4898. #if(RTL8192E_SUPPORT==1)
  4899. if(pDM_Odm->SupportICType == ODM_RTL8192E){
  4900. PWDB_rssi[i] |= (UL_DL_STATE << 24);
  4901. rtl8192e_set_rssi_cmd(Adapter, (u8 *)(&PWDB_rssi[i]));
  4902. }
  4903. #endif
  4904. }
  4905. else{
  4906. #if((RTL8188E_SUPPORT==1)&&(RATE_ADAPTIVE_SUPPORT == 1))
  4907. if(pDM_Odm->SupportICType == ODM_RTL8188E){
  4908. ODM_RA_SetRSSI_8188E(
  4909. &(pHalData->odmpriv), (PWDB_rssi[i]&0xFF), (u8)((PWDB_rssi[i]>>16) & 0xFF));
  4910. }
  4911. #endif
  4912. }
  4913. }
  4914. }
  4915. }
  4916. if(tmpEntryMaxPWDB != 0) // If associated entry is found
  4917. {
  4918. pdmpriv->EntryMaxUndecoratedSmoothedPWDB = tmpEntryMaxPWDB;
  4919. }
  4920. else
  4921. {
  4922. pdmpriv->EntryMaxUndecoratedSmoothedPWDB = 0;
  4923. }
  4924. if(tmpEntryMinPWDB != 0xff) // If associated entry is found
  4925. {
  4926. pdmpriv->EntryMinUndecoratedSmoothedPWDB = tmpEntryMinPWDB;
  4927. }
  4928. else
  4929. {
  4930. pdmpriv->EntryMinUndecoratedSmoothedPWDB = 0;
  4931. }
  4932. FindMinimumRSSI(Adapter);//get pdmpriv->MinUndecoratedPWDBForDM
  4933. #if(RTL8192D_SUPPORT==1)
  4934. FindMinimumRSSI_Dmsp(Adapter);
  4935. #endif
  4936. ODM_CmnInfoUpdate(&pHalData->odmpriv ,ODM_CMNINFO_RSSI_MIN, pdmpriv->MinUndecoratedPWDBForDM);
  4937. #endif//if (DM_ODM_SUPPORT_TYPE == ODM_CE)
  4938. }
  4939. VOID
  4940. odm_RSSIMonitorCheckAP(
  4941. IN PDM_ODM_T pDM_Odm
  4942. )
  4943. {
  4944. #if (DM_ODM_SUPPORT_TYPE == ODM_AP)
  4945. #ifdef CONFIG_RTL_92C_SUPPORT || defined(CONFIG_RTL_92D_SUPPORT)
  4946. u4Byte i;
  4947. PSTA_INFO_T pstat;
  4948. for(i=0; i<ODM_ASSOCIATE_ENTRY_NUM; i++)
  4949. {
  4950. pstat = pDM_Odm->pODM_StaInfo[i];
  4951. if(IS_STA_VALID(pstat) )
  4952. {
  4953. #ifdef STA_EXT
  4954. if (REMAP_AID(pstat) < (FW_NUM_STAT - 1))
  4955. #endif
  4956. add_update_rssi(pDM_Odm->priv, pstat);
  4957. }
  4958. }
  4959. #endif
  4960. #endif
  4961. }
  4962. VOID
  4963. ODM_InitAllTimers(
  4964. IN PDM_ODM_T pDM_Odm
  4965. )
  4966. {
  4967. #if(defined(CONFIG_SW_ANTENNA_DIVERSITY))
  4968. ODM_InitializeTimer(pDM_Odm,&pDM_Odm->DM_SWAT_Table.SwAntennaSwitchTimer,
  4969. (RT_TIMER_CALL_BACK)odm_SwAntDivChkAntSwitchCallback, NULL, "SwAntennaSwitchTimer");
  4970. #endif
  4971. #if (!(DM_ODM_SUPPORT_TYPE == ODM_CE))
  4972. #if(defined(CONFIG_HW_ANTENNA_DIVERSITY))
  4973. #if (RTL8188E_SUPPORT == 1)
  4974. ODM_InitializeTimer(pDM_Odm,&pDM_Odm->FastAntTrainingTimer,
  4975. (RT_TIMER_CALL_BACK)odm_FastAntTrainingCallback, NULL, "FastAntTrainingTimer");
  4976. #endif
  4977. #endif
  4978. #endif
  4979. #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
  4980. ODM_InitializeTimer(pDM_Odm, &pDM_Odm->PSDTimer,
  4981. (RT_TIMER_CALL_BACK)dm_PSDMonitorCallback, NULL, "PSDTimer");
  4982. //
  4983. //Path Diversity
  4984. //Neil Chen--2011--06--16-- / 2012/02/23 MH Revise Arch.
  4985. //
  4986. ODM_InitializeTimer(pDM_Odm, &pDM_Odm->PathDivSwitchTimer,
  4987. (RT_TIMER_CALL_BACK)odm_PathDivChkAntSwitchCallback, NULL, "PathDivTimer");
  4988. ODM_InitializeTimer(pDM_Odm, &pDM_Odm->CCKPathDiversityTimer,
  4989. (RT_TIMER_CALL_BACK)odm_CCKTXPathDiversityCallback, NULL, "CCKPathDiversityTimer");
  4990. ODM_InitializeTimer(pDM_Odm, &pDM_Odm->MPT_DIGTimer,
  4991. (RT_TIMER_CALL_BACK)odm_MPT_DIGCallback, NULL, "MPT_DIGTimer");
  4992. ODM_InitializeTimer(pDM_Odm, &pDM_Odm->DM_RXHP_Table.PSDTimer,
  4993. (RT_TIMER_CALL_BACK)odm_PSD_RXHPCallback, NULL, "PSDRXHPTimer");
  4994. #endif
  4995. }
  4996. VOID
  4997. ODM_CancelAllTimers(
  4998. IN PDM_ODM_T pDM_Odm
  4999. )
  5000. {
  5001. #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
  5002. //
  5003. // 2012/01/12 MH Temp BSOD fix. We need to find NIC allocate mem fail reason in
  5004. // win7 platform.
  5005. //
  5006. HAL_ADAPTER_STS_CHK(pDM_Odm)
  5007. #endif
  5008. #if(defined(CONFIG_SW_ANTENNA_DIVERSITY))
  5009. ODM_CancelTimer(pDM_Odm,&pDM_Odm->DM_SWAT_Table.SwAntennaSwitchTimer);
  5010. #endif
  5011. #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
  5012. #if (RTL8188E_SUPPORT == 1)
  5013. ODM_CancelTimer(pDM_Odm,&pDM_Odm->FastAntTrainingTimer);
  5014. #endif
  5015. ODM_CancelTimer(pDM_Odm, &pDM_Odm->PSDTimer);
  5016. //
  5017. //Path Diversity
  5018. //Neil Chen--2011--06--16-- / 2012/02/23 MH Revise Arch.
  5019. //
  5020. ODM_CancelTimer(pDM_Odm, &pDM_Odm->PathDivSwitchTimer);
  5021. ODM_CancelTimer(pDM_Odm, &pDM_Odm->CCKPathDiversityTimer);
  5022. ODM_CancelTimer(pDM_Odm, &pDM_Odm->MPT_DIGTimer);
  5023. ODM_CancelTimer(pDM_Odm, &pDM_Odm->DM_RXHP_Table.PSDTimer);
  5024. #endif
  5025. }
  5026. VOID
  5027. ODM_ReleaseAllTimers(
  5028. IN PDM_ODM_T pDM_Odm
  5029. )
  5030. {
  5031. ODM_ReleaseTimer(pDM_Odm,&pDM_Odm->DM_SWAT_Table.SwAntennaSwitchTimer);
  5032. #if (RTL8188E_SUPPORT == 1)
  5033. ODM_ReleaseTimer(pDM_Odm,&pDM_Odm->FastAntTrainingTimer);
  5034. #endif
  5035. #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
  5036. ODM_ReleaseTimer(pDM_Odm, &pDM_Odm->PSDTimer);
  5037. //
  5038. //Path Diversity
  5039. //Neil Chen--2011--06--16-- / 2012/02/23 MH Revise Arch.
  5040. //
  5041. ODM_ReleaseTimer(pDM_Odm, &pDM_Odm->PathDivSwitchTimer);
  5042. ODM_ReleaseTimer(pDM_Odm, &pDM_Odm->CCKPathDiversityTimer);
  5043. ODM_ReleaseTimer(pDM_Odm, &pDM_Odm->MPT_DIGTimer);
  5044. ODM_ReleaseTimer(pDM_Odm, &pDM_Odm->DM_RXHP_Table.PSDTimer);
  5045. #endif
  5046. }
  5047. //#endif
  5048. //3============================================================
  5049. //3 Tx Power Tracking
  5050. //3============================================================
  5051. VOID
  5052. odm_TXPowerTrackingInit(
  5053. IN PDM_ODM_T pDM_Odm
  5054. )
  5055. {
  5056. odm_TXPowerTrackingThermalMeterInit(pDM_Odm);
  5057. }
  5058. u1Byte
  5059. getSwingIndex(
  5060. IN PDM_ODM_T pDM_Odm
  5061. )
  5062. {
  5063. PADAPTER Adapter = pDM_Odm->Adapter;
  5064. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  5065. u1Byte i = 0;
  5066. u4Byte bbSwing;
  5067. #if ((RTL8812A_SUPPORT==1)||(RTL8821A_SUPPORT==1))
  5068. bbSwing = PHY_GetTxBBSwing_8812A(Adapter, pHalData->CurrentBandType, ODM_RF_PATH_A);
  5069. #endif
  5070. for (i = 0; i < TXSCALE_TABLE_SIZE; ++i)
  5071. if ( bbSwing == TxScalingTable_Jaguar[i])
  5072. break;
  5073. return i;
  5074. }
  5075. VOID
  5076. odm_TXPowerTrackingThermalMeterInit(
  5077. IN PDM_ODM_T pDM_Odm
  5078. )
  5079. {
  5080. u1Byte p = 0;
  5081. #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
  5082. PADAPTER Adapter = pDM_Odm->Adapter;
  5083. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  5084. #if MP_DRIVER != 1 //for mp driver, turn off txpwrtracking as default
  5085. pHalData->TxPowerTrackControl = TRUE;
  5086. #endif//#if (MP_DRIVER != 1)
  5087. #elif (DM_ODM_SUPPORT_TYPE == ODM_CE)
  5088. PADAPTER Adapter = pDM_Odm->Adapter;
  5089. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  5090. #if( (RTL8188E_SUPPORT==1) || (RTL8812A_SUPPORT==1) || (RTL8821A_SUPPORT==1) ||(RTL8192E_SUPPORT==1) )
  5091. {
  5092. pDM_Odm->RFCalibrateInfo.bTXPowerTracking = _TRUE;
  5093. pDM_Odm->RFCalibrateInfo.TXPowercount = 0;
  5094. pDM_Odm->RFCalibrateInfo.bTXPowerTrackingInit = _FALSE;
  5095. //#if (MP_DRIVER != 1) //for mp driver, turn off txpwrtracking as default
  5096. if ( *(pDM_Odm->mp_mode) != 1)
  5097. pDM_Odm->RFCalibrateInfo.TxPowerTrackControl = _TRUE;
  5098. //#endif//#if (MP_DRIVER != 1)
  5099. MSG_8192C("pDM_Odm TxPowerTrackControl = %d\n", pDM_Odm->RFCalibrateInfo.TxPowerTrackControl);
  5100. }
  5101. #else
  5102. {
  5103. struct dm_priv *pdmpriv = &pHalData->dmpriv;
  5104. //if(IS_HARDWARE_TYPE_8192C(pHalData))
  5105. {
  5106. pdmpriv->bTXPowerTracking = _TRUE;
  5107. pdmpriv->TXPowercount = 0;
  5108. pdmpriv->bTXPowerTrackingInit = _FALSE;
  5109. //#if (MP_DRIVER != 1) //for mp driver, turn off txpwrtracking as default
  5110. if (*(pDM_Odm->mp_mode) != 1)
  5111. pdmpriv->TxPowerTrackControl = _TRUE;
  5112. //#endif//#if (MP_DRIVER != 1)
  5113. }
  5114. MSG_8192C("pdmpriv->TxPowerTrackControl = %d\n", pdmpriv->TxPowerTrackControl);
  5115. }
  5116. #endif//endif (CONFIG_RTL8188E==1)
  5117. #elif (DM_ODM_SUPPORT_TYPE & (ODM_AP|ODM_ADSL))
  5118. #ifdef RTL8188E_SUPPORT
  5119. {
  5120. pDM_Odm->RFCalibrateInfo.bTXPowerTracking = _TRUE;
  5121. pDM_Odm->RFCalibrateInfo.TXPowercount = 0;
  5122. pDM_Odm->RFCalibrateInfo.bTXPowerTrackingInit = _FALSE;
  5123. pDM_Odm->RFCalibrateInfo.TxPowerTrackControl = _TRUE;
  5124. }
  5125. #endif
  5126. #endif
  5127. pDM_Odm->RFCalibrateInfo.TxPowerTrackControl = TRUE;
  5128. pDM_Odm->RFCalibrateInfo.ThermalValue = pHalData->EEPROMThermalMeter;
  5129. pDM_Odm->RFCalibrateInfo.ThermalValue_IQK = pHalData->EEPROMThermalMeter;
  5130. pDM_Odm->RFCalibrateInfo.ThermalValue_LCK = pHalData->EEPROMThermalMeter;
  5131. // The index of "0 dB" in SwingTable.
  5132. if (pDM_Odm->SupportICType == ODM_RTL8188E || pDM_Odm->SupportICType == ODM_RTL8723B ||
  5133. pDM_Odm->SupportICType == ODM_RTL8192E)
  5134. {
  5135. pDM_Odm->DefaultOfdmIndex = 30;
  5136. pDM_Odm->DefaultCckIndex = 20;
  5137. } else {
  5138. u1Byte defaultSwingIndex = getSwingIndex(pDM_Odm);
  5139. pDM_Odm->DefaultOfdmIndex = (defaultSwingIndex == TXSCALE_TABLE_SIZE) ? 24 : defaultSwingIndex;
  5140. pDM_Odm->DefaultCckIndex = 24;
  5141. }
  5142. pDM_Odm->BbSwingIdxCckBase = pDM_Odm->DefaultCckIndex;
  5143. pDM_Odm->RFCalibrateInfo.CCK_index = pDM_Odm->DefaultCckIndex;
  5144. for (p = ODM_RF_PATH_A; p < MAX_RF_PATH; ++p)
  5145. {
  5146. pDM_Odm->BbSwingIdxOfdmBase[p] = pDM_Odm->DefaultOfdmIndex;
  5147. pDM_Odm->RFCalibrateInfo.OFDM_index[p] = pDM_Odm->DefaultOfdmIndex;
  5148. pDM_Odm->RFCalibrateInfo.DeltaPowerIndex[p] = 0;
  5149. pDM_Odm->RFCalibrateInfo.DeltaPowerIndexLast[p] = 0;
  5150. pDM_Odm->RFCalibrateInfo.PowerIndexOffset[p] = 0;
  5151. }
  5152. }
  5153. VOID
  5154. ODM_TXPowerTrackingCheck(
  5155. IN PDM_ODM_T pDM_Odm
  5156. )
  5157. {
  5158. //
  5159. // For AP/ADSL use prtl8192cd_priv
  5160. // For CE/NIC use PADAPTER
  5161. //
  5162. //if (!(pDM_Odm->SupportAbility & ODM_RF_TX_PWR_TRACK))
  5163. //return;
  5164. //
  5165. // 2011/09/29 MH In HW integration first stage, we provide 4 different handle to operate
  5166. // at the same time. In the stage2/3, we need to prive universal interface and merge all
  5167. // HW dynamic mechanism.
  5168. //
  5169. switch (pDM_Odm->SupportPlatform)
  5170. {
  5171. case ODM_WIN:
  5172. odm_TXPowerTrackingCheckMP(pDM_Odm);
  5173. break;
  5174. case ODM_CE:
  5175. odm_TXPowerTrackingCheckCE(pDM_Odm);
  5176. break;
  5177. case ODM_AP:
  5178. odm_TXPowerTrackingCheckAP(pDM_Odm);
  5179. break;
  5180. case ODM_ADSL:
  5181. //odm_DIGAP(pDM_Odm);
  5182. break;
  5183. }
  5184. }
  5185. VOID
  5186. odm_TXPowerTrackingCheckCE(
  5187. IN PDM_ODM_T pDM_Odm
  5188. )
  5189. {
  5190. #if (DM_ODM_SUPPORT_TYPE == ODM_CE)
  5191. PADAPTER Adapter = pDM_Odm->Adapter;
  5192. #if( (RTL8192C_SUPPORT==1) || (RTL8723A_SUPPORT==1) )
  5193. if(IS_HARDWARE_TYPE_8192C(Adapter)){
  5194. rtl8192c_odm_CheckTXPowerTracking(Adapter);
  5195. return;
  5196. }
  5197. #endif
  5198. #if (RTL8192D_SUPPORT==1)
  5199. if(IS_HARDWARE_TYPE_8192D(Adapter)){
  5200. #if (RTL8192D_EASY_SMART_CONCURRENT == 1)
  5201. if(!Adapter->bSlaveOfDMSP)
  5202. #endif
  5203. rtl8192d_odm_CheckTXPowerTracking(Adapter);
  5204. return;
  5205. }
  5206. #endif
  5207. #if(((RTL8188E_SUPPORT==1) || (RTL8812A_SUPPORT==1) || (RTL8821A_SUPPORT==1) || (RTL8192E_SUPPORT==1) || (RTL8723B_SUPPORT==1) ))
  5208. if(!(pDM_Odm->SupportAbility & ODM_RF_TX_PWR_TRACK))
  5209. {
  5210. return;
  5211. }
  5212. if(!pDM_Odm->RFCalibrateInfo.TM_Trigger) //at least delay 1 sec
  5213. {
  5214. //pHalData->TxPowerCheckCnt++; //cosa add for debug
  5215. if(IS_HARDWARE_TYPE_8188E(Adapter) || IS_HARDWARE_TYPE_JAGUAR(Adapter) || IS_HARDWARE_TYPE_8192E(Adapter) )//||IS_HARDWARE_TYPE_8723B(Adapter))
  5216. ODM_SetRFReg(pDM_Odm, ODM_RF_PATH_A, RF_T_METER_NEW, (BIT17 | BIT16), 0x03);
  5217. else
  5218. ODM_SetRFReg(pDM_Odm, ODM_RF_PATH_A, RF_T_METER_OLD, bRFRegOffsetMask, 0x60);
  5219. //DBG_871X("Trigger Thermal Meter!!\n");
  5220. pDM_Odm->RFCalibrateInfo.TM_Trigger = 1;
  5221. return;
  5222. }
  5223. else
  5224. {
  5225. //DBG_871X("Schedule TxPowerTracking direct call!!\n");
  5226. ODM_TXPowerTrackingCallback_ThermalMeter(Adapter);
  5227. pDM_Odm->RFCalibrateInfo.TM_Trigger = 0;
  5228. }
  5229. #endif
  5230. #endif
  5231. }
  5232. VOID
  5233. odm_TXPowerTrackingCheckMP(
  5234. IN PDM_ODM_T pDM_Odm
  5235. )
  5236. {
  5237. #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
  5238. PADAPTER Adapter = pDM_Odm->Adapter;
  5239. if (ODM_CheckPowerStatus(Adapter) == FALSE)
  5240. {
  5241. RT_TRACE(COMP_POWER_TRACKING, DBG_LOUD, ("===>ODM_CheckPowerStatus() return FALSE\n"));
  5242. return;
  5243. }
  5244. if(IS_HARDWARE_TYPE_8723A(Adapter))
  5245. return;
  5246. if(!Adapter->bSlaveOfDMSP || Adapter->DualMacSmartConcurrent == FALSE)
  5247. odm_TXPowerTrackingThermalMeterCheck(Adapter);
  5248. else {
  5249. RT_TRACE(COMP_POWER_TRACKING, DBG_LOUD, ("!Adapter->bSlaveOfDMSP || Adapter->DualMacSmartConcurrent == FALSE\n"));
  5250. }
  5251. #endif
  5252. }
  5253. VOID
  5254. odm_TXPowerTrackingCheckAP(
  5255. IN PDM_ODM_T pDM_Odm
  5256. )
  5257. {
  5258. #if (DM_ODM_SUPPORT_TYPE == ODM_AP)
  5259. prtl8192cd_priv priv = pDM_Odm->priv;
  5260. if ( (priv->pmib->dot11RFEntry.ther) && ((priv->up_time % priv->pshare->rf_ft_var.tpt_period) == 0)){
  5261. #ifdef CONFIG_RTL_92D_SUPPORT
  5262. if (GET_CHIP_VER(priv)==VERSION_8192D){
  5263. tx_power_tracking_92D(priv);
  5264. } else
  5265. #endif
  5266. {
  5267. #ifdef CONFIG_RTL_92C_SUPPORT
  5268. tx_power_tracking(priv);
  5269. #endif
  5270. }
  5271. }
  5272. #endif
  5273. }
  5274. //antenna mapping info
  5275. // 1: right-side antenna
  5276. // 2/0: left-side antenna
  5277. //PDM_SWAT_Table->CCK_Ant1_Cnt /OFDM_Ant1_Cnt: for right-side antenna: Ant:1 RxDefaultAnt1
  5278. //PDM_SWAT_Table->CCK_Ant2_Cnt /OFDM_Ant2_Cnt: for left-side antenna: Ant:0 RxDefaultAnt2
  5279. // We select left antenna as default antenna in initial process, modify it as needed
  5280. //
  5281. #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
  5282. VOID
  5283. odm_TXPowerTrackingThermalMeterCheck(
  5284. IN PADAPTER Adapter
  5285. )
  5286. {
  5287. #ifndef AP_BUILD_WORKAROUND
  5288. static u1Byte TM_Trigger = 0;
  5289. if(!(GET_HAL_DATA(Adapter)->DM_OutSrc.SupportAbility & ODM_RF_TX_PWR_TRACK))
  5290. {
  5291. RT_TRACE(COMP_POWER_TRACKING, DBG_LOUD,
  5292. ("===>odm_TXPowerTrackingThermalMeterCheck(),pMgntInfo->bTXPowerTracking is FALSE, return!!\n"));
  5293. return;
  5294. }
  5295. if(!TM_Trigger) //at least delay 1 sec
  5296. {
  5297. if(IS_HARDWARE_TYPE_8192D(Adapter))
  5298. PHY_SetRFReg(Adapter, ODM_RF_PATH_A, RF_T_METER_92D, BIT17 | BIT16, 0x03);
  5299. else if(IS_HARDWARE_TYPE_8188E(Adapter) || IS_HARDWARE_TYPE_JAGUAR(Adapter) || IS_HARDWARE_TYPE_8192E(Adapter) ||
  5300. IS_HARDWARE_TYPE_8723B(Adapter))
  5301. PHY_SetRFReg(Adapter, ODM_RF_PATH_A, RF_T_METER_88E, BIT17 | BIT16, 0x03);
  5302. else
  5303. PHY_SetRFReg(Adapter, ODM_RF_PATH_A, RF_T_METER, bRFRegOffsetMask, 0x60);
  5304. RT_TRACE(COMP_POWER_TRACKING, DBG_LOUD,("Trigger Thermal Meter!!\n"));
  5305. TM_Trigger = 1;
  5306. return;
  5307. }
  5308. else
  5309. {
  5310. RT_TRACE(COMP_POWER_TRACKING, DBG_LOUD,("Schedule TxPowerTracking direct call!!\n"));
  5311. odm_TXPowerTrackingDirectCall(Adapter); //Using direct call is instead, added by Roger, 2009.06.18.
  5312. TM_Trigger = 0;
  5313. }
  5314. #endif
  5315. }
  5316. // Only for 8723A SW ANT DIV INIT--2012--07--17
  5317. VOID
  5318. odm_SwAntDivInit_NIC_8723A(
  5319. IN PDM_ODM_T pDM_Odm)
  5320. {
  5321. pSWAT_T pDM_SWAT_Table = &pDM_Odm->DM_SWAT_Table;
  5322. PADAPTER Adapter = pDM_Odm->Adapter;
  5323. u1Byte btAntNum=BT_GetPgAntNum(Adapter);
  5324. if(IS_HARDWARE_TYPE_8723A(Adapter))
  5325. {
  5326. pDM_SWAT_Table->ANTA_ON =TRUE;
  5327. // Set default antenna B status by PG
  5328. if(btAntNum == 2)
  5329. pDM_SWAT_Table->ANTB_ON = TRUE;
  5330. else if(btAntNum == 1)
  5331. pDM_SWAT_Table->ANTB_ON = FALSE;
  5332. else
  5333. pDM_SWAT_Table->ANTB_ON = TRUE;
  5334. }
  5335. }
  5336. #endif //end #ifMP
  5337. //3============================================================
  5338. //3 SW Antenna Diversity
  5339. //3============================================================
  5340. #if(defined(CONFIG_SW_ANTENNA_DIVERSITY))
  5341. VOID
  5342. odm_SwAntDivInit(
  5343. IN PDM_ODM_T pDM_Odm
  5344. )
  5345. {
  5346. #if (DM_ODM_SUPPORT_TYPE & (ODM_WIN|ODM_CE))
  5347. odm_SwAntDivInit_NIC(pDM_Odm);
  5348. #elif(DM_ODM_SUPPORT_TYPE == ODM_AP)
  5349. dm_SW_AntennaSwitchInit(pDM_Odm->priv);
  5350. #endif
  5351. }
  5352. VOID
  5353. odm_SwAntDivInit_NIC(
  5354. IN PDM_ODM_T pDM_Odm
  5355. )
  5356. {
  5357. pSWAT_T pDM_SWAT_Table = &pDM_Odm->DM_SWAT_Table;
  5358. // Init SW ANT DIV mechanism for 8723AE/AU/AS
  5359. // CE/AP/ADSL no using SW ANT DIV for 8723A Series IC
  5360. //#if (DM_ODM_SUPPORT_TYPE==ODM_WIN)
  5361. #if (RTL8723A_SUPPORT==1)
  5362. if(pDM_Odm->SupportICType == ODM_RTL8723A)
  5363. {
  5364. odm_SwAntDivInit_NIC_8723A(pDM_Odm);
  5365. }
  5366. #endif
  5367. ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("SWAS:Init SW Antenna Switch\n"));
  5368. pDM_SWAT_Table->RSSI_sum_A = 0;
  5369. pDM_SWAT_Table->RSSI_cnt_A = 0;
  5370. pDM_SWAT_Table->RSSI_sum_B = 0;
  5371. pDM_SWAT_Table->RSSI_cnt_B = 0;
  5372. pDM_SWAT_Table->CurAntenna = MAIN_ANT;
  5373. pDM_SWAT_Table->PreAntenna = MAIN_ANT;
  5374. pDM_SWAT_Table->try_flag = 0xff;
  5375. pDM_SWAT_Table->PreRSSI = 0;
  5376. pDM_SWAT_Table->SWAS_NoLink_State = 0;
  5377. pDM_SWAT_Table->bTriggerAntennaSwitch = 0;
  5378. pDM_SWAT_Table->SelectAntennaMap=0xAA;
  5379. pDM_SWAT_Table->lastTxOkCnt = 0;
  5380. pDM_SWAT_Table->lastRxOkCnt = 0;
  5381. pDM_SWAT_Table->TXByteCnt_A = 0;
  5382. pDM_SWAT_Table->TXByteCnt_B = 0;
  5383. pDM_SWAT_Table->RXByteCnt_A = 0;
  5384. pDM_SWAT_Table->RXByteCnt_B = 0;
  5385. pDM_SWAT_Table->TrafficLoad = TRAFFIC_LOW;
  5386. pDM_SWAT_Table->SWAS_NoLink_BK_Reg860 = ODM_Read4Byte(pDM_Odm, 0x860);
  5387. }
  5388. //
  5389. // 20100514 Joseph:
  5390. // Add new function to reset the state of antenna diversity before link.
  5391. //
  5392. VOID
  5393. ODM_SwAntDivResetBeforeLink(
  5394. IN PDM_ODM_T pDM_Odm
  5395. )
  5396. {
  5397. pSWAT_T pDM_SWAT_Table = &pDM_Odm->DM_SWAT_Table;
  5398. pDM_SWAT_Table->SWAS_NoLink_State = 0;
  5399. }
  5400. //
  5401. // 20100514 Luke/Joseph:
  5402. // Add new function to reset antenna diversity state after link.
  5403. //
  5404. VOID
  5405. ODM_SwAntDivRestAfterLink(
  5406. IN PDM_ODM_T pDM_Odm
  5407. )
  5408. {
  5409. pSWAT_T pDM_SWAT_Table = &pDM_Odm->DM_SWAT_Table;
  5410. pDM_SWAT_Table->RSSI_cnt_A = 0;
  5411. pDM_SWAT_Table->RSSI_cnt_B = 0;
  5412. pDM_Odm->RSSI_test = FALSE;
  5413. pDM_SWAT_Table->try_flag = 0xff;
  5414. pDM_SWAT_Table->RSSI_Trying = 0;
  5415. pDM_SWAT_Table->SelectAntennaMap=0xAA;
  5416. }
  5417. VOID
  5418. ODM_SwAntDivChkPerPktRssi(
  5419. IN PDM_ODM_T pDM_Odm,
  5420. IN u1Byte StationID,
  5421. IN PODM_PHY_INFO_T pPhyInfo
  5422. )
  5423. {
  5424. SWAT_T *pDM_SWAT_Table = &pDM_Odm->DM_SWAT_Table;
  5425. if(!(pDM_Odm->SupportAbility & (ODM_BB_ANT_DIV)))
  5426. return;
  5427. // temporary Fix 8723A MP SW ANT DIV Bug --NeilChen--2012--07--11
  5428. #if (DM_ODM_SUPPORT_TYPE==ODM_WIN)
  5429. if(pDM_Odm->SupportICType == ODM_RTL8723A)
  5430. {
  5431. //if(StationID == pDM_SWAT_Table->RSSI_target)
  5432. //{
  5433. //1 RSSI for SW Antenna Switch
  5434. if(pDM_SWAT_Table->CurAntenna == MAIN_ANT)
  5435. {
  5436. pDM_SWAT_Table->RSSI_sum_A += pPhyInfo->RxPWDBAll;
  5437. pDM_SWAT_Table->RSSI_cnt_A++;
  5438. }
  5439. else
  5440. {
  5441. pDM_SWAT_Table->RSSI_sum_B += pPhyInfo->RxPWDBAll;
  5442. pDM_SWAT_Table->RSSI_cnt_B++;
  5443. }
  5444. //}
  5445. }
  5446. else
  5447. {
  5448. if(StationID == pDM_SWAT_Table->RSSI_target)
  5449. {
  5450. //1 RSSI for SW Antenna Switch
  5451. if(pDM_SWAT_Table->CurAntenna == MAIN_ANT)
  5452. {
  5453. pDM_SWAT_Table->RSSI_sum_A += pPhyInfo->RxPWDBAll;
  5454. pDM_SWAT_Table->RSSI_cnt_A++;
  5455. }
  5456. else
  5457. {
  5458. pDM_SWAT_Table->RSSI_sum_B += pPhyInfo->RxPWDBAll;
  5459. pDM_SWAT_Table->RSSI_cnt_B++;
  5460. }
  5461. }
  5462. }
  5463. #else
  5464. if(StationID == pDM_SWAT_Table->RSSI_target)
  5465. {
  5466. //1 RSSI for SW Antenna Switch
  5467. if(pDM_SWAT_Table->CurAntenna == MAIN_ANT)
  5468. {
  5469. pDM_SWAT_Table->RSSI_sum_A += pPhyInfo->RxPWDBAll;
  5470. pDM_SWAT_Table->RSSI_cnt_A++;
  5471. }
  5472. else
  5473. {
  5474. pDM_SWAT_Table->RSSI_sum_B += pPhyInfo->RxPWDBAll;
  5475. pDM_SWAT_Table->RSSI_cnt_B++;
  5476. }
  5477. }
  5478. #endif
  5479. }
  5480. //
  5481. VOID
  5482. odm_SwAntDivChkAntSwitch(
  5483. IN PDM_ODM_T pDM_Odm,
  5484. IN u1Byte Step
  5485. )
  5486. {
  5487. //
  5488. // For AP/ADSL use prtl8192cd_priv
  5489. // For CE/NIC use PADAPTER
  5490. //
  5491. prtl8192cd_priv priv = pDM_Odm->priv;
  5492. //
  5493. // 2011/09/29 MH In HW integration first stage, we provide 4 different handle to operate
  5494. // at the same time. In the stage2/3, we need to prive universal interface and merge all
  5495. // HW dynamic mechanism.
  5496. //
  5497. switch (pDM_Odm->SupportPlatform)
  5498. {
  5499. case ODM_WIN:
  5500. odm_SwAntDivChkAntSwitchNIC(pDM_Odm, Step);
  5501. break;
  5502. case ODM_CE:
  5503. odm_SwAntDivChkAntSwitchNIC(pDM_Odm, Step);
  5504. break;
  5505. case ODM_AP:
  5506. case ODM_ADSL:
  5507. #if (DM_ODM_SUPPORT_TYPE & (ODM_AP |ODM_ADSL))
  5508. if (priv->pshare->rf_ft_var.antSw_enable && (priv->up_time % 4==1))
  5509. dm_SW_AntennaSwitch(priv, SWAW_STEP_PEAK);
  5510. #endif
  5511. break;
  5512. }
  5513. }
  5514. //
  5515. // 20100514 Luke/Joseph:
  5516. // Add new function for antenna diversity after link.
  5517. // This is the main function of antenna diversity after link.
  5518. // This function is called in HalDmWatchDog() and ODM_SwAntDivChkAntSwitchCallback().
  5519. // HalDmWatchDog() calls this function with SWAW_STEP_PEAK to initialize the antenna test.
  5520. // In SWAW_STEP_PEAK, another antenna and a 500ms timer will be set for testing.
  5521. // After 500ms, ODM_SwAntDivChkAntSwitchCallback() calls this function to compare the signal just
  5522. // listened on the air with the RSSI of original antenna.
  5523. // It chooses the antenna with better RSSI.
  5524. // There is also a aged policy for error trying. Each error trying will cost more 5 seconds waiting
  5525. // penalty to get next try.
  5526. VOID
  5527. ODM_SetAntenna(
  5528. IN PDM_ODM_T pDM_Odm,
  5529. IN u1Byte Antenna)
  5530. {
  5531. ODM_SetBBReg(pDM_Odm, 0x860, BIT8|BIT9, Antenna);
  5532. }
  5533. VOID
  5534. odm_SwAntDivChkAntSwitchNIC(
  5535. IN PDM_ODM_T pDM_Odm,
  5536. IN u1Byte Step
  5537. )
  5538. {
  5539. #if ((RTL8192C_SUPPORT==1)||(RTL8723A_SUPPORT==1))
  5540. //PMGNT_INFO pMgntInfo = &(Adapter->MgntInfo);
  5541. //HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  5542. #if (DM_ODM_SUPPORT_TYPE==ODM_WIN)
  5543. PADAPTER Adapter=pDM_Odm->Adapter;
  5544. #endif
  5545. pSWAT_T pDM_SWAT_Table = &pDM_Odm->DM_SWAT_Table;
  5546. s4Byte curRSSI=100, RSSI_A, RSSI_B;
  5547. u1Byte nextAntenna=AUX_ANT;
  5548. //static u8Byte lastTxOkCnt=0, lastRxOkCnt=0;
  5549. u8Byte curTxOkCnt=0, curRxOkCnt=0;
  5550. //static u8Byte TXByteCnt_A=0, TXByteCnt_B=0, RXByteCnt_A=0, RXByteCnt_B=0;
  5551. u8Byte CurByteCnt=0, PreByteCnt=0;
  5552. //static u1Byte TrafficLoad = TRAFFIC_LOW;
  5553. u1Byte Score_A=0, Score_B=0; //A: Main; B: AUX
  5554. u1Byte i;
  5555. if(!(pDM_Odm->SupportAbility & ODM_BB_ANT_DIV))
  5556. return;
  5557. if (pDM_Odm->SupportICType & (ODM_RTL8192D|ODM_RTL8188E))
  5558. return;
  5559. if((pDM_Odm->SupportICType == ODM_RTL8192C) &&(pDM_Odm->RFType == ODM_2T2R))
  5560. return;
  5561. if(pDM_Odm->SupportPlatform & ODM_WIN)
  5562. {
  5563. if(*(pDM_Odm->pAntennaTest))
  5564. return;
  5565. }
  5566. if((pDM_SWAT_Table->ANTA_ON == FALSE) ||(pDM_SWAT_Table->ANTB_ON == FALSE))
  5567. {
  5568. ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD,
  5569. ("odm_SwAntDivChkAntSwitch(): No AntDiv Mechanism, Antenna A or B is off\n"));
  5570. return;
  5571. }
  5572. // Radio off: Status reset to default and return.
  5573. if(*(pDM_Odm->pbPowerSaving)==TRUE) //pHalData->eRFPowerState==eRfOff
  5574. {
  5575. ODM_SwAntDivRestAfterLink(pDM_Odm);
  5576. return;
  5577. }
  5578. // Handling step mismatch condition.
  5579. // Peak step is not finished at last time. Recover the variable and check again.
  5580. if( Step != pDM_SWAT_Table->try_flag )
  5581. {
  5582. ODM_SwAntDivRestAfterLink(pDM_Odm);
  5583. }
  5584. #if (DM_ODM_SUPPORT_TYPE &( ODM_WIN| ODM_CE ))
  5585. if(pDM_SWAT_Table->try_flag == 0xff)
  5586. {
  5587. pDM_SWAT_Table->RSSI_target = 0xff;
  5588. #if(DM_ODM_SUPPORT_TYPE & ODM_CE)
  5589. {
  5590. u1Byte index = 0;
  5591. PSTA_INFO_T pEntry = NULL;
  5592. for(index=0; index<ODM_ASSOCIATE_ENTRY_NUM; index++)
  5593. {
  5594. pEntry = pDM_Odm->pODM_StaInfo[index];
  5595. if(IS_STA_VALID(pEntry) ) {
  5596. break;
  5597. }
  5598. }
  5599. if(pEntry == NULL)
  5600. {
  5601. ODM_SwAntDivRestAfterLink(pDM_Odm);
  5602. ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("odm_SwAntDivChkAntSwitch(): No Link.\n"));
  5603. return;
  5604. }
  5605. else
  5606. {
  5607. pDM_SWAT_Table->RSSI_target = index;
  5608. ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("odm_SwAntDivChkAntSwitch(): RSSI_target is PEER STA\n"));
  5609. }
  5610. }
  5611. #elif (DM_ODM_SUPPORT_TYPE & ODM_WIN)
  5612. {
  5613. PADAPTER pAdapter = pDM_Odm->Adapter;
  5614. PMGNT_INFO pMgntInfo=&pAdapter->MgntInfo;
  5615. // Select RSSI checking target
  5616. if(pMgntInfo->mAssoc && !ACTING_AS_AP(pAdapter))
  5617. {
  5618. // Target: Infrastructure mode AP.
  5619. //pDM_SWAT_Table->RSSI_target = NULL;
  5620. ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD,("odm_SwAntDivChkAntSwitch(): RSSI_target is DEF AP!\n"));
  5621. }
  5622. else
  5623. {
  5624. u1Byte index = 0;
  5625. PSTA_INFO_T pEntry = NULL;
  5626. PADAPTER pTargetAdapter = NULL;
  5627. if(pMgntInfo->mIbss )
  5628. {
  5629. // Target: AP/IBSS peer.
  5630. pTargetAdapter = pAdapter;
  5631. }
  5632. else
  5633. {
  5634. pTargetAdapter = GetFirstAPAdapter(pAdapter);
  5635. }
  5636. if(pTargetAdapter != NULL)
  5637. {
  5638. for(index=0; index<ODM_ASSOCIATE_ENTRY_NUM; index++)
  5639. {
  5640. pEntry = AsocEntry_EnumStation(pTargetAdapter, index);
  5641. if(pEntry != NULL)
  5642. {
  5643. if(pEntry->bAssociated)
  5644. break;
  5645. }
  5646. }
  5647. }
  5648. if(pEntry == NULL)
  5649. {
  5650. ODM_SwAntDivRestAfterLink(pDM_Odm);
  5651. ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("odm_SwAntDivChkAntSwitch(): No Link.\n"));
  5652. return;
  5653. }
  5654. else
  5655. {
  5656. //pDM_SWAT_Table->RSSI_target = pEntry;
  5657. pDM_SWAT_Table->RSSI_target = index;
  5658. ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("odm_SwAntDivChkAntSwitch(): RSSI_target is PEER STA\n"));
  5659. }
  5660. }//end if(pMgntInfo->mAssoc && !ACTING_AS_AP(Adapter))
  5661. }
  5662. #endif
  5663. pDM_SWAT_Table->RSSI_cnt_A = 0;
  5664. pDM_SWAT_Table->RSSI_cnt_B = 0;
  5665. pDM_SWAT_Table->try_flag = 0;
  5666. ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD,("odm_SwAntDivChkAntSwitch(): Set try_flag to 0 prepare for peak!\n"));
  5667. return;
  5668. }
  5669. else
  5670. {
  5671. // To Fix 8723A SW ANT DIV Bug issue
  5672. #if (DM_ODM_SUPPORT_TYPE==ODM_WIN)
  5673. if (pDM_Odm->SupportICType & ODM_RTL8723A)
  5674. {
  5675. curTxOkCnt = Adapter->TxStats.NumTxBytesUnicast - pDM_SWAT_Table->lastTxOkCnt;
  5676. curRxOkCnt =Adapter->RxStats.NumRxBytesUnicast - pDM_SWAT_Table->lastRxOkCnt;
  5677. pDM_SWAT_Table->lastTxOkCnt = Adapter->TxStats.NumTxBytesUnicast;
  5678. pDM_SWAT_Table->lastRxOkCnt = Adapter->RxStats.NumRxBytesUnicast;
  5679. }
  5680. #else
  5681. curTxOkCnt = *(pDM_Odm->pNumTxBytesUnicast) - pDM_SWAT_Table->lastTxOkCnt;
  5682. curRxOkCnt = *(pDM_Odm->pNumRxBytesUnicast) - pDM_SWAT_Table->lastRxOkCnt;
  5683. pDM_SWAT_Table->lastTxOkCnt = *(pDM_Odm->pNumTxBytesUnicast);
  5684. pDM_SWAT_Table->lastRxOkCnt = *(pDM_Odm->pNumRxBytesUnicast);
  5685. #endif
  5686. if(pDM_SWAT_Table->try_flag == 1)
  5687. {
  5688. if(pDM_SWAT_Table->CurAntenna == MAIN_ANT)
  5689. {
  5690. pDM_SWAT_Table->TXByteCnt_A += curTxOkCnt;
  5691. pDM_SWAT_Table->RXByteCnt_A += curRxOkCnt;
  5692. }
  5693. else
  5694. {
  5695. pDM_SWAT_Table->TXByteCnt_B += curTxOkCnt;
  5696. pDM_SWAT_Table->RXByteCnt_B += curRxOkCnt;
  5697. }
  5698. nextAntenna = (pDM_SWAT_Table->CurAntenna == MAIN_ANT)? AUX_ANT : MAIN_ANT;
  5699. pDM_SWAT_Table->RSSI_Trying--;
  5700. ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("RSSI_Trying = %d\n",pDM_SWAT_Table->RSSI_Trying));
  5701. if(pDM_SWAT_Table->RSSI_Trying == 0)
  5702. {
  5703. CurByteCnt = (pDM_SWAT_Table->CurAntenna == MAIN_ANT)? (pDM_SWAT_Table->TXByteCnt_A+pDM_SWAT_Table->RXByteCnt_A) : (pDM_SWAT_Table->TXByteCnt_B+pDM_SWAT_Table->RXByteCnt_B);
  5704. PreByteCnt = (pDM_SWAT_Table->CurAntenna == MAIN_ANT)? (pDM_SWAT_Table->TXByteCnt_B+pDM_SWAT_Table->RXByteCnt_B) : (pDM_SWAT_Table->TXByteCnt_A+pDM_SWAT_Table->RXByteCnt_A);
  5705. if(pDM_SWAT_Table->TrafficLoad == TRAFFIC_HIGH)
  5706. //CurByteCnt = PlatformDivision64(CurByteCnt, 9);
  5707. PreByteCnt = PreByteCnt*9;
  5708. else if(pDM_SWAT_Table->TrafficLoad == TRAFFIC_LOW)
  5709. //CurByteCnt = PlatformDivision64(CurByteCnt, 2);
  5710. PreByteCnt = PreByteCnt*2;
  5711. if(pDM_SWAT_Table->RSSI_cnt_A > 0)
  5712. RSSI_A = pDM_SWAT_Table->RSSI_sum_A/pDM_SWAT_Table->RSSI_cnt_A;
  5713. else
  5714. RSSI_A = 0;
  5715. if(pDM_SWAT_Table->RSSI_cnt_B > 0)
  5716. RSSI_B = pDM_SWAT_Table->RSSI_sum_B/pDM_SWAT_Table->RSSI_cnt_B;
  5717. else
  5718. RSSI_B = 0;
  5719. curRSSI = (pDM_SWAT_Table->CurAntenna == MAIN_ANT)? RSSI_A : RSSI_B;
  5720. pDM_SWAT_Table->PreRSSI = (pDM_SWAT_Table->CurAntenna == MAIN_ANT)? RSSI_B : RSSI_A;
  5721. ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("Luke:PreRSSI = %d, CurRSSI = %d\n",pDM_SWAT_Table->PreRSSI, curRSSI));
  5722. ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("SWAS: preAntenna= %s, curAntenna= %s \n",
  5723. (pDM_SWAT_Table->PreAntenna == MAIN_ANT?"MAIN":"AUX"), (pDM_SWAT_Table->CurAntenna == MAIN_ANT?"MAIN":"AUX")));
  5724. ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("Luke:RSSI_A= %d, RSSI_cnt_A = %d, RSSI_B= %d, RSSI_cnt_B = %d\n",
  5725. RSSI_A, pDM_SWAT_Table->RSSI_cnt_A, RSSI_B, pDM_SWAT_Table->RSSI_cnt_B));
  5726. }
  5727. }
  5728. else
  5729. {
  5730. if(pDM_SWAT_Table->RSSI_cnt_A > 0)
  5731. RSSI_A = pDM_SWAT_Table->RSSI_sum_A/pDM_SWAT_Table->RSSI_cnt_A;
  5732. else
  5733. RSSI_A = 0;
  5734. if(pDM_SWAT_Table->RSSI_cnt_B > 0)
  5735. RSSI_B = pDM_SWAT_Table->RSSI_sum_B/pDM_SWAT_Table->RSSI_cnt_B;
  5736. else
  5737. RSSI_B = 0;
  5738. curRSSI = (pDM_SWAT_Table->CurAntenna == MAIN_ANT)? RSSI_A : RSSI_B;
  5739. pDM_SWAT_Table->PreRSSI = (pDM_SWAT_Table->PreAntenna == MAIN_ANT)? RSSI_A : RSSI_B;
  5740. ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("Ekul:PreRSSI = %d, CurRSSI = %d\n", pDM_SWAT_Table->PreRSSI, curRSSI));
  5741. ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("SWAS: preAntenna= %s, curAntenna= %s \n",
  5742. (pDM_SWAT_Table->PreAntenna == MAIN_ANT?"MAIN":"AUX"), (pDM_SWAT_Table->CurAntenna == MAIN_ANT?"MAIN":"AUX")));
  5743. ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("Ekul:RSSI_A= %d, RSSI_cnt_A = %d, RSSI_B= %d, RSSI_cnt_B = %d\n",
  5744. RSSI_A, pDM_SWAT_Table->RSSI_cnt_A, RSSI_B, pDM_SWAT_Table->RSSI_cnt_B));
  5745. //RT_TRACE(COMP_SWAS, DBG_LOUD, ("Ekul:curTxOkCnt = %d\n", curTxOkCnt));
  5746. //RT_TRACE(COMP_SWAS, DBG_LOUD, ("Ekul:curRxOkCnt = %d\n", curRxOkCnt));
  5747. }
  5748. //1 Trying State
  5749. if((pDM_SWAT_Table->try_flag == 1)&&(pDM_SWAT_Table->RSSI_Trying == 0))
  5750. {
  5751. if(pDM_SWAT_Table->TestMode == TP_MODE)
  5752. {
  5753. ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("SWAS: TestMode = TP_MODE"));
  5754. ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("TRY:CurByteCnt = %lld,", CurByteCnt));
  5755. ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("TRY:PreByteCnt = %lld\n",PreByteCnt));
  5756. if(CurByteCnt < PreByteCnt)
  5757. {
  5758. if(pDM_SWAT_Table->CurAntenna == MAIN_ANT)
  5759. pDM_SWAT_Table->SelectAntennaMap=pDM_SWAT_Table->SelectAntennaMap<<1;
  5760. else
  5761. pDM_SWAT_Table->SelectAntennaMap=(pDM_SWAT_Table->SelectAntennaMap<<1)+1;
  5762. }
  5763. else
  5764. {
  5765. if(pDM_SWAT_Table->CurAntenna == MAIN_ANT)
  5766. pDM_SWAT_Table->SelectAntennaMap=(pDM_SWAT_Table->SelectAntennaMap<<1)+1;
  5767. else
  5768. pDM_SWAT_Table->SelectAntennaMap=pDM_SWAT_Table->SelectAntennaMap<<1;
  5769. }
  5770. for (i= 0; i<8; i++)
  5771. {
  5772. if(((pDM_SWAT_Table->SelectAntennaMap>>i)&BIT0) == 1)
  5773. Score_A++;
  5774. else
  5775. Score_B++;
  5776. }
  5777. ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("SelectAntennaMap=%x\n ",pDM_SWAT_Table->SelectAntennaMap));
  5778. ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("Score_A=%d, Score_B=%d\n", Score_A, Score_B));
  5779. if(pDM_SWAT_Table->CurAntenna == MAIN_ANT)
  5780. {
  5781. nextAntenna = (Score_A > Score_B)?MAIN_ANT:AUX_ANT;
  5782. }
  5783. else
  5784. {
  5785. nextAntenna = (Score_B > Score_A)?AUX_ANT:MAIN_ANT;
  5786. }
  5787. //RT_TRACE(COMP_SWAS, DBG_LOUD, ("nextAntenna=%s\n",(nextAntenna==Antenna_A)?"A":"B"));
  5788. //RT_TRACE(COMP_SWAS, DBG_LOUD, ("preAntenna= %s, curAntenna= %s \n",
  5789. //(DM_SWAT_Table.PreAntenna == Antenna_A?"A":"B"), (DM_SWAT_Table.CurAntenna == Antenna_A?"A":"B")));
  5790. if(nextAntenna != pDM_SWAT_Table->CurAntenna)
  5791. {
  5792. ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("SWAS: Switch back to another antenna"));
  5793. }
  5794. else
  5795. {
  5796. ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("SWAS: current anntena is good\n"));
  5797. }
  5798. }
  5799. if(pDM_SWAT_Table->TestMode == RSSI_MODE)
  5800. {
  5801. ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("SWAS: TestMode = RSSI_MODE"));
  5802. pDM_SWAT_Table->SelectAntennaMap=0xAA;
  5803. if(curRSSI < pDM_SWAT_Table->PreRSSI) //Current antenna is worse than previous antenna
  5804. {
  5805. ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("SWAS: Switch back to another antenna"));
  5806. nextAntenna = (pDM_SWAT_Table->CurAntenna == MAIN_ANT)? AUX_ANT : MAIN_ANT;
  5807. }
  5808. else // current anntena is good
  5809. {
  5810. nextAntenna =pDM_SWAT_Table->CurAntenna;
  5811. ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("SWAS: current anntena is good\n"));
  5812. }
  5813. }
  5814. pDM_SWAT_Table->try_flag = 0;
  5815. pDM_Odm->RSSI_test = FALSE;
  5816. pDM_SWAT_Table->RSSI_sum_A = 0;
  5817. pDM_SWAT_Table->RSSI_cnt_A = 0;
  5818. pDM_SWAT_Table->RSSI_sum_B = 0;
  5819. pDM_SWAT_Table->RSSI_cnt_B = 0;
  5820. pDM_SWAT_Table->TXByteCnt_A = 0;
  5821. pDM_SWAT_Table->TXByteCnt_B = 0;
  5822. pDM_SWAT_Table->RXByteCnt_A = 0;
  5823. pDM_SWAT_Table->RXByteCnt_B = 0;
  5824. }
  5825. //1 Normal State
  5826. else if(pDM_SWAT_Table->try_flag == 0)
  5827. {
  5828. if(pDM_SWAT_Table->TrafficLoad == TRAFFIC_HIGH)
  5829. {
  5830. if ((curTxOkCnt+curRxOkCnt) > 3750000)//if(PlatformDivision64(curTxOkCnt+curRxOkCnt, 2) > 1875000)
  5831. pDM_SWAT_Table->TrafficLoad = TRAFFIC_HIGH;
  5832. else
  5833. pDM_SWAT_Table->TrafficLoad = TRAFFIC_LOW;
  5834. }
  5835. else if(pDM_SWAT_Table->TrafficLoad == TRAFFIC_LOW)
  5836. {
  5837. if ((curTxOkCnt+curRxOkCnt) > 3750000) //if(PlatformDivision64(curTxOkCnt+curRxOkCnt, 2) > 1875000)
  5838. pDM_SWAT_Table->TrafficLoad = TRAFFIC_HIGH;
  5839. else
  5840. pDM_SWAT_Table->TrafficLoad = TRAFFIC_LOW;
  5841. }
  5842. if(pDM_SWAT_Table->TrafficLoad == TRAFFIC_HIGH)
  5843. pDM_SWAT_Table->bTriggerAntennaSwitch = 0;
  5844. //RT_TRACE(COMP_SWAS, DBG_LOUD, ("Normal:TrafficLoad = %llu\n", curTxOkCnt+curRxOkCnt));
  5845. //Prepare To Try Antenna
  5846. nextAntenna = (pDM_SWAT_Table->CurAntenna == MAIN_ANT)? AUX_ANT : MAIN_ANT;
  5847. pDM_SWAT_Table->try_flag = 1;
  5848. pDM_Odm->RSSI_test = TRUE;
  5849. if((curRxOkCnt+curTxOkCnt) > 1000)
  5850. {
  5851. pDM_SWAT_Table->RSSI_Trying = 4;
  5852. pDM_SWAT_Table->TestMode = TP_MODE;
  5853. }
  5854. else
  5855. {
  5856. pDM_SWAT_Table->RSSI_Trying = 2;
  5857. pDM_SWAT_Table->TestMode = RSSI_MODE;
  5858. }
  5859. ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("SWAS: Normal State -> Begin Trying!\n"));
  5860. pDM_SWAT_Table->RSSI_sum_A = 0;
  5861. pDM_SWAT_Table->RSSI_cnt_A = 0;
  5862. pDM_SWAT_Table->RSSI_sum_B = 0;
  5863. pDM_SWAT_Table->RSSI_cnt_B = 0;
  5864. }
  5865. }
  5866. //1 4.Change TRX antenna
  5867. if(nextAntenna != pDM_SWAT_Table->CurAntenna)
  5868. {
  5869. ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("SWAS: Change TX Antenna!\n "));
  5870. //PHY_SetBBReg(Adapter, rFPGA0_XA_RFInterfaceOE, 0x300, nextAntenna);
  5871. #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
  5872. ODM_SetAntenna(pDM_Odm,nextAntenna);
  5873. #elif (DM_ODM_SUPPORT_TYPE == ODM_CE)
  5874. {
  5875. BOOLEAN bEnqueue;
  5876. bEnqueue = (pDM_Odm->SupportInterface == ODM_ITRF_PCIE)?FALSE :TRUE;
  5877. rtw_antenna_select_cmd(pDM_Odm->Adapter, nextAntenna, bEnqueue);
  5878. }
  5879. #endif
  5880. }
  5881. //1 5.Reset Statistics
  5882. pDM_SWAT_Table->PreAntenna = pDM_SWAT_Table->CurAntenna;
  5883. pDM_SWAT_Table->CurAntenna = nextAntenna;
  5884. pDM_SWAT_Table->PreRSSI = curRSSI;
  5885. //1 6.Set next timer
  5886. {
  5887. //PADAPTER pAdapter = pDM_Odm->Adapter;
  5888. //HAL_DATA_TYPE *pHalData = GET_HAL_DATA(pAdapter);
  5889. if(pDM_SWAT_Table->RSSI_Trying == 0)
  5890. return;
  5891. if(pDM_SWAT_Table->RSSI_Trying%2 == 0)
  5892. {
  5893. if(pDM_SWAT_Table->TestMode == TP_MODE)
  5894. {
  5895. if(pDM_SWAT_Table->TrafficLoad == TRAFFIC_HIGH)
  5896. {
  5897. //PlatformSetTimer( pAdapter, &pHalData->SwAntennaSwitchTimer, 10 ); //ms
  5898. ODM_SetTimer(pDM_Odm,&pDM_SWAT_Table->SwAntennaSwitchTimer, 10 ); //ms
  5899. ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("dm_SW_AntennaSwitch(): Test another antenna for 10 ms\n"));
  5900. }
  5901. else if(pDM_SWAT_Table->TrafficLoad == TRAFFIC_LOW)
  5902. {
  5903. //PlatformSetTimer( pAdapter, &pHalData->SwAntennaSwitchTimer, 50 ); //ms
  5904. ODM_SetTimer(pDM_Odm,&pDM_SWAT_Table->SwAntennaSwitchTimer, 50 ); //ms
  5905. ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("dm_SW_AntennaSwitch(): Test another antenna for 50 ms\n"));
  5906. }
  5907. }
  5908. else
  5909. {
  5910. //PlatformSetTimer( pAdapter, &pHalData->SwAntennaSwitchTimer, 500 ); //ms
  5911. ODM_SetTimer(pDM_Odm,&pDM_SWAT_Table->SwAntennaSwitchTimer, 500 ); //ms
  5912. ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("dm_SW_AntennaSwitch(): Test another antenna for 500 ms\n"));
  5913. }
  5914. }
  5915. else
  5916. {
  5917. if(pDM_SWAT_Table->TestMode == TP_MODE)
  5918. {
  5919. if(pDM_SWAT_Table->TrafficLoad == TRAFFIC_HIGH)
  5920. //PlatformSetTimer( pAdapter, &pHalData->SwAntennaSwitchTimer, 90 ); //ms
  5921. ODM_SetTimer(pDM_Odm,&pDM_SWAT_Table->SwAntennaSwitchTimer, 90 ); //ms
  5922. else if(pDM_SWAT_Table->TrafficLoad == TRAFFIC_LOW)
  5923. //PlatformSetTimer( pAdapter, &pHalData->SwAntennaSwitchTimer, 100 ); //ms
  5924. ODM_SetTimer(pDM_Odm,&pDM_SWAT_Table->SwAntennaSwitchTimer, 100 ); //ms
  5925. }
  5926. else
  5927. //PlatformSetTimer( pAdapter, &pHalData->SwAntennaSwitchTimer, 500 ); //ms
  5928. ODM_SetTimer(pDM_Odm,&pDM_SWAT_Table->SwAntennaSwitchTimer, 500 ); //ms
  5929. }
  5930. }
  5931. #endif // #if (DM_ODM_SUPPORT_TYPE & (ODM_WIN|ODM_CE))
  5932. #endif // #if (RTL8192C_SUPPORT==1)
  5933. }
  5934. #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
  5935. u1Byte
  5936. odm_SwAntDivSelectChkChnl(
  5937. IN PADAPTER Adapter
  5938. )
  5939. {
  5940. #if (RT_MEM_SIZE_LEVEL != RT_MEM_SIZE_MINIMUM)
  5941. u1Byte index, target_chnl=0;
  5942. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  5943. PDM_ODM_T pDM_Odm = &pHalData->DM_OutSrc;
  5944. u1Byte chnl_peer_cnt[14] = {0};
  5945. if(Adapter->MgntInfo.tmpNumBssDesc==0)
  5946. {
  5947. return 0;
  5948. }
  5949. else
  5950. {
  5951. // 20100519 Joseph: Select checking channel from current scan list.
  5952. // We just choose the channel with most APs to be the test scan channel.
  5953. for(index=0; index<Adapter->MgntInfo.tmpNumBssDesc; index++)
  5954. {
  5955. // Add by hpfan: prevent access invalid channel number
  5956. // TODO: Verify channel number by channel plan
  5957. if(Adapter->MgntInfo.tmpbssDesc[index].ChannelNumber == 0 ||
  5958. Adapter->MgntInfo.tmpbssDesc[index].ChannelNumber > 13)
  5959. continue;
  5960. chnl_peer_cnt[Adapter->MgntInfo.tmpbssDesc[index].ChannelNumber-1]++;
  5961. }
  5962. for(index=0; index<14; index++)
  5963. {
  5964. if(chnl_peer_cnt[index]>chnl_peer_cnt[target_chnl])
  5965. target_chnl = index;
  5966. }
  5967. target_chnl+=1;
  5968. ODM_RT_TRACE(pDM_Odm,COMP_SWAS, DBG_LOUD,
  5969. ("odm_SwAntDivSelectChkChnl(): Channel %d is select as test channel.\n", target_chnl));
  5970. return target_chnl;
  5971. }
  5972. #else
  5973. return 0;
  5974. #endif
  5975. }
  5976. VOID
  5977. odm_SwAntDivConsructChkScanChnl(
  5978. IN PADAPTER Adapter,
  5979. IN u1Byte ChkChnl
  5980. )
  5981. {
  5982. PMGNT_INFO pMgntInfo = &Adapter->MgntInfo;
  5983. PRT_CHANNEL_LIST pChannelList = GET_RT_CHANNEL_LIST(pMgntInfo);
  5984. u1Byte index;
  5985. if(ChkChnl==0)
  5986. {
  5987. // 20100519 Joseph: Original antenna scanned nothing.
  5988. // Test antenna shall scan all channel with half period in this condition.
  5989. RtActChannelList(Adapter, RT_CHNL_LIST_ACTION_CONSTRUCT_SCAN_LIST, NULL, NULL);
  5990. for(index=0; index<pChannelList->ChannelLen; index++)
  5991. pChannelList->ChnlListEntry[index].ScanPeriod /= 2;
  5992. }
  5993. else
  5994. {
  5995. // The using of this CustomizedScanRequest is a trick to rescan the two channels
  5996. // under the NORMAL scanning process. It will not affect MGNT_INFO.CustomizedScanRequest.
  5997. CUSTOMIZED_SCAN_REQUEST CustomScanReq;
  5998. CustomScanReq.bEnabled = TRUE;
  5999. CustomScanReq.Channels[0] = ChkChnl;
  6000. CustomScanReq.Channels[1] = pMgntInfo->dot11CurrentChannelNumber;
  6001. CustomScanReq.nChannels = 2;
  6002. CustomScanReq.ScanType = SCAN_ACTIVE;
  6003. CustomScanReq.Duration = DEFAULT_ACTIVE_SCAN_PERIOD;
  6004. RtActChannelList(Adapter, RT_CHNL_LIST_ACTION_CONSTRUCT_SCAN_LIST, &CustomScanReq, NULL);
  6005. }
  6006. }
  6007. #endif //#if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
  6008. //
  6009. // 20100514 Luke/Joseph:
  6010. // Callback function for 500ms antenna test trying.
  6011. //
  6012. #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
  6013. VOID
  6014. odm_SwAntDivChkAntSwitchCallback(
  6015. PRT_TIMER pTimer
  6016. )
  6017. {
  6018. PADAPTER Adapter = (PADAPTER)pTimer->Adapter;
  6019. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  6020. pSWAT_T pDM_SWAT_Table = &pHalData->DM_OutSrc.DM_SWAT_Table;
  6021. #if DEV_BUS_TYPE==RT_PCI_INTERFACE
  6022. #if USE_WORKITEM
  6023. ODM_ScheduleWorkItem(&pDM_SWAT_Table->SwAntennaSwitchWorkitem);
  6024. #else
  6025. odm_SwAntDivChkAntSwitch(&pHalData->DM_OutSrc, SWAW_STEP_DETERMINE);
  6026. #endif
  6027. #else
  6028. ODM_ScheduleWorkItem(&pDM_SWAT_Table->SwAntennaSwitchWorkitem);
  6029. #endif
  6030. }
  6031. VOID
  6032. odm_SwAntDivChkAntSwitchWorkitemCallback(
  6033. IN PVOID pContext
  6034. )
  6035. {
  6036. PADAPTER pAdapter = (PADAPTER)pContext;
  6037. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(pAdapter);
  6038. odm_SwAntDivChkAntSwitch(&pHalData->DM_OutSrc, SWAW_STEP_DETERMINE);
  6039. }
  6040. #elif (DM_ODM_SUPPORT_TYPE == ODM_CE)
  6041. VOID odm_SwAntDivChkAntSwitchCallback(void *FunctionContext)
  6042. {
  6043. PDM_ODM_T pDM_Odm= (PDM_ODM_T)FunctionContext;
  6044. PADAPTER padapter = pDM_Odm->Adapter;
  6045. if(padapter->net_closed == _TRUE)
  6046. return;
  6047. odm_SwAntDivChkAntSwitch(pDM_Odm, SWAW_STEP_DETERMINE);
  6048. }
  6049. #elif (DM_ODM_SUPPORT_TYPE & (ODM_AP|ODM_ADSL))
  6050. VOID odm_SwAntDivChkAntSwitchCallback(void *FunctionContext)
  6051. {
  6052. PDM_ODM_T pDM_Odm= (PDM_ODM_T)FunctionContext;
  6053. odm_SwAntDivChkAntSwitch(pDM_Odm, SWAW_STEP_DETERMINE);
  6054. }
  6055. #endif
  6056. #else //#if(defined(CONFIG_SW_ANTENNA_DIVERSITY))
  6057. VOID odm_SwAntDivInit( IN PDM_ODM_T pDM_Odm ) {}
  6058. VOID ODM_SwAntDivChkPerPktRssi(
  6059. IN PDM_ODM_T pDM_Odm,
  6060. IN u1Byte StationID,
  6061. IN PODM_PHY_INFO_T pPhyInfo
  6062. ) {}
  6063. VOID odm_SwAntDivChkAntSwitch(
  6064. IN PDM_ODM_T pDM_Odm,
  6065. IN u1Byte Step
  6066. ) {}
  6067. VOID ODM_SwAntDivResetBeforeLink( IN PDM_ODM_T pDM_Odm ){}
  6068. VOID ODM_SwAntDivRestAfterLink( IN PDM_ODM_T pDM_Odm ){}
  6069. #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
  6070. u1Byte odm_SwAntDivSelectChkChnl( IN PADAPTER Adapter ){ return 0;}
  6071. VOID
  6072. odm_SwAntDivConsructChkScanChnl(
  6073. IN PADAPTER Adapter,
  6074. IN u1Byte ChkChnl
  6075. ){}
  6076. #endif
  6077. #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
  6078. VOID odm_SwAntDivChkAntSwitchCallback( PRT_TIMER pTimer){}
  6079. VOID odm_SwAntDivChkAntSwitchWorkitemCallback( IN PVOID pContext ){}
  6080. #elif (DM_ODM_SUPPORT_TYPE == ODM_CE)
  6081. VOID odm_SwAntDivChkAntSwitchCallback(void *FunctionContext){}
  6082. #elif (DM_ODM_SUPPORT_TYPE & (ODM_AP|ODM_ADSL))
  6083. VOID odm_SwAntDivChkAntSwitchCallback(void *FunctionContext){}
  6084. #endif
  6085. #endif //#if(defined(CONFIG_SW_ANTENNA_DIVERSITY))
  6086. #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
  6087. #if((defined(CONFIG_SW_ANTENNA_DIVERSITY))||(defined(CONFIG_HW_ANTENNA_DIVERSITY)))
  6088. BOOLEAN
  6089. ODM_SwAntDivCheckBeforeLink8192C(
  6090. IN PDM_ODM_T pDM_Odm
  6091. )
  6092. {
  6093. #if (RT_MEM_SIZE_LEVEL != RT_MEM_SIZE_MINIMUM)
  6094. PADAPTER Adapter = pDM_Odm->Adapter;
  6095. HAL_DATA_TYPE* pHalData = NULL;
  6096. PMGNT_INFO pMgntInfo = NULL;
  6097. //pSWAT_T pDM_SWAT_Table = &Adapter->DM_SWAT_Table;
  6098. pSWAT_T pDM_SWAT_Table = &pDM_Odm->DM_SWAT_Table;
  6099. pFAT_T pDM_FatTable = &pDM_Odm->DM_FatTable;
  6100. s1Byte Score = 0;
  6101. PRT_WLAN_BSS pTmpBssDesc;
  6102. PRT_WLAN_BSS pTestBssDesc;
  6103. u1Byte target_chnl = 0;
  6104. u1Byte index;
  6105. return FALSE;
  6106. if (pDM_Odm->Adapter == NULL) //For BSOD when plug/unplug fast. //By YJ,120413
  6107. { // The ODM structure is not initialized.
  6108. return FALSE;
  6109. }
  6110. // 2012/04/26 MH Prevent no-checked IC to execute antenna diversity.
  6111. if(pDM_Odm->SupportICType == ODM_RTL8188E && pDM_Odm->SupportInterface != ODM_ITRF_PCIE)
  6112. return FALSE;
  6113. pHalData = GET_HAL_DATA(Adapter);
  6114. pMgntInfo = &Adapter->MgntInfo;
  6115. // Condition that does not need to use antenna diversity.
  6116. if(IS_8723A_SERIES(pHalData->VersionID) ||
  6117. IS_92C_SERIAL(pHalData->VersionID) ||
  6118. (pHalData->AntDivCfg==0) ||
  6119. pMgntInfo->AntennaTest ||
  6120. Adapter->bInHctTest)
  6121. {
  6122. ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD,
  6123. ("ODM_SwAntDivCheckBeforeLink8192C(): No AntDiv Mechanism.\n"));
  6124. return FALSE;
  6125. }
  6126. if(IS_8723A_SERIES(pHalData->VersionID) || IS_92C_SERIAL(pHalData->VersionID) )
  6127. {
  6128. if((pDM_SWAT_Table->ANTA_ON == FALSE) ||(pDM_SWAT_Table->ANTB_ON == FALSE))
  6129. {
  6130. ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD,
  6131. ("ODM_SwAntDivCheckBeforeLink8192C(): No AntDiv Mechanism, Antenna A or B is off\n"));
  6132. return FALSE;
  6133. }
  6134. }
  6135. // Since driver is going to set BB register, it shall check if there is another thread controlling BB/RF.
  6136. PlatformAcquireSpinLock(Adapter, RT_RF_STATE_SPINLOCK);
  6137. if(pHalData->eRFPowerState!=eRfOn || pMgntInfo->RFChangeInProgress || pMgntInfo->bMediaConnect)
  6138. {
  6139. PlatformReleaseSpinLock(Adapter, RT_RF_STATE_SPINLOCK);
  6140. ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD,
  6141. ("ODM_SwAntDivCheckBeforeLink8192C(): RFChangeInProgress(%x), eRFPowerState(%x)\n",
  6142. pMgntInfo->RFChangeInProgress,
  6143. pHalData->eRFPowerState));
  6144. pDM_SWAT_Table->SWAS_NoLink_State = 0;
  6145. return FALSE;
  6146. }
  6147. else
  6148. {
  6149. PlatformReleaseSpinLock(Adapter, RT_RF_STATE_SPINLOCK);
  6150. }
  6151. //1 Run AntDiv mechanism "Before Link" part.
  6152. if(pDM_SWAT_Table->SWAS_NoLink_State == 0)
  6153. {
  6154. //1 Prepare to do Scan again to check current antenna state.
  6155. // Set check state to next step.
  6156. pDM_SWAT_Table->SWAS_NoLink_State = 1;
  6157. // Copy Current Scan list.
  6158. Adapter->MgntInfo.tmpNumBssDesc = pMgntInfo->NumBssDesc;
  6159. PlatformMoveMemory((PVOID)Adapter->MgntInfo.tmpbssDesc, (PVOID)pMgntInfo->bssDesc, sizeof(RT_WLAN_BSS)*MAX_BSS_DESC);
  6160. if(pDM_Odm->SupportICType == ODM_RTL8188E)
  6161. {
  6162. if(pDM_FatTable->RxIdleAnt == MAIN_ANT)
  6163. ODM_UpdateRxIdleAnt_88E(pDM_Odm, AUX_ANT);
  6164. else
  6165. ODM_UpdateRxIdleAnt_88E(pDM_Odm, MAIN_ANT);
  6166. ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD,
  6167. ("ODM_SwAntDivCheckBeforeLink8192C: Change to %s for testing.\n", ((pDM_FatTable->RxIdleAnt == MAIN_ANT)?"MAIN_ANT":"AUX_ANT")));
  6168. }
  6169. if(pDM_Odm->SupportICType != ODM_RTL8188E)
  6170. {
  6171. // Switch Antenna to another one.
  6172. pDM_SWAT_Table->PreAntenna = pDM_SWAT_Table->CurAntenna;
  6173. pDM_SWAT_Table->CurAntenna = (pDM_SWAT_Table->CurAntenna==MAIN_ANT)?AUX_ANT:MAIN_ANT;
  6174. ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD,
  6175. ("ODM_SwAntDivCheckBeforeLink8192C: Change to Ant(%s) for testing.\n", (pDM_SWAT_Table->CurAntenna==MAIN_ANT)?"MAIN":"AUX"));
  6176. //PHY_SetBBReg(Adapter, rFPGA0_XA_RFInterfaceOE, 0x300, DM_SWAT_Table.CurAntenna);
  6177. pDM_SWAT_Table->SWAS_NoLink_BK_Reg860 = ((pDM_SWAT_Table->SWAS_NoLink_BK_Reg860 & 0xfffffcff) | (pDM_SWAT_Table->CurAntenna<<8));
  6178. ODM_SetBBReg(pDM_Odm, rFPGA0_XA_RFInterfaceOE, bMaskDWord, pDM_SWAT_Table->SWAS_NoLink_BK_Reg860);
  6179. }
  6180. // Go back to scan function again.
  6181. ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("ODM_SwAntDivCheckBeforeLink8192C: Scan one more time\n"));
  6182. pMgntInfo->ScanStep=0;
  6183. target_chnl = odm_SwAntDivSelectChkChnl(Adapter);
  6184. odm_SwAntDivConsructChkScanChnl(Adapter, target_chnl);
  6185. CHNL_ReleaseOpLock(Adapter);
  6186. PlatformSetTimer(Adapter, &pMgntInfo->ScanTimer, 5);
  6187. return TRUE;
  6188. }
  6189. else
  6190. {
  6191. //1 ScanComple() is called after antenna swiched.
  6192. //1 Check scan result and determine which antenna is going
  6193. //1 to be used.
  6194. for(index=0; index<Adapter->MgntInfo.tmpNumBssDesc; index++)
  6195. {
  6196. pTmpBssDesc = &(Adapter->MgntInfo.tmpbssDesc[index]);
  6197. pTestBssDesc = &(pMgntInfo->bssDesc[index]);
  6198. if(PlatformCompareMemory(pTestBssDesc->bdBssIdBuf, pTmpBssDesc->bdBssIdBuf, 6)!=0)
  6199. {
  6200. ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("ODM_SwAntDivCheckBeforeLink8192C(): ERROR!! This shall not happen.\n"));
  6201. continue;
  6202. }
  6203. if(pTmpBssDesc->RecvSignalPower > pTestBssDesc->RecvSignalPower)
  6204. {
  6205. ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("ODM_SwAntDivCheckBeforeLink8192C: Compare scan entry: Score++\n"));
  6206. RT_PRINT_STR(ODM_COMP_ANT_DIV, ODM_DBG_LOUD, "SSID: ", pTestBssDesc->bdSsIdBuf, pTestBssDesc->bdSsIdLen);
  6207. ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("Original: %d, Test: %d\n", pTmpBssDesc->RecvSignalPower, pTestBssDesc->RecvSignalPower));
  6208. Score++;
  6209. PlatformMoveMemory(pTestBssDesc, pTmpBssDesc, sizeof(RT_WLAN_BSS));
  6210. }
  6211. else if(pTmpBssDesc->RecvSignalPower < pTestBssDesc->RecvSignalPower)
  6212. {
  6213. ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("ODM_SwAntDivCheckBeforeLink8192C: Compare scan entry: Score--\n"));
  6214. RT_PRINT_STR(ODM_COMP_ANT_DIV, ODM_DBG_LOUD, "SSID: ", pTestBssDesc->bdSsIdBuf, pTestBssDesc->bdSsIdLen);
  6215. ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("Original: %d, Test: %d\n", pTmpBssDesc->RecvSignalPower, pTestBssDesc->RecvSignalPower));
  6216. Score--;
  6217. }
  6218. }
  6219. if(pDM_Odm->SupportICType == ODM_RTL8188E)
  6220. {
  6221. if(pMgntInfo->NumBssDesc!=0 && Score<=0)
  6222. {
  6223. ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD,
  6224. ("ODM_SwAntDivCheckBeforeLink8192C(): Using Ant(%s)\n", (pDM_FatTable->RxIdleAnt==MAIN_ANT)?"MAIN_ANT":"AUX_ANT"));
  6225. }
  6226. else
  6227. {
  6228. ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD,
  6229. ("ODM_SwAntDivCheckBeforeLink8192C(): Remain Ant(%s)\n", (pDM_FatTable->RxIdleAnt==MAIN_ANT)?"AUX_ANT":"MAIN_ANT"));
  6230. if(pDM_FatTable->RxIdleAnt == MAIN_ANT)
  6231. ODM_UpdateRxIdleAnt_88E(pDM_Odm, AUX_ANT);
  6232. else
  6233. ODM_UpdateRxIdleAnt_88E(pDM_Odm, MAIN_ANT);
  6234. }
  6235. }
  6236. if(pDM_Odm->SupportICType != ODM_RTL8188E)
  6237. {
  6238. if(pMgntInfo->NumBssDesc!=0 && Score<=0)
  6239. {
  6240. ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD,
  6241. ("ODM_SwAntDivCheckBeforeLink8192C(): Using Ant(%s)\n", (pDM_SWAT_Table->CurAntenna==MAIN_ANT)?"MAIN":"AUX"));
  6242. pDM_SWAT_Table->PreAntenna = pDM_SWAT_Table->CurAntenna;
  6243. }
  6244. else
  6245. {
  6246. ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD,
  6247. ("ODM_SwAntDivCheckBeforeLink8192C(): Remain Ant(%s)\n", (pDM_SWAT_Table->CurAntenna==MAIN_ANT)?"AUX":"MAIN"));
  6248. pDM_SWAT_Table->CurAntenna = pDM_SWAT_Table->PreAntenna;
  6249. //PHY_SetBBReg(Adapter, rFPGA0_XA_RFInterfaceOE, 0x300, DM_SWAT_Table.CurAntenna);
  6250. pDM_SWAT_Table->SWAS_NoLink_BK_Reg860 = ((pDM_SWAT_Table->SWAS_NoLink_BK_Reg860 & 0xfffffcff) | (pDM_SWAT_Table->CurAntenna<<8));
  6251. PHY_SetBBReg(Adapter, rFPGA0_XA_RFInterfaceOE, bMaskDWord, pDM_SWAT_Table->SWAS_NoLink_BK_Reg860);
  6252. }
  6253. }
  6254. // Check state reset to default and wait for next time.
  6255. pDM_SWAT_Table->SWAS_NoLink_State = 0;
  6256. return FALSE;
  6257. }
  6258. #else
  6259. return FALSE;
  6260. #endif
  6261. return FALSE;
  6262. }
  6263. #else
  6264. BOOLEAN
  6265. ODM_SwAntDivCheckBeforeLink8192C(
  6266. IN PDM_ODM_T pDM_Odm
  6267. )
  6268. {
  6269. return FALSE;
  6270. }
  6271. #endif //#if((defined(CONFIG_SW_ANTENNA_DIVERSITY))||(defined(CONFIG_HW_ANTENNA_DIVERSITY)))
  6272. #endif //#if(DM_ODM_SUPPORT_TYPE==ODM_WIN)
  6273. //3============================================================
  6274. //3 SW Antenna Diversity
  6275. //3============================================================
  6276. #if(defined(CONFIG_HW_ANTENNA_DIVERSITY))
  6277. VOID
  6278. odm_InitHybridAntDiv_88C_92D(
  6279. IN PDM_ODM_T pDM_Odm
  6280. )
  6281. {
  6282. #if((DM_ODM_SUPPORT_TYPE==ODM_AP)||(DM_ODM_SUPPORT_TYPE==ODM_ADSL))
  6283. struct rtl8192cd_priv *priv=pDM_Odm->priv;
  6284. #endif
  6285. SWAT_T *pDM_SWAT_Table = &pDM_Odm->DM_SWAT_Table;
  6286. u1Byte bTxPathSel=0; //0:Path-A 1:Path-B
  6287. u1Byte i;
  6288. ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV,ODM_DBG_LOUD,("odm_InitHybridAntDiv==============>\n"));
  6289. //whether to do antenna diversity or not
  6290. #if(DM_ODM_SUPPORT_TYPE==ODM_AP)
  6291. if(priv==NULL) return;
  6292. if(!priv->pshare->rf_ft_var.antHw_enable)
  6293. return;
  6294. #ifdef SW_ANT_SWITCH
  6295. priv->pshare->rf_ft_var.antSw_enable =0;
  6296. #endif
  6297. #endif
  6298. if((pDM_Odm->SupportICType != ODM_RTL8192C) && (pDM_Odm->SupportICType != ODM_RTL8192D))
  6299. return;
  6300. bTxPathSel=(pDM_Odm->RFType==ODM_1T1R)?FALSE:TRUE;
  6301. ODM_SetBBReg(pDM_Odm,ODM_REG_BB_PWR_SAV1_11N, BIT23, 0); //No update ANTSEL during GNT_BT=1
  6302. ODM_SetBBReg(pDM_Odm,ODM_REG_TX_ANT_CTRL_11N, BIT21, 1); //TX atenna selection from tx_info
  6303. ODM_SetBBReg(pDM_Odm,ODM_REG_ANTSEL_PIN_11N, BIT23, 1); //enable LED[1:0] pin as ANTSEL
  6304. ODM_SetBBReg(pDM_Odm,ODM_REG_ANTSEL_CTRL_11N, BIT8|BIT9, 0x01); // 0x01: left antenna, 0x02: right antenna
  6305. // check HW setting: ANTSEL pin connection
  6306. #if(DM_ODM_SUPPORT_TYPE==ODM_AP)
  6307. ODM_Write2Byte(pDM_Odm,ODM_REG_RF_PIN_11N, (ODM_Read2Byte(pDM_Odm,0x804)&0xf0ff )| BIT(8) ); // b11-b8=0001,update RFPin setting
  6308. #endif
  6309. // only AP support different path selection temperarly
  6310. if(!bTxPathSel){ //PATH-A
  6311. ODM_SetBBReg(pDM_Odm,ODM_REG_PIN_CTRL_11N, BIT8|BIT9, 0 ); // ANTSEL as HW control
  6312. ODM_SetBBReg(pDM_Odm,ODM_REG_ANTSEL_PATH_11N, BIT13, 1); //select TX ANTESEL from path A
  6313. }
  6314. else {
  6315. ODM_SetBBReg(pDM_Odm,ODM_REG_PIN_CTRL_11N, BIT24|BIT25, 0 ); // ANTSEL as HW control
  6316. ODM_SetBBReg(pDM_Odm,ODM_REG_ANTSEL_PATH_11N, BIT13, 0); //select ANTESEL from path B
  6317. }
  6318. //Set OFDM HW RX Antenna Diversity
  6319. ODM_SetBBReg(pDM_Odm,ODM_REG_ANTDIV_PARA1_11N, 0x7FF, 0x0c0); //Pwdb threshold=8dB
  6320. ODM_SetBBReg(pDM_Odm,ODM_REG_ANTDIV_PARA1_11N, BIT11, 0); //Switch to another antenna by checking pwdb threshold
  6321. ODM_SetBBReg(pDM_Odm,ODM_REG_ANTDIV_PARA3_11N, BIT23, 1); // Decide final antenna by comparing 2 antennas' pwdb
  6322. //Set CCK HW RX Antenna Diversity
  6323. ODM_SetBBReg(pDM_Odm,ODM_REG_CCK_ANTDIV_PARA2_11N, BIT4, 0); //Antenna diversity decision period = 32 sample
  6324. ODM_SetBBReg(pDM_Odm,ODM_REG_CCK_ANTDIV_PARA2_11N, 0xf, 0xf); //Threshold for antenna diversity. Check another antenna power if input power < ANT_lim*4
  6325. ODM_SetBBReg(pDM_Odm,ODM_REG_CCK_ANTDIV_PARA3_11N, BIT13, 1); //polarity ana_A=1 and ana_B=0
  6326. ODM_SetBBReg(pDM_Odm,ODM_REG_CCK_ANTDIV_PARA4_11N, 0x1f, 0x8); //default antenna power = inpwr*(0.5 + r_ant_step/16)
  6327. //Enable HW Antenna Diversity
  6328. if(!bTxPathSel) //PATH-A
  6329. ODM_SetBBReg(pDM_Odm,ODM_REG_IGI_A_11N, BIT7,1); // Enable Hardware antenna switch
  6330. else
  6331. ODM_SetBBReg(pDM_Odm,ODM_REG_IGI_B_11N, BIT7,1); // Enable Hardware antenna switch
  6332. ODM_SetBBReg(pDM_Odm,ODM_REG_CCK_ANTDIV_PARA1_11N, BIT15, 1);//Enable antenna diversity
  6333. pDM_SWAT_Table->CurAntenna=0; //choose left antenna as default antenna
  6334. pDM_SWAT_Table->PreAntenna=0;
  6335. for(i=0; i<ASSOCIATE_ENTRY_NUM ; i++)
  6336. {
  6337. pDM_SWAT_Table->CCK_Ant1_Cnt[i] = 0;
  6338. pDM_SWAT_Table->CCK_Ant2_Cnt[i] = 0;
  6339. pDM_SWAT_Table->OFDM_Ant1_Cnt[i] = 0;
  6340. pDM_SWAT_Table->OFDM_Ant2_Cnt[i] = 0;
  6341. pDM_SWAT_Table->RSSI_Ant1_Sum[i] = 0;
  6342. pDM_SWAT_Table->RSSI_Ant2_Sum[i] = 0;
  6343. }
  6344. ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV,ODM_DBG_LOUD,("<==============odm_InitHybridAntDiv\n"));
  6345. }
  6346. VOID
  6347. odm_InitHybridAntDiv(
  6348. IN PDM_ODM_T pDM_Odm
  6349. )
  6350. {
  6351. if(!(pDM_Odm->SupportAbility & ODM_BB_ANT_DIV))
  6352. {
  6353. ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV,ODM_DBG_LOUD,("Return: Not Support HW AntDiv\n"));
  6354. return;
  6355. }
  6356. if(pDM_Odm->SupportICType & (ODM_RTL8192C | ODM_RTL8192D))
  6357. {
  6358. #if ((RTL8192C_SUPPORT == 1)||(RTL8192D_SUPPORT == 1))
  6359. odm_InitHybridAntDiv_88C_92D(pDM_Odm);
  6360. #endif
  6361. }
  6362. else if(pDM_Odm->SupportICType == ODM_RTL8188E)
  6363. {
  6364. #if (RTL8188E_SUPPORT == 1)
  6365. ODM_AntennaDiversityInit_88E(pDM_Odm);
  6366. #endif
  6367. }
  6368. else if(pDM_Odm->SupportICType == ODM_RTL8821)
  6369. {
  6370. #if (RTL8821A_SUPPORT == 1)
  6371. // ODM_AntennaDiversityInit_8821A(pDM_Odm);
  6372. #endif
  6373. }
  6374. else if(pDM_Odm->SupportICType == ODM_RTL8723B)
  6375. {
  6376. #if (RTL8723B_SUPPORT == 1)
  6377. ODM_AntennaDiversityInit_8723B(pDM_Odm);
  6378. #endif
  6379. }
  6380. }
  6381. BOOLEAN
  6382. odm_StaDefAntSel(
  6383. IN PDM_ODM_T pDM_Odm,
  6384. IN u4Byte OFDM_Ant1_Cnt,
  6385. IN u4Byte OFDM_Ant2_Cnt,
  6386. IN u4Byte CCK_Ant1_Cnt,
  6387. IN u4Byte CCK_Ant2_Cnt,
  6388. OUT u1Byte *pDefAnt
  6389. )
  6390. {
  6391. #if 1
  6392. ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV,ODM_DBG_LOUD,("odm_StaDefAntSelect==============>\n"));
  6393. ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV,ODM_DBG_LOUD,("OFDM_Ant1_Cnt:%d, OFDM_Ant2_Cnt:%d\n",OFDM_Ant1_Cnt,OFDM_Ant2_Cnt));
  6394. ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV,ODM_DBG_LOUD,("CCK_Ant1_Cnt:%d, CCK_Ant2_Cnt:%d\n",CCK_Ant1_Cnt,CCK_Ant2_Cnt));
  6395. if(((OFDM_Ant1_Cnt+OFDM_Ant2_Cnt)==0)&&((CCK_Ant1_Cnt + CCK_Ant2_Cnt) <10)){
  6396. ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV,ODM_DBG_LOUD,("odm_StaDefAntSelect Fail: No enough packet info!\n"));
  6397. return FALSE;
  6398. }
  6399. if(OFDM_Ant1_Cnt || OFDM_Ant2_Cnt ) {
  6400. //if RX OFDM packet number larger than 0
  6401. if(OFDM_Ant1_Cnt > OFDM_Ant2_Cnt)
  6402. (*pDefAnt)=1;
  6403. else
  6404. (*pDefAnt)=0;
  6405. }
  6406. // else if RX CCK packet number larger than 10
  6407. else if((CCK_Ant1_Cnt + CCK_Ant2_Cnt) >=10 )
  6408. {
  6409. if(CCK_Ant1_Cnt > (5*CCK_Ant2_Cnt))
  6410. (*pDefAnt)=1;
  6411. else if(CCK_Ant2_Cnt > (5*CCK_Ant1_Cnt))
  6412. (*pDefAnt)=0;
  6413. else if(CCK_Ant1_Cnt > CCK_Ant2_Cnt)
  6414. (*pDefAnt)=0;
  6415. else
  6416. (*pDefAnt)=1;
  6417. }
  6418. ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV,ODM_DBG_LOUD,("TxAnt = %s\n",((*pDefAnt)==1)?"Ant1":"Ant2"));
  6419. #endif
  6420. //u4Byte antsel = ODM_GetBBReg(pDM_Odm, 0xc88, bMaskByte0);
  6421. //(*pDefAnt)= (u1Byte) antsel;
  6422. ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV,ODM_DBG_LOUD,("<==============odm_StaDefAntSelect\n"));
  6423. return TRUE;
  6424. }
  6425. VOID
  6426. odm_SetRxIdleAnt(
  6427. IN PDM_ODM_T pDM_Odm,
  6428. IN u1Byte Ant,
  6429. IN BOOLEAN bDualPath
  6430. )
  6431. {
  6432. SWAT_T *pDM_SWAT_Table = &pDM_Odm->DM_SWAT_Table;
  6433. //ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV,ODM_DBG_LOUD,("odm_SetRxIdleAnt==============>\n"));
  6434. if(Ant != pDM_SWAT_Table->RxIdleAnt)
  6435. {
  6436. //for path-A
  6437. if(Ant==1)
  6438. ODM_SetBBReg(pDM_Odm,ODM_REG_RX_DEFUALT_A_11N, 0xFFFF, 0x65a9); //right-side antenna
  6439. else
  6440. ODM_SetBBReg(pDM_Odm,ODM_REG_RX_DEFUALT_A_11N, 0xFFFF, 0x569a); //left-side antenna
  6441. //for path-B
  6442. if(bDualPath){
  6443. if(Ant==0)
  6444. ODM_SetBBReg(pDM_Odm,ODM_REG_RX_DEFUALT_A_11N, 0xFFFF0000, 0x65a9); //right-side antenna
  6445. else
  6446. ODM_SetBBReg(pDM_Odm,ODM_REG_RX_DEFUALT_A_11N, 0xFFFF0000, 0x569a); //left-side antenna
  6447. }
  6448. }
  6449. pDM_SWAT_Table->RxIdleAnt = Ant;
  6450. ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD,("RxIdleAnt: %s Reg858=0x%x\n",(Ant==1)?"Ant1":"Ant2",(Ant==1)?0x65a9:0x569a));
  6451. //ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV,ODM_DBG_LOUD,("<==============odm_SetRxIdleAnt\n"));
  6452. }
  6453. VOID
  6454. ODM_AntselStatistics_88C(
  6455. IN PDM_ODM_T pDM_Odm,
  6456. IN u1Byte MacId,
  6457. IN u4Byte PWDBAll,
  6458. IN BOOLEAN isCCKrate
  6459. )
  6460. {
  6461. SWAT_T *pDM_SWAT_Table = &pDM_Odm->DM_SWAT_Table;
  6462. if(pDM_SWAT_Table->antsel == 1)
  6463. {
  6464. if(isCCKrate)
  6465. pDM_SWAT_Table->CCK_Ant1_Cnt[MacId]++;
  6466. else
  6467. {
  6468. pDM_SWAT_Table->OFDM_Ant1_Cnt[MacId]++;
  6469. pDM_SWAT_Table->RSSI_Ant1_Sum[MacId] += PWDBAll;
  6470. }
  6471. }
  6472. else
  6473. {
  6474. if(isCCKrate)
  6475. pDM_SWAT_Table->CCK_Ant2_Cnt[MacId]++;
  6476. else
  6477. {
  6478. pDM_SWAT_Table->OFDM_Ant2_Cnt[MacId]++;
  6479. pDM_SWAT_Table->RSSI_Ant2_Sum[MacId] += PWDBAll;
  6480. }
  6481. }
  6482. }
  6483. #if(DM_ODM_SUPPORT_TYPE==ODM_WIN)
  6484. VOID
  6485. ODM_SetTxAntByTxInfo_88C_92D(
  6486. IN PDM_ODM_T pDM_Odm,
  6487. IN pu1Byte pDesc,
  6488. IN u1Byte macId
  6489. )
  6490. {
  6491. SWAT_T *pDM_SWAT_Table = &pDM_Odm->DM_SWAT_Table;
  6492. u1Byte antsel;
  6493. if(!(pDM_Odm->SupportAbility&ODM_BB_ANT_DIV))
  6494. return;
  6495. if(pDM_SWAT_Table->RxIdleAnt == 1)
  6496. antsel=(pDM_SWAT_Table->TxAnt[macId] == 1)?0:1;
  6497. else
  6498. antsel=(pDM_SWAT_Table->TxAnt[macId] == 1)?1:0;
  6499. SET_TX_DESC_ANTSEL_A_92C(pDesc, antsel);
  6500. //SET_TX_DESC_ANTSEL_B_92C(pDesc, antsel);
  6501. //ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV,ODM_DBG_LOUD,("SET_TX_DESC_ANTSEL_A_92C=%d\n", pDM_SWAT_Table->TxAnt[macId]));
  6502. }
  6503. #elif(DM_ODM_SUPPORT_TYPE==ODM_CE)
  6504. VOID
  6505. ODM_SetTxAntByTxInfo_88C_92D(
  6506. IN PDM_ODM_T pDM_Odm
  6507. )
  6508. {
  6509. }
  6510. #elif(DM_ODM_SUPPORT_TYPE==ODM_AP)
  6511. VOID
  6512. ODM_SetTxAntByTxInfo_88C_92D(
  6513. IN PDM_ODM_T pDM_Odm
  6514. )
  6515. {
  6516. }
  6517. #endif
  6518. VOID
  6519. odm_HwAntDiv_92C_92D(
  6520. IN PDM_ODM_T pDM_Odm
  6521. )
  6522. {
  6523. SWAT_T *pDM_SWAT_Table = &pDM_Odm->DM_SWAT_Table;
  6524. u4Byte RSSI_Min=0xFF, RSSI, RSSI_Ant1, RSSI_Ant2;
  6525. u1Byte RxIdleAnt, i;
  6526. BOOLEAN bRet=FALSE;
  6527. PSTA_INFO_T pEntry;
  6528. #if (DM_ODM_SUPPORT_TYPE==ODM_AP)
  6529. struct rtl8192cd_priv *priv=pDM_Odm->priv;
  6530. //if test, return
  6531. if(priv->pshare->rf_ft_var.CurAntenna & 0x80)
  6532. return;
  6533. #endif
  6534. ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV,ODM_DBG_LOUD,("odm_HwAntDiv==============>\n"));
  6535. if(!(pDM_Odm->SupportAbility&ODM_BB_ANT_DIV)) //if don't support antenna diveristy
  6536. {
  6537. ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV,ODM_DBG_LOUD,("odm_HwAntDiv: Not supported!\n"));
  6538. return;
  6539. }
  6540. if((pDM_Odm->SupportICType != ODM_RTL8192C) && (pDM_Odm->SupportICType != ODM_RTL8192D))
  6541. {
  6542. ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV,ODM_DBG_LOUD,("Return: IC Type is not 92C or 92D\n"));
  6543. return;
  6544. }
  6545. #if (DM_ODM_SUPPORT_TYPE&(ODM_WIN|ODM_CE))
  6546. if(!pDM_Odm->bLinked)
  6547. {
  6548. ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV,ODM_DBG_LOUD,("Return: bLinked is FALSE\n"));
  6549. return;
  6550. }
  6551. #endif
  6552. for (i=0; i<ODM_ASSOCIATE_ENTRY_NUM; i++)
  6553. {
  6554. pEntry = pDM_Odm->pODM_StaInfo[i];
  6555. if(IS_STA_VALID(pEntry))
  6556. {
  6557. RSSI_Ant1 = (pDM_SWAT_Table->OFDM_Ant1_Cnt[i] == 0)?0:(pDM_SWAT_Table->RSSI_Ant1_Sum[i]/pDM_SWAT_Table->OFDM_Ant1_Cnt[i]);
  6558. RSSI_Ant2 = (pDM_SWAT_Table->OFDM_Ant2_Cnt[i] == 0)?0:(pDM_SWAT_Table->RSSI_Ant2_Sum[i]/pDM_SWAT_Table->OFDM_Ant2_Cnt[i]);
  6559. ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV,ODM_DBG_LOUD,("RSSI_Ant1=%d, RSSI_Ant2=%d\n", RSSI_Ant1, RSSI_Ant2));
  6560. if(RSSI_Ant1 ||RSSI_Ant2)
  6561. {
  6562. #if (DM_ODM_SUPPORT_TYPE==ODM_AP)
  6563. if(pDM_Odm->pODM_StaInfo[i]->expire_to)
  6564. #endif
  6565. {
  6566. RSSI = (RSSI_Ant1 < RSSI_Ant2) ? RSSI_Ant1 : RSSI_Ant2;
  6567. if((!RSSI) || ( RSSI < RSSI_Min) ) {
  6568. pDM_SWAT_Table->TargetSTA = i;
  6569. RSSI_Min = RSSI;
  6570. }
  6571. }
  6572. }
  6573. ///STA: found out default antenna
  6574. bRet=odm_StaDefAntSel(pDM_Odm,
  6575. pDM_SWAT_Table->OFDM_Ant1_Cnt[i],
  6576. pDM_SWAT_Table->OFDM_Ant2_Cnt[i],
  6577. pDM_SWAT_Table->CCK_Ant1_Cnt[i],
  6578. pDM_SWAT_Table->CCK_Ant2_Cnt[i],
  6579. &pDM_SWAT_Table->TxAnt[i]);
  6580. //if Tx antenna selection: successful
  6581. if(bRet){
  6582. pDM_SWAT_Table->RSSI_Ant1_Sum[i] = 0;
  6583. pDM_SWAT_Table->RSSI_Ant2_Sum[i] = 0;
  6584. pDM_SWAT_Table->OFDM_Ant1_Cnt[i] = 0;
  6585. pDM_SWAT_Table->OFDM_Ant2_Cnt[i] = 0;
  6586. pDM_SWAT_Table->CCK_Ant1_Cnt[i] = 0;
  6587. pDM_SWAT_Table->CCK_Ant2_Cnt[i] = 0;
  6588. }
  6589. }
  6590. }
  6591. //set RX Idle Ant
  6592. RxIdleAnt = pDM_SWAT_Table->TxAnt[pDM_SWAT_Table->TargetSTA];
  6593. odm_SetRxIdleAnt(pDM_Odm, RxIdleAnt, FALSE);
  6594. #if (DM_ODM_SUPPORT_TYPE==ODM_AP)
  6595. #ifdef TX_SHORTCUT
  6596. if (!priv->pmib->dot11OperationEntry.disable_txsc) {
  6597. plist = phead->next;
  6598. while(plist != phead) {
  6599. pstat = list_entry(plist, struct stat_info, asoc_list);
  6600. if(pstat->expire_to) {
  6601. for (i=0; i<TX_SC_ENTRY_NUM; i++) {
  6602. struct tx_desc *pdesc= &(pstat->tx_sc_ent[i].hwdesc1);
  6603. pdesc->Dword2 &= set_desc(~ (BIT(24)|BIT(25)));
  6604. if((pstat->CurAntenna^priv->pshare->rf_ft_var.CurAntenna)&1)
  6605. pdesc->Dword2 |= set_desc(BIT(24)|BIT(25));
  6606. pdesc= &(pstat->tx_sc_ent[i].hwdesc2);
  6607. pdesc->Dword2 &= set_desc(~ (BIT(24)|BIT(25)));
  6608. if((pstat->CurAntenna^priv->pshare->rf_ft_var.CurAntenna)&1)
  6609. pdesc->Dword2 |= set_desc(BIT(24)|BIT(25));
  6610. }
  6611. }
  6612. if (plist == plist->next)
  6613. break;
  6614. plist = plist->next;
  6615. };
  6616. }
  6617. #endif
  6618. #endif
  6619. ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD,("<==============odm_HwAntDiv\n"));
  6620. }
  6621. VOID
  6622. odm_HwAntDiv(
  6623. IN PDM_ODM_T pDM_Odm
  6624. )
  6625. {
  6626. PADAPTER pAdapter = pDM_Odm->Adapter;
  6627. //if(pAdapter->MgntInfo.AntennaTest)
  6628. // return;
  6629. if(!(pDM_Odm->SupportAbility & ODM_BB_ANT_DIV))
  6630. {
  6631. ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV,ODM_DBG_LOUD,("Return: Not Support HW AntDiv\n"));
  6632. return;
  6633. }
  6634. if(pDM_Odm->SupportICType & (ODM_RTL8192C | ODM_RTL8192D))
  6635. {
  6636. #if ((RTL8192C_SUPPORT == 1)||(RTL8192D_SUPPORT == 1))
  6637. odm_HwAntDiv_92C_92D(pDM_Odm);
  6638. #endif
  6639. }
  6640. else if(pDM_Odm->SupportICType == ODM_RTL8188E)
  6641. {
  6642. #if (RTL8188E_SUPPORT == 1)
  6643. ODM_AntennaDiversity_88E(pDM_Odm);
  6644. #endif
  6645. }
  6646. else if(pDM_Odm->SupportICType == ODM_RTL8821)
  6647. {
  6648. #if (RTL8821A_SUPPORT == 1)
  6649. ODM_AntennaDiversity_8821A(pDM_Odm);
  6650. #endif
  6651. }
  6652. else if(pDM_Odm->SupportICType == ODM_RTL8723B)
  6653. {
  6654. #if (RTL8723B_SUPPORT == 1)
  6655. ODM_AntennaDiversity_8723B(pDM_Odm);
  6656. #endif
  6657. }
  6658. }
  6659. #if(DM_ODM_SUPPORT_TYPE==ODM_AP)
  6660. #if 0
  6661. VOID
  6662. odm_HwAntDiv(
  6663. IN PDM_ODM_T pDM_Odm
  6664. )
  6665. {
  6666. struct rtl8192cd_priv *priv=pDM_Odm->priv;
  6667. struct stat_info *pstat, *pstat_min=NULL;
  6668. struct list_head *phead, *plist;
  6669. int rssi_min= 0xff, i;
  6670. u1Byte idleAnt=priv->pshare->rf_ft_var.CurAntenna;
  6671. u1Byte nextAnt;
  6672. BOOLEAN bRet=FALSE;
  6673. ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV,ODM_DBG_LOUD,("odm_HwAntDiv==============>\n"));
  6674. if((!priv->pshare->rf_ft_var.antHw_enable) ||(!(pDM_Odm->SupportAbility & ODM_BB_ANT_DIV)))
  6675. return;
  6676. //if test, return
  6677. if(priv->pshare->rf_ft_var.CurAntenna & 0x80)
  6678. return;
  6679. phead = &priv->asoc_list;
  6680. plist = phead->next;
  6681. ////=========================
  6682. //find mimum rssi sta
  6683. ////=========================
  6684. while(plist != phead) {
  6685. pstat = list_entry(plist, struct stat_info, asoc_list);
  6686. if((pstat->expire_to) && (pstat->AntRSSI[0] || pstat->AntRSSI[1])) {
  6687. int rssi = (pstat->AntRSSI[0] < pstat->AntRSSI[1]) ? pstat->AntRSSI[0] : pstat->AntRSSI[1];
  6688. if((!pstat_min) || ( rssi < rssi_min) ) {
  6689. pstat_min = pstat;
  6690. rssi_min = rssi;
  6691. }
  6692. }
  6693. ///STA: found out default antenna
  6694. bRet=odm_StaDefAntSel(pDM_Odm,
  6695. pstat->hwRxAntSel[1],
  6696. pstat->hwRxAntSel[0],
  6697. pstat->cckPktCount[1],
  6698. pstat->cckPktCount[0],
  6699. &nextAnt
  6700. );
  6701. //if default antenna selection: successful
  6702. if(bRet){
  6703. pstat->CurAntenna = nextAnt;
  6704. //update rssi
  6705. for(i=0; i<2; i++) {
  6706. if(pstat->cckPktCount[i]==0 && pstat->hwRxAntSel[i]==0)
  6707. pstat->AntRSSI[i] = 0;
  6708. }
  6709. if(pstat->AntRSSI[idleAnt]==0)
  6710. pstat->AntRSSI[idleAnt] = pstat->AntRSSI[idleAnt^1];
  6711. // reset variables
  6712. pstat->hwRxAntSel[1] = pstat->hwRxAntSel[0] =0;
  6713. pstat->cckPktCount[1]= pstat->cckPktCount[0] =0;
  6714. }
  6715. if (plist == plist->next)
  6716. break;
  6717. plist = plist->next;
  6718. };
  6719. ////=========================
  6720. //Choose RX Idle antenna according to minmum rssi
  6721. ////=========================
  6722. if(pstat_min) {
  6723. if(priv->pshare->rf_ft_var.CurAntenna!=pstat_min->CurAntenna)
  6724. odm_SetRxIdleAnt(pDM_Odm,pstat_min->CurAntenna,TRUE);
  6725. priv->pshare->rf_ft_var.CurAntenna = pstat_min->CurAntenna;
  6726. }
  6727. #ifdef TX_SHORTCUT
  6728. if (!priv->pmib->dot11OperationEntry.disable_txsc) {
  6729. plist = phead->next;
  6730. while(plist != phead) {
  6731. pstat = list_entry(plist, struct stat_info, asoc_list);
  6732. if(pstat->expire_to) {
  6733. for (i=0; i<TX_SC_ENTRY_NUM; i++) {
  6734. struct tx_desc *pdesc= &(pstat->tx_sc_ent[i].hwdesc1);
  6735. pdesc->Dword2 &= set_desc(~ (BIT(24)|BIT(25)));
  6736. if((pstat->CurAntenna^priv->pshare->rf_ft_var.CurAntenna)&1)
  6737. pdesc->Dword2 |= set_desc(BIT(24)|BIT(25));
  6738. pdesc= &(pstat->tx_sc_ent[i].hwdesc2);
  6739. pdesc->Dword2 &= set_desc(~ (BIT(24)|BIT(25)));
  6740. if((pstat->CurAntenna^priv->pshare->rf_ft_var.CurAntenna)&1)
  6741. pdesc->Dword2 |= set_desc(BIT(24)|BIT(25));
  6742. }
  6743. }
  6744. if (plist == plist->next)
  6745. break;
  6746. plist = plist->next;
  6747. };
  6748. }
  6749. #endif
  6750. ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD,"<==============odm_HwAntDiv\n");
  6751. }
  6752. #endif
  6753. u1Byte
  6754. ODM_Diversity_AntennaSelect(
  6755. IN PDM_ODM_T pDM_Odm,
  6756. IN u1Byte *data
  6757. )
  6758. {
  6759. struct rtl8192cd_priv *priv=pDM_Odm->priv;
  6760. int ant = _atoi(data, 16);
  6761. ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV,ODM_DBG_LOUD,("ODM_Diversity_AntennaSelect==============>\n"));
  6762. #ifdef PCIE_POWER_SAVING
  6763. PCIeWakeUp(priv, POWER_DOWN_T0);
  6764. #endif
  6765. if (ant==AUX_ANT || ant==MAIN_ANT)
  6766. {
  6767. if ( !priv->pshare->rf_ft_var.antSw_select) {
  6768. ODM_Write4Byte(pDM_Odm,0x870, ODM_Read4Byte(pDM_Odm,0x870) | BIT(8)| BIT(9) ); // ANTSEL A as SW control
  6769. ODM_Write1Byte(pDM_Odm,0xc50, ODM_Read1Byte(pDM_Odm,0xc50) & (~ BIT(7))); // rx OFDM SW control
  6770. PHY_SetBBReg(priv, 0x860, 0x300, ant);
  6771. } else {
  6772. ODM_Write4Byte(pDM_Odm,0x870, ODM_Read4Byte(pDM_Odm,0x870) | BIT(24)| BIT(25) ); // ANTSEL B as HW control
  6773. PHY_SetBBReg(priv, 0x864, 0x300, ant);
  6774. ODM_Write1Byte(pDM_Odm,0xc58, ODM_Read1Byte(pDM_Odm,0xc58) & (~ BIT(7))); // rx OFDM SW control
  6775. }
  6776. ODM_Write1Byte(pDM_Odm,0xa01, ODM_Read1Byte(pDM_Odm,0xa01) & (~ BIT(7))); // rx CCK SW control
  6777. ODM_Write4Byte(pDM_Odm,0x80c, ODM_Read4Byte(pDM_Odm,0x80c) & (~ BIT(21))); // select ant by tx desc
  6778. ODM_Write4Byte(pDM_Odm,0x858, 0x569a569a);
  6779. priv->pshare->rf_ft_var.antHw_enable = 0;
  6780. priv->pshare->rf_ft_var.CurAntenna = (ant%2);
  6781. #ifdef SW_ANT_SWITCH
  6782. priv->pshare->rf_ft_var.antSw_enable = 0;
  6783. priv->pshare->DM_SWAT_Table.CurAntenna = ant;
  6784. priv->pshare->RSSI_test =0;
  6785. #endif
  6786. }
  6787. else if(ant==0){
  6788. if ( !priv->pshare->rf_ft_var.antSw_select) {
  6789. ODM_Write4Byte(pDM_Odm,0x870, ODM_Read4Byte(pDM_Odm,0x870) & ~(BIT(8)| BIT(9)) );
  6790. ODM_Write1Byte(pDM_Odm,0xc50, ODM_Read1Byte(pDM_Odm,0xc50) | BIT(7)); // OFDM HW control
  6791. } else {
  6792. ODM_Write4Byte(pDM_Odm,0x870, ODM_Read4Byte(pDM_Odm,0x870) & ~(BIT(24)| BIT(25)) );
  6793. ODM_Write1Byte(pDM_Odm,0xc58, ODM_Read1Byte(pDM_Odm,0xc58) | BIT(7)); // OFDM HW control
  6794. }
  6795. ODM_Write1Byte(pDM_Odm,0xa01, ODM_Read1Byte(pDM_Odm,0xa01) | BIT(7)); // CCK HW control
  6796. ODM_Write4Byte(pDM_Odm,0x80c, ODM_Read4Byte(pDM_Odm,0x80c) | BIT(21) ); // by tx desc
  6797. priv->pshare->rf_ft_var.CurAntenna = 0;
  6798. ODM_Write4Byte(pDM_Odm,0x858, 0x569a569a);
  6799. priv->pshare->rf_ft_var.antHw_enable = 1;
  6800. #ifdef SW_ANT_SWITCH
  6801. priv->pshare->rf_ft_var.antSw_enable = 0;
  6802. priv->pshare->RSSI_test =0;
  6803. #endif
  6804. }
  6805. #ifdef SW_ANT_SWITCH
  6806. else if(ant==3) {
  6807. if(!priv->pshare->rf_ft_var.antSw_enable) {
  6808. dm_SW_AntennaSwitchInit(priv);
  6809. ODM_Write4Byte(pDM_Odm,0x858, 0x569a569a);
  6810. priv->pshare->lastTxOkCnt = priv->net_stats.tx_bytes;
  6811. priv->pshare->lastRxOkCnt = priv->net_stats.rx_bytes;
  6812. }
  6813. if ( !priv->pshare->rf_ft_var.antSw_select)
  6814. ODM_Write1Byte(pDM_Odm,0xc50, ODM_Read1Byte(pDM_Odm,0xc50) & (~ BIT(7))); // rx OFDM SW control
  6815. else
  6816. ODM_Write1Byte(pDM_Odm,0xc58, ODM_Read1Byte(pDM_Odm,0xc58) & (~ BIT(7))); // rx OFDM SW control
  6817. ODM_Write1Byte(pDM_Odm,0xa01, ODM_Read1Byte(pDM_Odm,0xa01) & (~ BIT(7))); // rx CCK SW control
  6818. ODM_Write4Byte(pDM_Odm,0x80c, ODM_Read4Byte(pDM_Odm,0x80c) & (~ BIT(21))); // select ant by tx desc
  6819. priv->pshare->rf_ft_var.antHw_enable = 0;
  6820. priv->pshare->rf_ft_var.antSw_enable = 1;
  6821. }
  6822. #endif
  6823. ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV,ODM_DBG_LOUD,("<==============ODM_Diversity_AntennaSelect\n"));
  6824. return 1;
  6825. }
  6826. #endif
  6827. #else //#if(defined(CONFIG_HW_ANTENNA_DIVERSITY))
  6828. VOID odm_InitHybridAntDiv( IN PDM_ODM_T pDM_Odm ){}
  6829. VOID odm_HwAntDiv( IN PDM_ODM_T pDM_Odm){}
  6830. #if(DM_ODM_SUPPORT_TYPE==ODM_WIN)
  6831. VOID ODM_SetTxAntByTxInfo_88C_92D(
  6832. IN PDM_ODM_T pDM_Odm,
  6833. IN pu1Byte pDesc,
  6834. IN u1Byte macId
  6835. ){}
  6836. #elif(DM_ODM_SUPPORT_TYPE==ODM_CE)
  6837. VOID ODM_SetTxAntByTxInfo_88C_92D( IN PDM_ODM_T pDM_Odm){ }
  6838. #elif(DM_ODM_SUPPORT_TYPE==ODM_AP)
  6839. VOID ODM_SetTxAntByTxInfo_88C_92D( IN PDM_ODM_T pDM_Odm){ }
  6840. #endif
  6841. #endif //#if(defined(CONFIG_HW_ANTENNA_DIVERSITY))
  6842. //============================================================
  6843. //EDCA Turbo
  6844. //============================================================
  6845. VOID
  6846. ODM_EdcaTurboInit(
  6847. IN PDM_ODM_T pDM_Odm)
  6848. {
  6849. #if ((DM_ODM_SUPPORT_TYPE == ODM_AP)||(DM_ODM_SUPPORT_TYPE==ODM_ADSL))
  6850. odm_EdcaParaInit(pDM_Odm);
  6851. #elif (DM_ODM_SUPPORT_TYPE==ODM_WIN)
  6852. PADAPTER Adapter = NULL;
  6853. HAL_DATA_TYPE *pHalData = NULL;
  6854. if(pDM_Odm->Adapter==NULL) {
  6855. ODM_RT_TRACE(pDM_Odm,ODM_COMP_EDCA_TURBO,ODM_DBG_LOUD,("EdcaTurboInit fail!!!\n"));
  6856. return;
  6857. }
  6858. Adapter=pDM_Odm->Adapter;
  6859. pHalData=GET_HAL_DATA(Adapter);
  6860. pDM_Odm->DM_EDCA_Table.bCurrentTurboEDCA = FALSE;
  6861. pDM_Odm->DM_EDCA_Table.bIsCurRDLState = FALSE;
  6862. pHalData->bIsAnyNonBEPkts = FALSE;
  6863. #elif(DM_ODM_SUPPORT_TYPE==ODM_CE)
  6864. PADAPTER Adapter = pDM_Odm->Adapter;
  6865. pDM_Odm->DM_EDCA_Table.bCurrentTurboEDCA = FALSE;
  6866. pDM_Odm->DM_EDCA_Table.bIsCurRDLState = FALSE;
  6867. Adapter->recvpriv.bIsAnyNonBEPkts =FALSE;
  6868. #endif
  6869. ODM_RT_TRACE(pDM_Odm,ODM_COMP_EDCA_TURBO,ODM_DBG_LOUD,("Orginial VO PARAM: 0x%x\n",ODM_Read4Byte(pDM_Odm,ODM_EDCA_VO_PARAM)));
  6870. ODM_RT_TRACE(pDM_Odm,ODM_COMP_EDCA_TURBO,ODM_DBG_LOUD,("Orginial VI PARAM: 0x%x\n",ODM_Read4Byte(pDM_Odm,ODM_EDCA_VI_PARAM)));
  6871. ODM_RT_TRACE(pDM_Odm,ODM_COMP_EDCA_TURBO,ODM_DBG_LOUD,("Orginial BE PARAM: 0x%x\n",ODM_Read4Byte(pDM_Odm,ODM_EDCA_BE_PARAM)));
  6872. ODM_RT_TRACE(pDM_Odm,ODM_COMP_EDCA_TURBO,ODM_DBG_LOUD,("Orginial BK PARAM: 0x%x\n",ODM_Read4Byte(pDM_Odm,ODM_EDCA_BK_PARAM)));
  6873. } // ODM_InitEdcaTurbo
  6874. VOID
  6875. odm_EdcaTurboCheck(
  6876. IN PDM_ODM_T pDM_Odm
  6877. )
  6878. {
  6879. //
  6880. // For AP/ADSL use prtl8192cd_priv
  6881. // For CE/NIC use PADAPTER
  6882. //
  6883. //
  6884. // 2011/09/29 MH In HW integration first stage, we provide 4 different handle to operate
  6885. // at the same time. In the stage2/3, we need to prive universal interface and merge all
  6886. // HW dynamic mechanism.
  6887. //
  6888. ODM_RT_TRACE(pDM_Odm,ODM_COMP_EDCA_TURBO,ODM_DBG_LOUD,("odm_EdcaTurboCheck========================>\n"));
  6889. if(!(pDM_Odm->SupportAbility& ODM_MAC_EDCA_TURBO ))
  6890. return;
  6891. switch (pDM_Odm->SupportPlatform)
  6892. {
  6893. case ODM_WIN:
  6894. #if(DM_ODM_SUPPORT_TYPE==ODM_WIN)
  6895. odm_EdcaTurboCheckMP(pDM_Odm);
  6896. #endif
  6897. break;
  6898. case ODM_CE:
  6899. #if(DM_ODM_SUPPORT_TYPE==ODM_CE)
  6900. odm_EdcaTurboCheckCE(pDM_Odm);
  6901. #endif
  6902. break;
  6903. case ODM_AP:
  6904. case ODM_ADSL:
  6905. #if ((DM_ODM_SUPPORT_TYPE == ODM_AP)||(DM_ODM_SUPPORT_TYPE==ODM_ADSL))
  6906. odm_IotEngine(pDM_Odm);
  6907. #endif
  6908. break;
  6909. }
  6910. ODM_RT_TRACE(pDM_Odm,ODM_COMP_EDCA_TURBO,ODM_DBG_LOUD,("<========================odm_EdcaTurboCheck\n"));
  6911. } // odm_CheckEdcaTurbo
  6912. #if(DM_ODM_SUPPORT_TYPE==ODM_CE)
  6913. VOID
  6914. odm_EdcaTurboCheckCE(
  6915. IN PDM_ODM_T pDM_Odm
  6916. )
  6917. {
  6918. #if(DM_ODM_SUPPORT_TYPE==ODM_CE)
  6919. PADAPTER Adapter = pDM_Odm->Adapter;
  6920. u32 EDCA_BE_UL = 0x5ea42b;//Parameter suggested by Scott //edca_setting_UL[pMgntInfo->IOTPeer];
  6921. u32 EDCA_BE_DL = 0x5ea42b;//Parameter suggested by Scott //edca_setting_DL[pMgntInfo->IOTPeer];
  6922. u32 ICType=pDM_Odm->SupportICType;
  6923. u32 IOTPeer=0;
  6924. u8 WirelessMode=0xFF; //invalid value
  6925. u32 trafficIndex;
  6926. u32 edca_param;
  6927. u64 cur_tx_bytes = 0;
  6928. u64 cur_rx_bytes = 0;
  6929. u8 bbtchange = _FALSE;
  6930. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  6931. struct xmit_priv *pxmitpriv = &(Adapter->xmitpriv);
  6932. struct recv_priv *precvpriv = &(Adapter->recvpriv);
  6933. struct registry_priv *pregpriv = &Adapter->registrypriv;
  6934. struct mlme_ext_priv *pmlmeext = &(Adapter->mlmeextpriv);
  6935. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  6936. if ((pregpriv->wifi_spec == 1) )//|| (pmlmeinfo->HT_enable == 0))
  6937. {
  6938. goto dm_CheckEdcaTurbo_EXIT;
  6939. }
  6940. if(pDM_Odm->pWirelessMode!=NULL)
  6941. WirelessMode=*(pDM_Odm->pWirelessMode);
  6942. IOTPeer = pmlmeinfo->assoc_AP_vendor;
  6943. if (IOTPeer >= HT_IOT_PEER_MAX)
  6944. {
  6945. goto dm_CheckEdcaTurbo_EXIT;
  6946. }
  6947. // Check if the status needs to be changed.
  6948. if((bbtchange) || (!precvpriv->bIsAnyNonBEPkts) )
  6949. {
  6950. cur_tx_bytes = pxmitpriv->tx_bytes - pxmitpriv->last_tx_bytes;
  6951. cur_rx_bytes = precvpriv->rx_bytes - precvpriv->last_rx_bytes;
  6952. //traffic, TX or RX
  6953. if((IOTPeer == HT_IOT_PEER_RALINK)||(IOTPeer == HT_IOT_PEER_ATHEROS))
  6954. {
  6955. if (cur_tx_bytes > (cur_rx_bytes << 2))
  6956. { // Uplink TP is present.
  6957. trafficIndex = UP_LINK;
  6958. }
  6959. else
  6960. { // Balance TP is present.
  6961. trafficIndex = DOWN_LINK;
  6962. }
  6963. }
  6964. else
  6965. {
  6966. if (cur_rx_bytes > (cur_tx_bytes << 2))
  6967. { // Downlink TP is present.
  6968. trafficIndex = DOWN_LINK;
  6969. }
  6970. else
  6971. { // Balance TP is present.
  6972. trafficIndex = UP_LINK;
  6973. }
  6974. }
  6975. if ((pDM_Odm->DM_EDCA_Table.prv_traffic_idx != trafficIndex) || (!pDM_Odm->DM_EDCA_Table.bCurrentTurboEDCA))
  6976. {
  6977. if(ICType==ODM_RTL8192D)
  6978. {
  6979. // Single PHY
  6980. if(pDM_Odm->RFType==ODM_2T2R)
  6981. {
  6982. EDCA_BE_UL = 0x60a42b; //0x5ea42b;
  6983. EDCA_BE_DL = 0x60a42b; //0x5ea42b;
  6984. }
  6985. else
  6986. {
  6987. EDCA_BE_UL = 0x6ea42b;
  6988. EDCA_BE_DL = 0x6ea42b;
  6989. }
  6990. }
  6991. else
  6992. {
  6993. if(pDM_Odm->SupportInterface==ODM_ITRF_PCIE) {
  6994. if((ICType==ODM_RTL8192C)&&(pDM_Odm->RFType==ODM_2T2R)) {
  6995. EDCA_BE_UL = 0x60a42b;
  6996. EDCA_BE_DL = 0x60a42b;
  6997. }
  6998. else
  6999. {
  7000. EDCA_BE_UL = 0x6ea42b;
  7001. EDCA_BE_DL = 0x6ea42b;
  7002. }
  7003. }
  7004. }
  7005. //92D txop can't be set to 0x3e for cisco1250
  7006. if((ICType!=ODM_RTL8192D) && (IOTPeer== HT_IOT_PEER_CISCO) &&(WirelessMode==ODM_WM_N24G))
  7007. {
  7008. EDCA_BE_DL = edca_setting_DL[IOTPeer];
  7009. EDCA_BE_UL = edca_setting_UL[IOTPeer];
  7010. }
  7011. //merge from 92s_92c_merge temp brunch v2445 20120215
  7012. else if((IOTPeer == HT_IOT_PEER_CISCO) &&((WirelessMode==ODM_WM_G)||(WirelessMode==(ODM_WM_B|ODM_WM_G))||(WirelessMode==ODM_WM_A)||(WirelessMode==ODM_WM_B)))
  7013. {
  7014. EDCA_BE_DL = edca_setting_DL_GMode[IOTPeer];
  7015. }
  7016. else if((IOTPeer== HT_IOT_PEER_AIRGO )&& ((WirelessMode==ODM_WM_G)||(WirelessMode==ODM_WM_A)))
  7017. {
  7018. EDCA_BE_DL = 0xa630;
  7019. }
  7020. else if(IOTPeer == HT_IOT_PEER_MARVELL)
  7021. {
  7022. EDCA_BE_DL = edca_setting_DL[IOTPeer];
  7023. EDCA_BE_UL = edca_setting_UL[IOTPeer];
  7024. }
  7025. else if(IOTPeer == HT_IOT_PEER_ATHEROS)
  7026. {
  7027. // Set DL EDCA for Atheros peer to 0x3ea42b. Suggested by SD3 Wilson for ASUS TP issue.
  7028. EDCA_BE_DL = edca_setting_DL[IOTPeer];
  7029. }
  7030. if((ICType==ODM_RTL8812)||(ICType==ODM_RTL8192E)) //add 8812AU/8812AE
  7031. {
  7032. EDCA_BE_UL = 0x5ea42b;
  7033. EDCA_BE_DL = 0x5ea42b;
  7034. ODM_RT_TRACE(pDM_Odm,ODM_COMP_EDCA_TURBO,ODM_DBG_LOUD,("8812A: EDCA_BE_UL=0x%x EDCA_BE_DL =0x%x",EDCA_BE_UL,EDCA_BE_DL));
  7035. }
  7036. if (trafficIndex == DOWN_LINK)
  7037. edca_param = EDCA_BE_DL;
  7038. else
  7039. edca_param = EDCA_BE_UL;
  7040. rtw_write32(Adapter, REG_EDCA_BE_PARAM, edca_param);
  7041. pDM_Odm->DM_EDCA_Table.prv_traffic_idx = trafficIndex;
  7042. }
  7043. pDM_Odm->DM_EDCA_Table.bCurrentTurboEDCA = _TRUE;
  7044. }
  7045. else
  7046. {
  7047. //
  7048. // Turn Off EDCA turbo here.
  7049. // Restore original EDCA according to the declaration of AP.
  7050. //
  7051. if(pDM_Odm->DM_EDCA_Table.bCurrentTurboEDCA)
  7052. {
  7053. rtw_write32(Adapter, REG_EDCA_BE_PARAM, pHalData->AcParam_BE);
  7054. pDM_Odm->DM_EDCA_Table.bCurrentTurboEDCA = _FALSE;
  7055. }
  7056. }
  7057. dm_CheckEdcaTurbo_EXIT:
  7058. // Set variables for next time.
  7059. precvpriv->bIsAnyNonBEPkts = _FALSE;
  7060. pxmitpriv->last_tx_bytes = pxmitpriv->tx_bytes;
  7061. precvpriv->last_rx_bytes = precvpriv->rx_bytes;
  7062. #endif
  7063. }
  7064. #elif(DM_ODM_SUPPORT_TYPE==ODM_WIN)
  7065. VOID
  7066. odm_EdcaTurboCheckMP(
  7067. IN PDM_ODM_T pDM_Odm
  7068. )
  7069. {
  7070. PADAPTER Adapter = pDM_Odm->Adapter;
  7071. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  7072. #if(DM_ODM_SUPPORT_TYPE==ODM_WIN)
  7073. PADAPTER pDefaultAdapter = GetDefaultAdapter(Adapter);
  7074. PADAPTER pExtAdapter = GetFirstExtAdapter(Adapter);//NULL;
  7075. PMGNT_INFO pMgntInfo = &Adapter->MgntInfo;
  7076. PSTA_QOS pStaQos = Adapter->MgntInfo.pStaQos;
  7077. //[Win7 Count Tx/Rx statistic for Extension Port] odm_CheckEdcaTurbo's Adapter is always Default. 2009.08.20, by Bohn
  7078. u8Byte Ext_curTxOkCnt = 0;
  7079. u8Byte Ext_curRxOkCnt = 0;
  7080. //For future Win7 Enable Default Port to modify AMPDU size dynamically, 2009.08.20, Bohn.
  7081. u1Byte TwoPortStatus = (u1Byte)TWO_PORT_STATUS__WITHOUT_ANY_ASSOCIATE;
  7082. #elif (DM_ODM_SUPPORT_TYPE==ODM_CE)
  7083. struct dm_priv *pdmpriv = &pHalData->dmpriv;
  7084. struct xmit_priv *pxmitpriv = &(Adapter->xmitpriv);
  7085. struct recv_priv *precvpriv = &(Adapter->recvpriv);
  7086. struct registry_priv *pregpriv = &Adapter->registrypriv;
  7087. struct mlme_ext_priv *pmlmeext = &(Adapter->mlmeextpriv);
  7088. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  7089. #ifdef CONFIG_BT_COEXIST
  7090. struct btcoexist_priv *pbtpriv = &(pHalData->bt_coexist);
  7091. #endif
  7092. u1Byte bbtchange =FALSE;
  7093. #endif
  7094. // Keep past Tx/Rx packet count for RT-to-RT EDCA turbo.
  7095. u8Byte curTxOkCnt = 0;
  7096. u8Byte curRxOkCnt = 0;
  7097. u4Byte EDCA_BE_UL = 0x5ea42b;//Parameter suggested by Scott //edca_setting_UL[pMgntInfo->IOTPeer];
  7098. u4Byte EDCA_BE_DL = 0x5ea42b;//Parameter suggested by Scott //edca_setting_DL[pMgntInfo->IOTPeer];
  7099. u4Byte EDCA_BE = 0x5ea42b;
  7100. u4Byte IOTPeer=0;
  7101. BOOLEAN *pbIsCurRDLState=NULL;
  7102. BOOLEAN bLastIsCurRDLState=FALSE;
  7103. BOOLEAN bBiasOnRx=FALSE;
  7104. BOOLEAN bEdcaTurboOn=FALSE;
  7105. u1Byte TxRate = 0xFF;
  7106. u8Byte value64;
  7107. ODM_RT_TRACE(pDM_Odm,ODM_COMP_EDCA_TURBO,ODM_DBG_LOUD,("odm_EdcaTurboCheckMP========================>"));
  7108. ODM_RT_TRACE(pDM_Odm,ODM_COMP_EDCA_TURBO,ODM_DBG_LOUD,("Orginial BE PARAM: 0x%x\n",ODM_Read4Byte(pDM_Odm,ODM_EDCA_BE_PARAM)));
  7109. ////===============================
  7110. ////list paramter for different platform
  7111. ////===============================
  7112. bLastIsCurRDLState=pDM_Odm->DM_EDCA_Table.bIsCurRDLState;
  7113. pbIsCurRDLState=&(pDM_Odm->DM_EDCA_Table.bIsCurRDLState);
  7114. #if (DM_ODM_SUPPORT_TYPE==ODM_WIN)
  7115. //2012/09/14 MH Add
  7116. if (pMgntInfo->NumNonBePkt > pMgntInfo->RegEdcaThresh &&
  7117. !Adapter->MgntInfo.bWiFiConfg)
  7118. {
  7119. pHalData->bIsAnyNonBEPkts = TRUE;
  7120. }
  7121. pMgntInfo->NumNonBePkt = 0;
  7122. // Caculate TX/RX TP:
  7123. //curTxOkCnt = Adapter->TxStats.NumTxBytesUnicast - pMgntInfo->lastTxOkCnt;
  7124. //curRxOkCnt = Adapter->RxStats.NumRxBytesUnicast - pMgntInfo->lastRxOkCnt;
  7125. curTxOkCnt = Adapter->TxStats.NumTxBytesUnicast - pDM_Odm->lastTxOkCnt;
  7126. curRxOkCnt = Adapter->RxStats.NumRxBytesUnicast - pDM_Odm->lastRxOkCnt;
  7127. pDM_Odm->lastTxOkCnt = Adapter->TxStats.NumTxBytesUnicast;
  7128. pDM_Odm->lastRxOkCnt = Adapter->RxStats.NumRxBytesUnicast;
  7129. if(pExtAdapter == NULL)
  7130. pExtAdapter = pDefaultAdapter;
  7131. Ext_curTxOkCnt = pExtAdapter->TxStats.NumTxBytesUnicast - pMgntInfo->Ext_lastTxOkCnt;
  7132. Ext_curRxOkCnt = pExtAdapter->RxStats.NumRxBytesUnicast - pMgntInfo->Ext_lastRxOkCnt;
  7133. GetTwoPortSharedResource(Adapter,TWO_PORT_SHARED_OBJECT__STATUS,NULL,&TwoPortStatus);
  7134. //For future Win7 Enable Default Port to modify AMPDU size dynamically, 2009.08.20, Bohn.
  7135. if(TwoPortStatus == TWO_PORT_STATUS__EXTENSION_ONLY)
  7136. {
  7137. curTxOkCnt = Ext_curTxOkCnt ;
  7138. curRxOkCnt = Ext_curRxOkCnt ;
  7139. }
  7140. //
  7141. IOTPeer=pMgntInfo->IOTPeer;
  7142. bBiasOnRx=(pMgntInfo->IOTAction & HT_IOT_ACT_EDCA_BIAS_ON_RX)?TRUE:FALSE;
  7143. bEdcaTurboOn=((!pHalData->bIsAnyNonBEPkts) && (!pMgntInfo->bDisableFrameBursting))?TRUE:FALSE;
  7144. ODM_RT_TRACE(pDM_Odm,ODM_COMP_EDCA_TURBO,ODM_DBG_LOUD,("bIsAnyNonBEPkts : 0x%lx bDisableFrameBursting : 0x%lx \n",pHalData->bIsAnyNonBEPkts,pMgntInfo->bDisableFrameBursting));
  7145. #elif(DM_ODM_SUPPORT_TYPE==ODM_CE)
  7146. // Caculate TX/RX TP:
  7147. curTxOkCnt = pxmitpriv->tx_bytes - pxmitpriv->last_tx_bytes;
  7148. curRxOkCnt = precvpriv->rx_bytes - precvpriv->last_rx_bytes;
  7149. #ifdef CONFIG_BT_COEXIST
  7150. if(pbtpriv->BT_Coexist)
  7151. {
  7152. if( (pbtpriv->BT_EDCA[UP_LINK]!=0) || (pbtpriv->BT_EDCA[DOWN_LINK]!=0))
  7153. bbtchange = TRUE;
  7154. }
  7155. #endif
  7156. IOTPeer=pmlmeinfo->assoc_AP_vendor;
  7157. bBiasOnRx=((IOTPeer == HT_IOT_PEER_RALINK)||(IOTPeer == HT_IOT_PEER_ATHEROS))?TRUE:FALSE;
  7158. bEdcaTurboOn=(bbtchange || (!precvpriv->bIsAnyNonBEPkts))?TRUE:FALSE;
  7159. ODM_RT_TRACE(pDM_Odm,ODM_COMP_EDCA_TURBO,ODM_DBG_LOUD,("bbtchange : 0x%lx bIsAnyNonBEPkts : 0x%lx \n",bbtchange,precvpriv->bIsAnyNonBEPkts));
  7160. #endif
  7161. ////===============================
  7162. ////check if edca turbo is disabled
  7163. ////===============================
  7164. if(odm_IsEdcaTurboDisable(pDM_Odm))
  7165. goto dm_CheckEdcaTurbo_EXIT;
  7166. ////===============================
  7167. ////remove iot case out
  7168. ////===============================
  7169. ODM_EdcaParaSelByIot(pDM_Odm, &EDCA_BE_UL, &EDCA_BE_DL);
  7170. ////===============================
  7171. ////Check if the status needs to be changed.
  7172. ////===============================
  7173. if(bEdcaTurboOn)
  7174. {
  7175. ODM_RT_TRACE(pDM_Odm,ODM_COMP_EDCA_TURBO,ODM_DBG_LOUD,("bEdcaTurboOn : 0x%x bBiasOnRx : 0x%x\n",bEdcaTurboOn,bBiasOnRx));
  7176. ODM_RT_TRACE(pDM_Odm,ODM_COMP_EDCA_TURBO,ODM_DBG_LOUD,("curTxOkCnt : 0x%lx \n",curTxOkCnt));
  7177. ODM_RT_TRACE(pDM_Odm,ODM_COMP_EDCA_TURBO,ODM_DBG_LOUD,("curRxOkCnt : 0x%lx \n",curRxOkCnt));
  7178. if(bBiasOnRx)
  7179. odm_EdcaChooseTrafficIdx(pDM_Odm,curTxOkCnt, curRxOkCnt, TRUE, pbIsCurRDLState);
  7180. else
  7181. odm_EdcaChooseTrafficIdx(pDM_Odm,curTxOkCnt, curRxOkCnt, FALSE, pbIsCurRDLState);
  7182. //modify by Guo.Mingzhi 2011-12-29
  7183. EDCA_BE=((*pbIsCurRDLState)==TRUE)?EDCA_BE_DL:EDCA_BE_UL;
  7184. if(IS_HARDWARE_TYPE_8811AU(Adapter))
  7185. {
  7186. if(pMgntInfo->RegTxDutyEnable)
  7187. {
  7188. //2013.01.23 LukeLee: debug for 8811AU thermal issue (reduce Tx duty cycle)
  7189. if(!pMgntInfo->ForcedDataRate) //auto rate
  7190. {
  7191. if(pDM_Odm->TxRate != 0xFF)
  7192. TxRate = HwRateToMRate8812(pDM_Odm->TxRate);
  7193. }
  7194. else //force rate
  7195. {
  7196. TxRate = (u1Byte) pMgntInfo->ForcedDataRate;
  7197. }
  7198. value64 = (curRxOkCnt<<2);
  7199. if(curTxOkCnt < value64) //Downlink
  7200. ODM_Write4Byte(pDM_Odm,ODM_EDCA_BE_PARAM,EDCA_BE);
  7201. else //Uplink
  7202. {
  7203. //DbgPrint("pDM_Odm->RFCalibrateInfo.ThermalValue = 0x%X\n", pDM_Odm->RFCalibrateInfo.ThermalValue);
  7204. //if(pDM_Odm->RFCalibrateInfo.ThermalValue < pHalData->EEPROMThermalMeter)
  7205. if(pDM_Odm->RFCalibrateInfo.ThermalValue < 0x2c)
  7206. ODM_Write4Byte(pDM_Odm,ODM_EDCA_BE_PARAM,EDCA_BE);
  7207. else
  7208. {
  7209. switch (TxRate)
  7210. {
  7211. case MGN_VHT1SS_MCS6:
  7212. case MGN_VHT1SS_MCS5:
  7213. ODM_Write4Byte(pDM_Odm,ODM_EDCA_BE_PARAM,0x1ea42b);
  7214. break;
  7215. case MGN_VHT1SS_MCS4:
  7216. ODM_Write4Byte(pDM_Odm,ODM_EDCA_BE_PARAM,0xa42b);
  7217. break;
  7218. case MGN_VHT1SS_MCS3:
  7219. ODM_Write4Byte(pDM_Odm,ODM_EDCA_BE_PARAM,0xa47f);
  7220. break;
  7221. case MGN_VHT1SS_MCS2:
  7222. ODM_Write4Byte(pDM_Odm,ODM_EDCA_BE_PARAM,0xa57f);
  7223. break;
  7224. case MGN_VHT1SS_MCS1:
  7225. ODM_Write4Byte(pDM_Odm,ODM_EDCA_BE_PARAM,0xa77f);
  7226. break;
  7227. case MGN_VHT1SS_MCS0:
  7228. ODM_Write4Byte(pDM_Odm,ODM_EDCA_BE_PARAM,0xa87f);
  7229. break;
  7230. default:
  7231. ODM_Write4Byte(pDM_Odm,ODM_EDCA_BE_PARAM,EDCA_BE);
  7232. break;
  7233. }
  7234. }
  7235. }
  7236. }
  7237. else
  7238. {
  7239. ODM_Write4Byte(pDM_Odm,ODM_EDCA_BE_PARAM,EDCA_BE);
  7240. }
  7241. }
  7242. else
  7243. ODM_Write4Byte(pDM_Odm,ODM_EDCA_BE_PARAM,EDCA_BE);
  7244. ODM_RT_TRACE(pDM_Odm,ODM_COMP_EDCA_TURBO,ODM_DBG_LOUD,("EDCA Turbo on: EDCA_BE:0x%lx\n",EDCA_BE));
  7245. // if(((*pbIsCurRDLState)!=bLastIsCurRDLState)||(!pDM_Odm->DM_EDCA_Table.bCurrentTurboEDCA))
  7246. // {
  7247. // EDCA_BE=((*pbIsCurRDLState)==TRUE)?EDCA_BE_DL:EDCA_BE_UL;
  7248. // ODM_Write4Byte(pDM_Odm,ODM_EDCA_BE_PARAM,EDCA_BE);
  7249. // }
  7250. pDM_Odm->DM_EDCA_Table.bCurrentTurboEDCA = TRUE;
  7251. ODM_RT_TRACE(pDM_Odm,ODM_COMP_EDCA_TURBO,ODM_DBG_LOUD,("EDCA_BE_DL : 0x%lx EDCA_BE_UL : 0x%lx EDCA_BE : 0x%lx \n",EDCA_BE_DL,EDCA_BE_UL,EDCA_BE));
  7252. }
  7253. else
  7254. {
  7255. // Turn Off EDCA turbo here.
  7256. // Restore original EDCA according to the declaration of AP.
  7257. if(pDM_Odm->DM_EDCA_Table.bCurrentTurboEDCA)
  7258. {
  7259. #if (DM_ODM_SUPPORT_TYPE==ODM_WIN)
  7260. Adapter->HalFunc.SetHwRegHandler(Adapter, HW_VAR_AC_PARAM, GET_WMM_PARAM_ELE_SINGLE_AC_PARAM(pStaQos->WMMParamEle, AC0_BE) );
  7261. #elif(DM_ODM_SUPPORT_TYPE==ODM_CE)
  7262. ODM_Write4Byte(pDM_Odm, ODM_EDCA_BE_PARAM, pHalData->AcParam_BE);
  7263. #endif
  7264. pDM_Odm->DM_EDCA_Table.bCurrentTurboEDCA = FALSE;
  7265. ODM_RT_TRACE(pDM_Odm,ODM_COMP_EDCA_TURBO,ODM_DBG_LOUD,("Restore EDCA BE: 0x%lx \n",pDM_Odm->WMMEDCA_BE));
  7266. }
  7267. }
  7268. ////===============================
  7269. ////Set variables for next time.
  7270. ////===============================
  7271. dm_CheckEdcaTurbo_EXIT:
  7272. #if (DM_ODM_SUPPORT_TYPE==ODM_WIN)
  7273. pHalData->bIsAnyNonBEPkts = FALSE;
  7274. pMgntInfo->lastTxOkCnt = Adapter->TxStats.NumTxBytesUnicast;
  7275. pMgntInfo->lastRxOkCnt = Adapter->RxStats.NumRxBytesUnicast;
  7276. pMgntInfo->Ext_lastTxOkCnt = pExtAdapter->TxStats.NumTxBytesUnicast;
  7277. pMgntInfo->Ext_lastRxOkCnt = pExtAdapter->RxStats.NumRxBytesUnicast;
  7278. #elif (DM_ODM_SUPPORT_TYPE==ODM_CE)
  7279. precvpriv->bIsAnyNonBEPkts = FALSE;
  7280. pxmitpriv->last_tx_bytes = pxmitpriv->tx_bytes;
  7281. precvpriv->last_rx_bytes = precvpriv->rx_bytes;
  7282. #endif
  7283. }
  7284. //check if edca turbo is disabled
  7285. BOOLEAN
  7286. odm_IsEdcaTurboDisable(
  7287. IN PDM_ODM_T pDM_Odm
  7288. )
  7289. {
  7290. PADAPTER Adapter = pDM_Odm->Adapter;
  7291. #if(DM_ODM_SUPPORT_TYPE==ODM_WIN)
  7292. PMGNT_INFO pMgntInfo = &Adapter->MgntInfo;
  7293. u4Byte IOTPeer=pMgntInfo->IOTPeer;
  7294. #elif (DM_ODM_SUPPORT_TYPE==ODM_CE)
  7295. struct registry_priv *pregpriv = &Adapter->registrypriv;
  7296. struct mlme_ext_priv *pmlmeext = &(Adapter->mlmeextpriv);
  7297. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  7298. u4Byte IOTPeer=pmlmeinfo->assoc_AP_vendor;
  7299. u1Byte WirelessMode=0xFF; //invalid value
  7300. if(pDM_Odm->pWirelessMode!=NULL)
  7301. WirelessMode=*(pDM_Odm->pWirelessMode);
  7302. #endif
  7303. if(pDM_Odm->bBtDisableEdcaTurbo)
  7304. {
  7305. ODM_RT_TRACE(pDM_Odm, ODM_COMP_EDCA_TURBO,ODM_DBG_LOUD, ("EdcaTurboDisable for BT!!\n"));
  7306. return TRUE;
  7307. }
  7308. if((!(pDM_Odm->SupportAbility& ODM_MAC_EDCA_TURBO ))||
  7309. (pDM_Odm->bWIFITest)||
  7310. (IOTPeer>= HT_IOT_PEER_MAX))
  7311. {
  7312. ODM_RT_TRACE(pDM_Odm, ODM_COMP_EDCA_TURBO,ODM_DBG_LOUD, ("EdcaTurboDisable\n"));
  7313. return TRUE;
  7314. }
  7315. #if (DM_ODM_SUPPORT_TYPE ==ODM_WIN)
  7316. // 1. We do not turn on EDCA turbo mode for some AP that has IOT issue
  7317. // 2. User may disable EDCA Turbo mode with OID settings.
  7318. if(pMgntInfo->IOTAction & HT_IOT_ACT_DISABLE_EDCA_TURBO){
  7319. ODM_RT_TRACE(pDM_Odm, ODM_COMP_EDCA_TURBO,ODM_DBG_LOUD, ("IOTAction:EdcaTurboDisable\n"));
  7320. return TRUE;
  7321. }
  7322. #elif(DM_ODM_SUPPORT_TYPE==ODM_CE)
  7323. //suggested by Jr.Luke: open TXOP for B/G/BG/A mode 2012-0215
  7324. if((WirelessMode==ODM_WM_B)||(WirelessMode==(ODM_WM_B|ODM_WM_G)||(WirelessMode==ODM_WM_G)||(WirelessMode=ODM_WM_A))
  7325. ODM_Write4Byte(pDM_Odm, ODM_EDCA_BE_PARAM, ODM_Read4Byte(pDM_Odm, ODM_EDCA_BE_PARAM)|0x5E0000);
  7326. if(pDM_Odm->SupportICType==ODM_RTL8192D) {
  7327. if ((pregpriv->wifi_spec == 1) || (pmlmeext->cur_wireless_mode == WIRELESS_11B)) {
  7328. ODM_RT_TRACE(pDM_Odm, ODM_COMP_EDCA_TURBO,ODM_DBG_LOUD, ("92D:EdcaTurboDisable\n"));
  7329. return TRUE;
  7330. }
  7331. }
  7332. else
  7333. {
  7334. if((pregpriv->wifi_spec == 1) || (pmlmeinfo->HT_enable == 0)){
  7335. ODM_RT_TRACE(pDM_Odm, ODM_COMP_EDCA_TURBO,ODM_DBG_LOUD, ("Others:EdcaTurboDisable\n"));
  7336. return TRUE;
  7337. }
  7338. }
  7339. #endif
  7340. return FALSE;
  7341. }
  7342. //add iot case here: for MP/CE
  7343. VOID
  7344. ODM_EdcaParaSelByIot(
  7345. IN PDM_ODM_T pDM_Odm,
  7346. OUT u4Byte *EDCA_BE_UL,
  7347. OUT u4Byte *EDCA_BE_DL
  7348. )
  7349. {
  7350. PADAPTER Adapter = pDM_Odm->Adapter;
  7351. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  7352. u4Byte IOTPeer=0;
  7353. u4Byte ICType=pDM_Odm->SupportICType;
  7354. u1Byte WirelessMode=0xFF; //invalid value
  7355. u4Byte RFType=pDM_Odm->RFType;
  7356. u4Byte IOTPeerSubType=0;
  7357. #if(DM_ODM_SUPPORT_TYPE==ODM_WIN)
  7358. PMGNT_INFO pMgntInfo = &Adapter->MgntInfo;
  7359. u1Byte TwoPortStatus = (u1Byte)TWO_PORT_STATUS__WITHOUT_ANY_ASSOCIATE;
  7360. #elif(DM_ODM_SUPPORT_TYPE==ODM_CE)
  7361. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  7362. #ifdef CONFIG_BT_COEXIST
  7363. struct btcoexist_priv *pbtpriv = &(pHalData->bt_coexist);
  7364. #endif
  7365. u1Byte bbtchange =FALSE;
  7366. #endif
  7367. if(pDM_Odm->pWirelessMode!=NULL)
  7368. WirelessMode=*(pDM_Odm->pWirelessMode);
  7369. ///////////////////////////////////////////////////////////
  7370. ////list paramter for different platform
  7371. #if (DM_ODM_SUPPORT_TYPE==ODM_WIN)
  7372. IOTPeer=pMgntInfo->IOTPeer;
  7373. IOTPeerSubType=pMgntInfo->IOTPeerSubtype;
  7374. GetTwoPortSharedResource(Adapter,TWO_PORT_SHARED_OBJECT__STATUS,NULL,&TwoPortStatus);
  7375. #elif(DM_ODM_SUPPORT_TYPE==ODM_CE)
  7376. IOTPeer=pmlmeinfo->assoc_AP_vendor;
  7377. #ifdef CONFIG_BT_COEXIST
  7378. if(pbtpriv->BT_Coexist)
  7379. {
  7380. if( (pbtpriv->BT_EDCA[UP_LINK]!=0) || (pbtpriv->BT_EDCA[DOWN_LINK]!=0))
  7381. bbtchange = TRUE;
  7382. }
  7383. #endif
  7384. #endif
  7385. if(ICType==ODM_RTL8192D)
  7386. {
  7387. // Single PHY
  7388. if(pDM_Odm->RFType==ODM_2T2R)
  7389. {
  7390. (*EDCA_BE_UL) = 0x60a42b; //0x5ea42b;
  7391. (*EDCA_BE_DL) = 0x60a42b; //0x5ea42b;
  7392. }
  7393. else
  7394. {
  7395. (*EDCA_BE_UL) = 0x6ea42b;
  7396. (*EDCA_BE_DL) = 0x6ea42b;
  7397. }
  7398. }
  7399. ////============================
  7400. /// IOT case for MP
  7401. ////============================
  7402. #if (DM_ODM_SUPPORT_TYPE==ODM_WIN)
  7403. else
  7404. {
  7405. if(pDM_Odm->SupportInterface==ODM_ITRF_PCIE){
  7406. if((ICType==ODM_RTL8192C)&&(pDM_Odm->RFType==ODM_2T2R)) {
  7407. (*EDCA_BE_UL) = 0x60a42b;
  7408. (*EDCA_BE_DL) = 0x60a42b;
  7409. }
  7410. else
  7411. {
  7412. (*EDCA_BE_UL) = 0x6ea42b;
  7413. (*EDCA_BE_DL) = 0x6ea42b;
  7414. }
  7415. }
  7416. }
  7417. if(TwoPortStatus == TWO_PORT_STATUS__EXTENSION_ONLY)
  7418. {
  7419. (*EDCA_BE_UL) = 0x5ea42b;//Parameter suggested by Scott //edca_setting_UL[ExtAdapter->MgntInfo.IOTPeer];
  7420. (*EDCA_BE_DL) = 0x5ea42b;//Parameter suggested by Scott //edca_setting_DL[ExtAdapter->MgntInfo.IOTPeer];
  7421. }
  7422. #if (INTEL_PROXIMITY_SUPPORT == 1)
  7423. if(pMgntInfo->IntelClassModeInfo.bEnableCA == TRUE)
  7424. {
  7425. (*EDCA_BE_UL) = (*EDCA_BE_DL) = 0xa44f;
  7426. }
  7427. else
  7428. #endif
  7429. {
  7430. if((!pMgntInfo->bDisableFrameBursting) &&
  7431. (pMgntInfo->IOTAction & (HT_IOT_ACT_FORCED_ENABLE_BE_TXOP|HT_IOT_ACT_AMSDU_ENABLE)))
  7432. {// To check whether we shall force turn on TXOP configuration.
  7433. if(!((*EDCA_BE_UL) & 0xffff0000))
  7434. (*EDCA_BE_UL) |= 0x005e0000; // Force TxOP limit to 0x005e for UL.
  7435. if(!((*EDCA_BE_DL) & 0xffff0000))
  7436. (*EDCA_BE_DL) |= 0x005e0000; // Force TxOP limit to 0x005e for DL.
  7437. }
  7438. //92D txop can't be set to 0x3e for cisco1250
  7439. if((ICType!=ODM_RTL8192D) && (IOTPeer== HT_IOT_PEER_CISCO) &&(WirelessMode==ODM_WM_N24G))
  7440. {
  7441. (*EDCA_BE_DL) = edca_setting_DL[IOTPeer];
  7442. (*EDCA_BE_UL) = edca_setting_UL[IOTPeer];
  7443. }
  7444. //merge from 92s_92c_merge temp brunch v2445 20120215
  7445. else if((IOTPeer == HT_IOT_PEER_CISCO) &&((WirelessMode==ODM_WM_G)||(WirelessMode==(ODM_WM_B|ODM_WM_G))||(WirelessMode==ODM_WM_A)||(WirelessMode==ODM_WM_B)))
  7446. {
  7447. (*EDCA_BE_DL) = edca_setting_DL_GMode[IOTPeer];
  7448. }
  7449. else if((IOTPeer== HT_IOT_PEER_AIRGO )&& ((WirelessMode==ODM_WM_G)||(WirelessMode==ODM_WM_A)))
  7450. {
  7451. (*EDCA_BE_DL) = 0xa630;
  7452. }
  7453. else if(IOTPeer == HT_IOT_PEER_MARVELL)
  7454. {
  7455. (*EDCA_BE_DL) = edca_setting_DL[IOTPeer];
  7456. (*EDCA_BE_UL) = edca_setting_UL[IOTPeer];
  7457. }
  7458. else if(IOTPeer == HT_IOT_PEER_ATHEROS)
  7459. {
  7460. // Set DL EDCA for Atheros peer to 0x3ea42b. Suggested by SD3 Wilson for ASUS TP issue.
  7461. (*EDCA_BE_DL) = edca_setting_DL[IOTPeer];
  7462. if(ICType == ODM_RTL8821)
  7463. (*EDCA_BE_DL) = 0x5ea630;
  7464. }
  7465. }
  7466. if((ICType == ODM_RTL8192D)&&(IOTPeerSubType == HT_IOT_PEER_LINKSYS_E4200_V1)&&((WirelessMode==ODM_WM_N5G)))
  7467. {
  7468. (*EDCA_BE_DL) = 0x432b;
  7469. (*EDCA_BE_UL) = 0x432b;
  7470. }
  7471. if((ICType==ODM_RTL8812)||(ICType==ODM_RTL8192E)) //add 8812AU/8812AE
  7472. {
  7473. (*EDCA_BE_UL) = 0x5ea42b;
  7474. (*EDCA_BE_DL) = 0x5ea42b;
  7475. ODM_RT_TRACE(pDM_Odm,ODM_COMP_EDCA_TURBO,ODM_DBG_LOUD,("8812A: EDCA_BE_UL=0x%lx EDCA_BE_DL =0x%lx",(*EDCA_BE_UL),(*EDCA_BE_DL)));
  7476. }
  7477. // Revised for Atheros DIR-655 IOT issue to improve down link TP, added by Roger, 2013.03.22.
  7478. if((ICType == ODM_RTL8723A) && (IOTPeerSubType== HT_IOT_PEER_ATHEROS_DIR655) &&
  7479. (pMgntInfo->dot11CurrentChannelNumber == 6))
  7480. {
  7481. (*EDCA_BE_DL) = 0xa92b;
  7482. }
  7483. ////============================
  7484. /// IOT case for CE
  7485. ////============================
  7486. #elif (DM_ODM_SUPPORT_TYPE==ODM_CE)
  7487. if(RFType==ODM_RTL8192D)
  7488. {
  7489. if((IOTPeer == HT_IOT_PEER_CISCO) &&(WirelessMode==ODM_WM_N24G))
  7490. {
  7491. (*EDCA_BE_UL) = EDCAParam[IOTPeer][UP_LINK];
  7492. (*EDCA_BE_DL)=EDCAParam[IOTPeer][DOWN_LINK];
  7493. }
  7494. else if((IOTPeer == HT_IOT_PEER_AIRGO) &&
  7495. ((WirelessMode==ODM_WM_B)||(WirelessMode==(ODM_WM_B|ODM_WM_G))))
  7496. (*EDCA_BE_DL)=0x00a630;
  7497. else if((IOTPeer== HT_IOT_PEER_ATHEROS) &&
  7498. (WirelessMode&ODM_WM_N5G) &&
  7499. (Adapter->securitypriv.dot11PrivacyAlgrthm == _AES_ ))
  7500. (*EDCA_BE_DL)=0xa42b;
  7501. }
  7502. //92C IOT case:
  7503. else
  7504. {
  7505. #ifdef CONFIG_BT_COEXIST
  7506. if(bbtchange)
  7507. {
  7508. (*EDCA_BE_UL) = pbtpriv->BT_EDCA[UP_LINK];
  7509. (*EDCA_BE_DL) = pbtpriv->BT_EDCA[DOWN_LINK];
  7510. }
  7511. else
  7512. #endif
  7513. {
  7514. if((IOTPeer == HT_IOT_PEER_CISCO) &&(WirelessMode==ODM_WM_N24G))
  7515. {
  7516. (*EDCA_BE_UL) = EDCAParam[IOTPeer][UP_LINK];
  7517. (*EDCA_BE_DL)=EDCAParam[IOTPeer][DOWN_LINK];
  7518. }
  7519. else
  7520. {
  7521. (*EDCA_BE_UL)=EDCAParam[HT_IOT_PEER_UNKNOWN][UP_LINK];
  7522. (*EDCA_BE_DL)=EDCAParam[HT_IOT_PEER_UNKNOWN][DOWN_LINK];
  7523. }
  7524. }
  7525. if(pDM_Odm->SupportInterface==ODM_ITRF_PCIE){
  7526. if((ICType==ODM_RTL8192C)&&(pDM_Odm->RFType==ODM_2T2R))
  7527. {
  7528. (*EDCA_BE_UL) = 0x60a42b;
  7529. (*EDCA_BE_DL) = 0x60a42b;
  7530. }
  7531. else
  7532. {
  7533. (*EDCA_BE_UL) = 0x6ea42b;
  7534. (*EDCA_BE_DL) = 0x6ea42b;
  7535. }
  7536. }
  7537. }
  7538. #endif
  7539. ODM_RT_TRACE(pDM_Odm,ODM_COMP_EDCA_TURBO,ODM_DBG_LOUD,("Special: EDCA_BE_UL=0x%lx EDCA_BE_DL =0x%lx",(*EDCA_BE_UL),(*EDCA_BE_DL)));
  7540. }
  7541. VOID
  7542. odm_EdcaChooseTrafficIdx(
  7543. IN PDM_ODM_T pDM_Odm,
  7544. IN u8Byte cur_tx_bytes,
  7545. IN u8Byte cur_rx_bytes,
  7546. IN BOOLEAN bBiasOnRx,
  7547. OUT BOOLEAN *pbIsCurRDLState
  7548. )
  7549. {
  7550. if(bBiasOnRx)
  7551. {
  7552. if(cur_tx_bytes>(cur_rx_bytes*4))
  7553. {
  7554. *pbIsCurRDLState=FALSE;
  7555. ODM_RT_TRACE(pDM_Odm,ODM_COMP_EDCA_TURBO,ODM_DBG_LOUD,("Uplink Traffic\n "));
  7556. }
  7557. else
  7558. {
  7559. *pbIsCurRDLState=TRUE;
  7560. ODM_RT_TRACE(pDM_Odm,ODM_COMP_EDCA_TURBO,ODM_DBG_LOUD,("Balance Traffic\n"));
  7561. }
  7562. }
  7563. else
  7564. {
  7565. if(cur_rx_bytes>(cur_tx_bytes*4))
  7566. {
  7567. *pbIsCurRDLState=TRUE;
  7568. ODM_RT_TRACE(pDM_Odm,ODM_COMP_EDCA_TURBO,ODM_DBG_LOUD,("Downlink Traffic\n"));
  7569. }
  7570. else
  7571. {
  7572. *pbIsCurRDLState=FALSE;
  7573. ODM_RT_TRACE(pDM_Odm,ODM_COMP_EDCA_TURBO,ODM_DBG_LOUD,("Balance Traffic\n"));
  7574. }
  7575. }
  7576. return ;
  7577. }
  7578. #endif
  7579. #if((DM_ODM_SUPPORT_TYPE==ODM_AP)||(DM_ODM_SUPPORT_TYPE==ODM_ADSL))
  7580. void odm_EdcaParaInit(
  7581. IN PDM_ODM_T pDM_Odm
  7582. )
  7583. {
  7584. prtl8192cd_priv priv = pDM_Odm->priv;
  7585. int mode=priv->pmib->dot11BssType.net_work_type;
  7586. static unsigned int slot_time, VO_TXOP, VI_TXOP, sifs_time;
  7587. struct ParaRecord EDCA[4];
  7588. memset(EDCA, 0, 4*sizeof(struct ParaRecord));
  7589. sifs_time = 10;
  7590. slot_time = 20;
  7591. if (mode & (ODM_WM_N24G|ODM_WM_N5G))
  7592. sifs_time = 16;
  7593. if (mode & (ODM_WM_N24G|ODM_WM_N5G| ODM_WM_G|ODM_WM_A))
  7594. slot_time = 9;
  7595. #if((defined(RTL_MANUAL_EDCA))&&(DM_ODM_SUPPORT_TYPE==ODM_AP))
  7596. if( priv->pmib->dot11QosEntry.ManualEDCA ) {
  7597. if( OPMODE & WIFI_AP_STATE )
  7598. memcpy(EDCA, priv->pmib->dot11QosEntry.AP_manualEDCA, 4*sizeof(struct ParaRecord));
  7599. else
  7600. memcpy(EDCA, priv->pmib->dot11QosEntry.STA_manualEDCA, 4*sizeof(struct ParaRecord));
  7601. #ifdef WIFI_WMM
  7602. if (QOS_ENABLE)
  7603. ODM_Write4Byte(pDM_Odm, ODM_EDCA_VI_PARAM, (EDCA[VI].TXOPlimit<< 16) | (EDCA[VI].ECWmax<< 12) | (EDCA[VI].ECWmin<< 8) | (sifs_time + EDCA[VI].AIFSN* slot_time));
  7604. else
  7605. #endif
  7606. ODM_Write4Byte(pDM_Odm, ODM_EDCA_VI_PARAM, (EDCA[BE].TXOPlimit<< 16) | (EDCA[BE].ECWmax<< 12) | (EDCA[BE].ECWmin<< 8) | (sifs_time + EDCA[VI].AIFSN* slot_time));
  7607. }else
  7608. #endif //RTL_MANUAL_EDCA
  7609. {
  7610. if(OPMODE & WIFI_AP_STATE)
  7611. {
  7612. memcpy(EDCA, rtl_ap_EDCA, 2*sizeof(struct ParaRecord));
  7613. if(mode & (ODM_WM_A|ODM_WM_G|ODM_WM_N24G|ODM_WM_N5G))
  7614. memcpy(&EDCA[VI], &rtl_ap_EDCA[VI_AG], 2*sizeof(struct ParaRecord));
  7615. else
  7616. memcpy(&EDCA[VI], &rtl_ap_EDCA[VI], 2*sizeof(struct ParaRecord));
  7617. }
  7618. else
  7619. {
  7620. memcpy(EDCA, rtl_sta_EDCA, 2*sizeof(struct ParaRecord));
  7621. if(mode & (ODM_WM_A|ODM_WM_G|ODM_WM_N24G|ODM_WM_N5G))
  7622. memcpy(&EDCA[VI], &rtl_sta_EDCA[VI_AG], 2*sizeof(struct ParaRecord));
  7623. else
  7624. memcpy(&EDCA[VI], &rtl_sta_EDCA[VI], 2*sizeof(struct ParaRecord));
  7625. }
  7626. #ifdef WIFI_WMM
  7627. if (QOS_ENABLE)
  7628. ODM_Write4Byte(pDM_Odm, ODM_EDCA_VI_PARAM, (EDCA[VI].TXOPlimit<< 16) | (EDCA[VI].ECWmax<< 12) | (EDCA[VI].ECWmin<< 8) | (sifs_time + EDCA[VI].AIFSN* slot_time));
  7629. else
  7630. #endif
  7631. #if (DM_ODM_SUPPORT_TYPE==ODM_AP)
  7632. ODM_Write4Byte(pDM_Odm, ODM_EDCA_VI_PARAM, (EDCA[BK].ECWmax<< 12) | (EDCA[BK].ECWmin<< 8) | (sifs_time + EDCA[VI].AIFSN* slot_time));
  7633. #elif(DM_ODM_SUPPORT_TYPE==ODM_ADSL)
  7634. ODM_Write4Byte(pDM_Odm, ODM_EDCA_VI_PARAM, (EDCA[BK].ECWmax<< 12) | (EDCA[BK].ECWmin<< 8) | (sifs_time + 2* slot_time));
  7635. #endif
  7636. }
  7637. ODM_Write4Byte(pDM_Odm, ODM_EDCA_VO_PARAM, (EDCA[VO].TXOPlimit<< 16) | (EDCA[VO].ECWmax<< 12) | (EDCA[VO].ECWmin<< 8) | (sifs_time + EDCA[VO].AIFSN* slot_time));
  7638. ODM_Write4Byte(pDM_Odm, ODM_EDCA_BE_PARAM, (EDCA[BE].TXOPlimit<< 16) | (EDCA[BE].ECWmax<< 12) | (EDCA[BE].ECWmin<< 8) | (sifs_time + EDCA[BE].AIFSN* slot_time));
  7639. ODM_Write4Byte(pDM_Odm, ODM_EDCA_BK_PARAM, (EDCA[BK].TXOPlimit<< 16) | (EDCA[BK].ECWmax<< 12) | (EDCA[BK].ECWmin<< 8) | (sifs_time + EDCA[BK].AIFSN* slot_time));
  7640. // ODM_Write1Byte(pDM_Odm,ACMHWCTRL, 0x00);
  7641. priv->pshare->iot_mode_enable = 0;
  7642. #if(DM_ODM_SUPPORT_TYPE==ODM_AP)
  7643. if (priv->pshare->rf_ft_var.wifi_beq_iot)
  7644. priv->pshare->iot_mode_VI_exist = 0;
  7645. #ifdef WMM_VIBE_PRI
  7646. priv->pshare->iot_mode_BE_exist = 0;
  7647. #endif
  7648. #ifdef LOW_TP_TXOP
  7649. priv->pshare->BE_cwmax_enhance = 0;
  7650. #endif
  7651. #elif (DM_ODM_SUPPORT_TYPE==ODM_ADSL)
  7652. priv->pshare->iot_mode_BE_exist = 0;
  7653. #endif
  7654. priv->pshare->iot_mode_VO_exist = 0;
  7655. }
  7656. BOOLEAN
  7657. ODM_ChooseIotMainSTA(
  7658. IN PDM_ODM_T pDM_Odm,
  7659. IN PSTA_INFO_T pstat
  7660. )
  7661. {
  7662. prtl8192cd_priv priv = pDM_Odm->priv;
  7663. BOOLEAN bhighTP_found_pstat=FALSE;
  7664. if ((GET_ROOT(priv)->up_time % 2) == 0) {
  7665. unsigned int tx_2s_avg = 0;
  7666. unsigned int rx_2s_avg = 0;
  7667. int i=0, aggReady=0;
  7668. unsigned long total_sum = (priv->pshare->current_tx_bytes+priv->pshare->current_rx_bytes);
  7669. pstat->current_tx_bytes += pstat->tx_byte_cnt;
  7670. pstat->current_rx_bytes += pstat->rx_byte_cnt;
  7671. if (total_sum != 0) {
  7672. if (total_sum <= 100) {
  7673. tx_2s_avg = (unsigned int)((pstat->current_tx_bytes*100) / total_sum);
  7674. rx_2s_avg = (unsigned int)((pstat->current_rx_bytes*100) / total_sum);
  7675. } else {
  7676. tx_2s_avg = (unsigned int)(pstat->current_tx_bytes / (total_sum / 100));
  7677. rx_2s_avg = (unsigned int)(pstat->current_rx_bytes / (total_sum / 100));
  7678. }
  7679. }
  7680. #if(DM_ODM_SUPPORT_TYPE==ODM_ADSL)
  7681. if (pstat->ht_cap_len) {
  7682. if ((tx_2s_avg + rx_2s_avg) >=25 /*50*/) {
  7683. priv->pshare->highTP_found_pstat = pstat;
  7684. bhighTP_found_pstat=TRUE;
  7685. }
  7686. }
  7687. #elif(DM_ODM_SUPPORT_TYPE==ODM_AP)
  7688. for(i=0; i<8; i++)
  7689. aggReady += (pstat->ADDBA_ready[i]);
  7690. if (pstat->ht_cap_len && aggReady)
  7691. {
  7692. if ((tx_2s_avg + rx_2s_avg >= 25)) {
  7693. priv->pshare->highTP_found_pstat = pstat;
  7694. }
  7695. #ifdef CLIENT_MODE
  7696. if (OPMODE & WIFI_STATION_STATE) {
  7697. #if (DM_ODM_SUPPORT_TYPE &ODM_AP) && defined(USE_OUT_SRC)
  7698. if ((pstat->IOTPeer==HT_IOT_PEER_RALINK) && ((tx_2s_avg + rx_2s_avg) >= 45))
  7699. #else
  7700. if(pstat->is_ralink_sta && ((tx_2s_avg + rx_2s_avg) >= 45))
  7701. #endif
  7702. priv->pshare->highTP_found_pstat = pstat;
  7703. }
  7704. #endif
  7705. }
  7706. #endif
  7707. } else {
  7708. pstat->current_tx_bytes = pstat->tx_byte_cnt;
  7709. pstat->current_rx_bytes = pstat->rx_byte_cnt;
  7710. }
  7711. return bhighTP_found_pstat;
  7712. }
  7713. #ifdef WIFI_WMM
  7714. VOID
  7715. ODM_IotEdcaSwitch(
  7716. IN PDM_ODM_T pDM_Odm,
  7717. IN unsigned char enable
  7718. )
  7719. {
  7720. prtl8192cd_priv priv = pDM_Odm->priv;
  7721. int mode=priv->pmib->dot11BssType.net_work_type;
  7722. unsigned int slot_time = 20, sifs_time = 10, BE_TXOP = 47, VI_TXOP = 94;
  7723. unsigned int vi_cw_max = 4, vi_cw_min = 3, vi_aifs;
  7724. #if (DM_ODM_SUPPORT_TYPE==ODM_AP)
  7725. if (!(!priv->pmib->dot11OperationEntry.wifi_specific ||
  7726. ((OPMODE & WIFI_AP_STATE) && (priv->pmib->dot11OperationEntry.wifi_specific == 2))
  7727. #ifdef CLIENT_MODE
  7728. || ((OPMODE & WIFI_STATION_STATE) && (priv->pmib->dot11OperationEntry.wifi_specific == 2))
  7729. #endif
  7730. ))
  7731. return;
  7732. #endif
  7733. if ((mode & (ODM_WM_N24G|ODM_WM_N5G)) && (priv->pshare->ht_sta_num
  7734. #ifdef WDS
  7735. || ((OPMODE & WIFI_AP_STATE) && priv->pmib->dot11WdsInfo.wdsEnabled && priv->pmib->dot11WdsInfo.wdsNum)
  7736. #endif
  7737. ))
  7738. sifs_time = 16;
  7739. if (mode & (ODM_WM_N24G|ODM_WM_N5G|ODM_WM_G|ODM_WM_A)) {
  7740. slot_time = 9;
  7741. }
  7742. else
  7743. {
  7744. BE_TXOP = 94;
  7745. VI_TXOP = 188;
  7746. }
  7747. #if (DM_ODM_SUPPORT_TYPE==ODM_ADSL)
  7748. if (priv->pshare->iot_mode_VO_exist) {
  7749. // to separate AC_VI and AC_BE to avoid using the same EDCA settings
  7750. if (priv->pshare->iot_mode_BE_exist) {
  7751. vi_cw_max = 5;
  7752. vi_cw_min = 3;
  7753. } else {
  7754. vi_cw_max = 6;
  7755. vi_cw_min = 4;
  7756. }
  7757. }
  7758. vi_aifs = (sifs_time + ((OPMODE & WIFI_AP_STATE)?1:2) * slot_time);
  7759. ODM_Write4Byte(pDM_Odm, ODM_EDCA_VI_PARAM, ((VI_TXOP*(1-priv->pshare->iot_mode_VO_exist)) << 16)| (vi_cw_max << 12) | (vi_cw_min << 8) | vi_aifs);
  7760. #elif (DM_ODM_SUPPORT_TYPE==ODM_AP)
  7761. if ((OPMODE & WIFI_AP_STATE) && priv->pmib->dot11OperationEntry.wifi_specific) {
  7762. if (priv->pshare->iot_mode_VO_exist) {
  7763. #ifdef WMM_VIBE_PRI
  7764. if (priv->pshare->iot_mode_BE_exist)
  7765. {
  7766. vi_cw_max = 5;
  7767. vi_cw_min = 3;
  7768. vi_aifs = (sifs_time + ((OPMODE & WIFI_AP_STATE)?1:2) * slot_time);
  7769. }
  7770. else
  7771. #endif
  7772. {
  7773. vi_cw_max = 6;
  7774. vi_cw_min = 4;
  7775. vi_aifs = 0x2b;
  7776. }
  7777. }
  7778. else {
  7779. vi_aifs = (sifs_time + ((OPMODE & WIFI_AP_STATE)?1:2) * slot_time);
  7780. }
  7781. ODM_Write4Byte(pDM_Odm, ODM_EDCA_VI_PARAM, ((VI_TXOP*(1-priv->pshare->iot_mode_VO_exist)) << 16)
  7782. | (vi_cw_max << 12) | (vi_cw_min << 8) | vi_aifs);
  7783. }
  7784. #endif
  7785. #if (DM_ODM_SUPPORT_TYPE==ODM_AP)
  7786. if (priv->pshare->rf_ft_var.wifi_beq_iot && priv->pshare->iot_mode_VI_exist)
  7787. ODM_Write4Byte(pDM_Odm, ODM_EDCA_BE_PARAM, (10 << 12) | (4 << 8) | 0x4f);
  7788. else if(!enable)
  7789. #elif(DM_ODM_SUPPORT_TYPE==ODM_ADSL)
  7790. if(!enable) //if iot is disable ,maintain original BEQ PARAM
  7791. #endif
  7792. ODM_Write4Byte(pDM_Odm, ODM_EDCA_BE_PARAM, (((OPMODE & WIFI_AP_STATE)?6:10) << 12) | (4 << 8)
  7793. | (sifs_time + 3 * slot_time));
  7794. else
  7795. {
  7796. int txop_enlarge;
  7797. int txop;
  7798. unsigned int cw_max;
  7799. unsigned int txop_close;
  7800. #if((DM_ODM_SUPPORT_TYPE==ODM_AP)&&(defined LOW_TP_TXOP))
  7801. cw_max = ((priv->pshare->BE_cwmax_enhance) ? 10 : 6);
  7802. txop_close = ((priv->pshare->rf_ft_var.low_tp_txop && priv->pshare->rf_ft_var.low_tp_txop_close) ? 1 : 0);
  7803. if(priv->pshare->txop_enlarge == 0xe) //if intel case
  7804. txop = (txop_close ? 0 : (BE_TXOP*2));
  7805. else //if other case
  7806. txop = (txop_close ? 0: (BE_TXOP*priv->pshare->txop_enlarge));
  7807. #else
  7808. cw_max=6;
  7809. if((priv->pshare->txop_enlarge==0xe)||(priv->pshare->txop_enlarge==0xd))
  7810. txop=BE_TXOP*2;
  7811. else
  7812. txop=BE_TXOP*priv->pshare->txop_enlarge;
  7813. #endif
  7814. if (priv->pshare->ht_sta_num
  7815. #ifdef WDS
  7816. || ((OPMODE & WIFI_AP_STATE) && (mode & (ODM_WM_N24G|ODM_WM_N5G)) &&
  7817. priv->pmib->dot11WdsInfo.wdsEnabled && priv->pmib->dot11WdsInfo.wdsNum)
  7818. #endif
  7819. )
  7820. {
  7821. if (priv->pshare->txop_enlarge == 0xe) {
  7822. // is intel client, use a different edca value
  7823. ODM_Write4Byte(pDM_Odm, ODM_EDCA_BE_PARAM, (txop<< 16) | (cw_max<< 12) | (4 << 8) | 0x1f);
  7824. priv->pshare->txop_enlarge = 2;
  7825. }
  7826. #if(DM_ODM_SUPPORT_TYPE==ODM_AP)
  7827. #ifndef LOW_TP_TXOP
  7828. else if (priv->pshare->txop_enlarge == 0xd) {
  7829. // is intel ralink, use a different edca value
  7830. ODM_Write4Byte(pDM_Odm, ODM_EDCA_BE_PARAM, (txop << 16) | (4 << 12) | (3 << 8) | 0x19);
  7831. priv->pshare->txop_enlarge = 2;
  7832. }
  7833. #endif
  7834. #endif
  7835. else
  7836. {
  7837. if (pDM_Odm->RFType==ODM_2T2R)
  7838. ODM_Write4Byte(pDM_Odm, ODM_EDCA_BE_PARAM, (txop << 16) |
  7839. (cw_max << 12) | (4 << 8) | (sifs_time + 3 * slot_time));
  7840. else
  7841. #if(DM_ODM_SUPPORT_TYPE==ODM_AP)&&(defined LOW_TP_TXOP)
  7842. ODM_Write4Byte(pDM_Odm, ODM_EDCA_BE_PARAM, (txop << 16) |
  7843. (((priv->pshare->BE_cwmax_enhance) ? 10 : 5) << 12) | (3 << 8) | (sifs_time + 2 * slot_time));
  7844. #else
  7845. ODM_Write4Byte(pDM_Odm, ODM_EDCA_BE_PARAM, (txop << 16) |
  7846. (5 << 12) | (3 << 8) | (sifs_time + 2 * slot_time));
  7847. #endif
  7848. }
  7849. }
  7850. else
  7851. {
  7852. #if((DM_ODM_SUPPORT_TYPE==ODM_AP)&&(defined LOW_TP_TXOP))
  7853. ODM_Write4Byte(pDM_Odm, ODM_EDCA_BE_PARAM, (BE_TXOP << 16) | (cw_max << 12) | (4 << 8) | (sifs_time + 3 * slot_time));
  7854. #else
  7855. #if defined(CONFIG_RTL_8196D) || defined(CONFIG_RTL_8196E) || (defined(CONFIG_RTL_8197D) && !defined(CONFIG_PORT0_EXT_GIGA))
  7856. ODM_Write4Byte(pDM_Odm, ODM_EDCA_BE_PARAM, (BE_TXOP*2 << 16) | (cw_max << 12) | (5 << 8) | (sifs_time + 3 * slot_time));
  7857. #else
  7858. ODM_Write4Byte(pDM_Odm, ODM_EDCA_BE_PARAM, (BE_TXOP*2 << 16) | (cw_max << 12) | (4 << 8) | (sifs_time + 3 * slot_time));
  7859. #endif
  7860. #endif
  7861. }
  7862. }
  7863. }
  7864. #endif
  7865. VOID
  7866. odm_IotEngine(
  7867. IN PDM_ODM_T pDM_Odm
  7868. )
  7869. {
  7870. struct rtl8192cd_priv *priv=pDM_Odm->priv;
  7871. PSTA_INFO_T pstat = NULL;
  7872. u4Byte i;
  7873. #ifdef WIFI_WMM
  7874. unsigned int switch_turbo = 0;
  7875. #endif
  7876. ////////////////////////////////////////////////////////
  7877. // if EDCA Turbo function is not supported or Manual EDCA Setting
  7878. // then return
  7879. ////////////////////////////////////////////////////////
  7880. if(!(pDM_Odm->SupportAbility&ODM_MAC_EDCA_TURBO)){
  7881. ODM_RT_TRACE(pDM_Odm, ODM_COMP_EDCA_TURBO, ODM_DBG_LOUD, ("ODM_MAC_EDCA_TURBO NOT SUPPORTED\n"));
  7882. return;
  7883. }
  7884. #if((DM_ODM_SUPPORT_TYPE==ODM_AP)&& defined(RTL_MANUAL_EDCA) && defined(WIFI_WMM))
  7885. if(priv->pmib->dot11QosEntry.ManualEDCA){
  7886. ODM_RT_TRACE(pDM_Odm, ODM_COMP_EDCA_TURBO, ODM_DBG_LOUD, ("ODM_MAC_EDCA_TURBO OFF: MANUAL SETTING\n"));
  7887. return ;
  7888. }
  7889. #endif
  7890. #if !(DM_ODM_SUPPORT_TYPE &ODM_AP)
  7891. //////////////////////////////////////////////////////
  7892. //find high TP STA every 2s
  7893. //////////////////////////////////////////////////////
  7894. if ((GET_ROOT(priv)->up_time % 2) == 0)
  7895. priv->pshare->highTP_found_pstat==NULL;
  7896. #if 0
  7897. phead = &priv->asoc_list;
  7898. plist = phead->next;
  7899. while(plist != phead) {
  7900. pstat = list_entry(plist, struct stat_info, asoc_list);
  7901. if(ODM_ChooseIotMainSTA(pDM_Odm, pstat)); //find the correct station
  7902. break;
  7903. if (plist == plist->next) //the last plist
  7904. break;
  7905. plist = plist->next;
  7906. };
  7907. #endif
  7908. //find highTP STA
  7909. for(i=0; i<ODM_ASSOCIATE_ENTRY_NUM; i++) {
  7910. pstat = pDM_Odm->pODM_StaInfo[i];
  7911. if(IS_STA_VALID(pstat) && (ODM_ChooseIotMainSTA(pDM_Odm, pstat))) //find the correct station
  7912. break;
  7913. }
  7914. //////////////////////////////////////////////////////
  7915. //if highTP STA is not found, then return
  7916. //////////////////////////////////////////////////////
  7917. if(priv->pshare->highTP_found_pstat==NULL) {
  7918. ODM_RT_TRACE(pDM_Odm, ODM_COMP_EDCA_TURBO, ODM_DBG_LOUD, ("ODM_MAC_EDCA_TURBO OFF: NO HT STA FOUND\n"));
  7919. return;
  7920. }
  7921. #endif
  7922. pstat=priv->pshare->highTP_found_pstat;
  7923. #ifdef WIFI_WMM
  7924. if (QOS_ENABLE) {
  7925. if (!priv->pmib->dot11OperationEntry.wifi_specific
  7926. #if(DM_ODM_SUPPORT_TYPE==ODM_AP)
  7927. ||((OPMODE & WIFI_AP_STATE) && (priv->pmib->dot11OperationEntry.wifi_specific == 2))
  7928. #elif(DM_ODM_SUPPORT_TYPE==ODM_ADSL)
  7929. || (priv->pmib->dot11OperationEntry.wifi_specific == 2)
  7930. #endif
  7931. ) {
  7932. if (priv->pshare->iot_mode_enable &&
  7933. ((priv->pshare->phw->VO_pkt_count > 50) ||
  7934. (priv->pshare->phw->VI_pkt_count > 50) ||
  7935. (priv->pshare->phw->BK_pkt_count > 50))) {
  7936. priv->pshare->iot_mode_enable = 0;
  7937. switch_turbo++;
  7938. } else if ((!priv->pshare->iot_mode_enable) &&
  7939. ((priv->pshare->phw->VO_pkt_count < 50) &&
  7940. (priv->pshare->phw->VI_pkt_count < 50) &&
  7941. (priv->pshare->phw->BK_pkt_count < 50))) {
  7942. priv->pshare->iot_mode_enable++;
  7943. switch_turbo++;
  7944. }
  7945. }
  7946. #if(DM_ODM_SUPPORT_TYPE==ODM_AP)
  7947. if ((OPMODE & WIFI_AP_STATE) && priv->pmib->dot11OperationEntry.wifi_specific)
  7948. #elif (DM_ODM_SUPPORT_TYPE==ODM_ADSL)
  7949. if (priv->pmib->dot11OperationEntry.wifi_specific)
  7950. #endif
  7951. {
  7952. if (!priv->pshare->iot_mode_VO_exist && (priv->pshare->phw->VO_pkt_count > 50)) {
  7953. priv->pshare->iot_mode_VO_exist++;
  7954. switch_turbo++;
  7955. } else if (priv->pshare->iot_mode_VO_exist && (priv->pshare->phw->VO_pkt_count < 50)) {
  7956. priv->pshare->iot_mode_VO_exist = 0;
  7957. switch_turbo++;
  7958. }
  7959. #if((DM_ODM_SUPPORT_TYPE==ODM_ADSL)||((DM_ODM_SUPPORT_TYPE==ODM_AP)&&(defined WMM_VIBE_PRI)))
  7960. if (priv->pshare->iot_mode_VO_exist) {
  7961. //printk("[%s %d] BE_pkt_count=%d\n", __FUNCTION__, __LINE__, priv->pshare->phw->BE_pkt_count);
  7962. if (!priv->pshare->iot_mode_BE_exist && (priv->pshare->phw->BE_pkt_count > 250)) {
  7963. priv->pshare->iot_mode_BE_exist++;
  7964. switch_turbo++;
  7965. } else if (priv->pshare->iot_mode_BE_exist && (priv->pshare->phw->BE_pkt_count < 250)) {
  7966. priv->pshare->iot_mode_BE_exist = 0;
  7967. switch_turbo++;
  7968. }
  7969. }
  7970. #endif
  7971. #if (DM_ODM_SUPPORT_TYPE==ODM_AP)
  7972. if (priv->pshare->rf_ft_var.wifi_beq_iot)
  7973. {
  7974. if (!priv->pshare->iot_mode_VI_exist && (priv->pshare->phw->VI_rx_pkt_count > 50)) {
  7975. priv->pshare->iot_mode_VI_exist++;
  7976. switch_turbo++;
  7977. } else if (priv->pshare->iot_mode_VI_exist && (priv->pshare->phw->VI_rx_pkt_count < 50)) {
  7978. priv->pshare->iot_mode_VI_exist = 0;
  7979. switch_turbo++;
  7980. }
  7981. }
  7982. #endif
  7983. }
  7984. else if (!pstat || pstat->rssi < priv->pshare->rf_ft_var.txop_enlarge_lower) {
  7985. if (priv->pshare->txop_enlarge) {
  7986. priv->pshare->txop_enlarge = 0;
  7987. if (priv->pshare->iot_mode_enable)
  7988. switch_turbo++;
  7989. }
  7990. }
  7991. #if(defined(CLIENT_MODE) && (DM_ODM_SUPPORT_TYPE==ODM_AP))
  7992. if ((OPMODE & WIFI_STATION_STATE) && (priv->pmib->dot11OperationEntry.wifi_specific == 2))
  7993. {
  7994. if (priv->pshare->iot_mode_enable &&
  7995. (((priv->pshare->phw->VO_pkt_count > 50) ||
  7996. (priv->pshare->phw->VI_pkt_count > 50) ||
  7997. (priv->pshare->phw->BK_pkt_count > 50)) ||
  7998. (pstat && (!pstat->ADDBA_ready[0]) & (!pstat->ADDBA_ready[3]))))
  7999. {
  8000. priv->pshare->iot_mode_enable = 0;
  8001. switch_turbo++;
  8002. }
  8003. else if ((!priv->pshare->iot_mode_enable) &&
  8004. (((priv->pshare->phw->VO_pkt_count < 50) &&
  8005. (priv->pshare->phw->VI_pkt_count < 50) &&
  8006. (priv->pshare->phw->BK_pkt_count < 50)) &&
  8007. (pstat && (pstat->ADDBA_ready[0] | pstat->ADDBA_ready[3]))))
  8008. {
  8009. priv->pshare->iot_mode_enable++;
  8010. switch_turbo++;
  8011. }
  8012. }
  8013. #endif
  8014. priv->pshare->phw->VO_pkt_count = 0;
  8015. priv->pshare->phw->VI_pkt_count = 0;
  8016. priv->pshare->phw->BK_pkt_count = 0;
  8017. #if((DM_ODM_SUPPORT_TYPE==ODM_ADSL)||((DM_ODM_SUPPORT_TYPE==ODM_AP)&&(defined WMM_VIBE_PRI)))
  8018. priv->pshare->phw->BE_pkt_count = 0;
  8019. #endif
  8020. #if(DM_ODM_SUPPORT_TYPE==ODM_AP)
  8021. if (priv->pshare->rf_ft_var.wifi_beq_iot)
  8022. priv->pshare->phw->VI_rx_pkt_count = 0;
  8023. #endif
  8024. }
  8025. #endif
  8026. if ((priv->up_time % 2) == 0) {
  8027. /*
  8028. * decide EDCA content for different chip vendor
  8029. */
  8030. #ifdef WIFI_WMM
  8031. #if(DM_ODM_SUPPORT_TYPE==ODM_ADSL)
  8032. if (QOS_ENABLE && (!priv->pmib->dot11OperationEntry.wifi_specific || (priv->pmib->dot11OperationEntry.wifi_specific == 2)
  8033. #elif(DM_ODM_SUPPORT_TYPE==ODM_AP)
  8034. if (QOS_ENABLE && (!priv->pmib->dot11OperationEntry.wifi_specific ||
  8035. ((OPMODE & WIFI_AP_STATE) && (priv->pmib->dot11OperationEntry.wifi_specific == 2))
  8036. #ifdef CLIENT_MODE
  8037. || ((OPMODE & WIFI_STATION_STATE) && (priv->pmib->dot11OperationEntry.wifi_specific == 2))
  8038. #endif
  8039. #endif
  8040. ))
  8041. {
  8042. if (pstat && pstat->rssi >= priv->pshare->rf_ft_var.txop_enlarge_upper) {
  8043. #ifdef LOW_TP_TXOP
  8044. #if (DM_ODM_SUPPORT_TYPE &ODM_AP) && defined(USE_OUT_SRC)
  8045. if (pstat->IOTPeer==HT_IOT_PEER_INTEL)
  8046. #else
  8047. if (pstat->is_intel_sta)
  8048. #endif
  8049. {
  8050. if (priv->pshare->txop_enlarge != 0xe)
  8051. {
  8052. priv->pshare->txop_enlarge = 0xe;
  8053. if (priv->pshare->iot_mode_enable)
  8054. switch_turbo++;
  8055. }
  8056. }
  8057. else if (priv->pshare->txop_enlarge != 2)
  8058. {
  8059. priv->pshare->txop_enlarge = 2;
  8060. if (priv->pshare->iot_mode_enable)
  8061. switch_turbo++;
  8062. }
  8063. #else
  8064. if (priv->pshare->txop_enlarge != 2)
  8065. {
  8066. #if (DM_ODM_SUPPORT_TYPE &ODM_AP) && defined(USE_OUT_SRC)
  8067. if (pstat->IOTPeer==HT_IOT_PEER_INTEL)
  8068. #else
  8069. if (pstat->is_intel_sta)
  8070. #endif
  8071. priv->pshare->txop_enlarge = 0xe;
  8072. #if (DM_ODM_SUPPORT_TYPE &ODM_AP) && defined(USE_OUT_SRC)
  8073. else if (pstat->IOTPeer==HT_IOT_PEER_RALINK)
  8074. #else
  8075. else if (pstat->is_ralink_sta)
  8076. #endif
  8077. priv->pshare->txop_enlarge = 0xd;
  8078. else
  8079. priv->pshare->txop_enlarge = 2;
  8080. if (priv->pshare->iot_mode_enable)
  8081. switch_turbo++;
  8082. }
  8083. #endif
  8084. #if 0
  8085. if (priv->pshare->txop_enlarge != 2)
  8086. {
  8087. #if(DM_ODM_SUPPORT_TYPE==ODM_AP)
  8088. if (pstat->IOTPeer==HT_IOT_PEER_INTEL)
  8089. #else
  8090. if (pstat->is_intel_sta)
  8091. #endif
  8092. priv->pshare->txop_enlarge = 0xe;
  8093. #if(DM_ODM_SUPPORT_TYPE==ODM_AP)
  8094. else if (pstat->IOTPeer==HT_IOT_PEER_RALINK)
  8095. priv->pshare->txop_enlarge = 0xd;
  8096. #endif
  8097. else
  8098. priv->pshare->txop_enlarge = 2;
  8099. if (priv->pshare->iot_mode_enable)
  8100. switch_turbo++;
  8101. }
  8102. #endif
  8103. }
  8104. else if (!pstat || pstat->rssi < priv->pshare->rf_ft_var.txop_enlarge_lower)
  8105. {
  8106. if (priv->pshare->txop_enlarge) {
  8107. priv->pshare->txop_enlarge = 0;
  8108. if (priv->pshare->iot_mode_enable)
  8109. switch_turbo++;
  8110. }
  8111. }
  8112. #if((DM_ODM_SUPPORT_TYPE==ODM_AP)&&( defined LOW_TP_TXOP))
  8113. // for Intel IOT, need to enlarge CW MAX from 6 to 10
  8114. if (pstat && pstat->is_intel_sta && (((pstat->tx_avarage+pstat->rx_avarage)>>10) <
  8115. priv->pshare->rf_ft_var.cwmax_enhance_thd))
  8116. {
  8117. if (!priv->pshare->BE_cwmax_enhance && priv->pshare->iot_mode_enable)
  8118. {
  8119. priv->pshare->BE_cwmax_enhance = 1;
  8120. switch_turbo++;
  8121. }
  8122. } else {
  8123. if (priv->pshare->BE_cwmax_enhance) {
  8124. priv->pshare->BE_cwmax_enhance = 0;
  8125. switch_turbo++;
  8126. }
  8127. }
  8128. #endif
  8129. }
  8130. #endif
  8131. priv->pshare->current_tx_bytes = 0;
  8132. priv->pshare->current_rx_bytes = 0;
  8133. }
  8134. #if((DM_ODM_SUPPORT_TYPE==ODM_AP)&& defined( SW_TX_QUEUE))
  8135. if ((priv->assoc_num > 1) && (AMPDU_ENABLE))
  8136. {
  8137. if (priv->swq_txmac_chg >= priv->pshare->rf_ft_var.swq_en_highthd){
  8138. if ((priv->swq_en == 0)){
  8139. switch_turbo++;
  8140. if (priv->pshare->txop_enlarge == 0)
  8141. priv->pshare->txop_enlarge = 2;
  8142. priv->swq_en = 1;
  8143. }
  8144. else
  8145. {
  8146. if ((switch_turbo > 0) && (priv->pshare->txop_enlarge == 0) && (priv->pshare->iot_mode_enable != 0))
  8147. {
  8148. priv->pshare->txop_enlarge = 2;
  8149. switch_turbo--;
  8150. }
  8151. }
  8152. }
  8153. else if(priv->swq_txmac_chg <= priv->pshare->rf_ft_var.swq_dis_lowthd){
  8154. priv->swq_en = 0;
  8155. }
  8156. else if ((priv->swq_en == 1) && (switch_turbo > 0) && (priv->pshare->txop_enlarge == 0) && (priv->pshare->iot_mode_enable != 0)) {
  8157. priv->pshare->txop_enlarge = 2;
  8158. switch_turbo--;
  8159. }
  8160. }
  8161. #if ((DM_ODM_SUPPORT_TYPE==ODM_AP)&&(defined CONFIG_RTL_819XD))
  8162. else if( (priv->assoc_num == 1) && (AMPDU_ENABLE)) {
  8163. if (pstat) {
  8164. int en_thd = 14417920>>(priv->up_time % 2);
  8165. if ((priv->swq_en == 0) && (pstat->current_tx_bytes > en_thd) && (pstat->current_rx_bytes > en_thd) ) { //50Mbps
  8166. priv->swq_en = 1;
  8167. priv->swqen_keeptime = priv->up_time;
  8168. }
  8169. else if ((priv->swq_en == 1) && ((pstat->tx_avarage < 4587520) || (pstat->rx_avarage < 4587520))) { //35Mbps
  8170. priv->swq_en = 0;
  8171. priv->swqen_keeptime = 0;
  8172. }
  8173. }
  8174. else {
  8175. priv->swq_en = 0;
  8176. priv->swqen_keeptime = 0;
  8177. }
  8178. }
  8179. #endif
  8180. #endif
  8181. #ifdef WIFI_WMM
  8182. #ifdef LOW_TP_TXOP
  8183. if ((!priv->pmib->dot11OperationEntry.wifi_specific || (priv->pmib->dot11OperationEntry.wifi_specific == 2))
  8184. && QOS_ENABLE) {
  8185. if (switch_turbo || priv->pshare->rf_ft_var.low_tp_txop) {
  8186. unsigned int thd_tp;
  8187. unsigned char under_thd;
  8188. unsigned int curr_tp;
  8189. if (priv->pmib->dot11BssType.net_work_type & (ODM_WM_N24G|ODM_WM_N5G| ODM_WM_G))
  8190. {
  8191. // Determine the upper bound throughput threshold.
  8192. if (priv->pmib->dot11BssType.net_work_type & (ODM_WM_N24G|ODM_WM_N5G)) {
  8193. if (priv->assoc_num && priv->assoc_num != priv->pshare->ht_sta_num)
  8194. thd_tp = priv->pshare->rf_ft_var.low_tp_txop_thd_g;
  8195. else
  8196. thd_tp = priv->pshare->rf_ft_var.low_tp_txop_thd_n;
  8197. }
  8198. else
  8199. thd_tp = priv->pshare->rf_ft_var.low_tp_txop_thd_g;
  8200. // Determine to close txop.
  8201. curr_tp = (unsigned int)(priv->ext_stats.tx_avarage>>17) + (unsigned int)(priv->ext_stats.rx_avarage>>17);
  8202. if (curr_tp <= thd_tp && curr_tp >= priv->pshare->rf_ft_var.low_tp_txop_thd_low)
  8203. under_thd = 1;
  8204. else
  8205. under_thd = 0;
  8206. }
  8207. else
  8208. {
  8209. under_thd = 0;
  8210. }
  8211. if (switch_turbo)
  8212. {
  8213. priv->pshare->rf_ft_var.low_tp_txop_close = under_thd;
  8214. priv->pshare->rf_ft_var.low_tp_txop_count = 0;
  8215. }
  8216. else if (priv->pshare->iot_mode_enable && (priv->pshare->rf_ft_var.low_tp_txop_close != under_thd)) {
  8217. priv->pshare->rf_ft_var.low_tp_txop_count++;
  8218. if (priv->pshare->rf_ft_var.low_tp_txop_close) {
  8219. priv->pshare->rf_ft_var.low_tp_txop_count = priv->pshare->rf_ft_var.low_tp_txop_delay;
  8220. }
  8221. if (priv->pshare->rf_ft_var.low_tp_txop_count ==priv->pshare->rf_ft_var.low_tp_txop_delay)
  8222. {
  8223. priv->pshare->rf_ft_var.low_tp_txop_count = 0;
  8224. priv->pshare->rf_ft_var.low_tp_txop_close = under_thd;
  8225. switch_turbo++;
  8226. }
  8227. }
  8228. else
  8229. {
  8230. priv->pshare->rf_ft_var.low_tp_txop_count = 0;
  8231. }
  8232. }
  8233. }
  8234. #endif
  8235. if (switch_turbo)
  8236. ODM_IotEdcaSwitch( pDM_Odm, priv->pshare->iot_mode_enable );
  8237. #endif
  8238. }
  8239. #endif
  8240. #if( DM_ODM_SUPPORT_TYPE == ODM_WIN)
  8241. //
  8242. // 2011/07/26 MH Add an API for testing IQK fail case.
  8243. //
  8244. BOOLEAN
  8245. ODM_CheckPowerStatus(
  8246. IN PADAPTER Adapter)
  8247. {
  8248. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  8249. PDM_ODM_T pDM_Odm = &pHalData->DM_OutSrc;
  8250. RT_RF_POWER_STATE rtState;
  8251. PMGNT_INFO pMgntInfo = &(Adapter->MgntInfo);
  8252. // 2011/07/27 MH We are not testing ready~~!! We may fail to get correct value when init sequence.
  8253. if (pMgntInfo->init_adpt_in_progress == TRUE)
  8254. {
  8255. ODM_RT_TRACE(pDM_Odm, ODM_COMP_INIT, ODM_DBG_LOUD, ("ODM_CheckPowerStatus Return TRUE, due to initadapter"));
  8256. return TRUE;
  8257. }
  8258. //
  8259. // 2011/07/19 MH We can not execute tx pwoer tracking/ LLC calibrate or IQK.
  8260. //
  8261. Adapter->HalFunc.GetHwRegHandler(Adapter, HW_VAR_RF_STATE, (pu1Byte)(&rtState));
  8262. if(Adapter->bDriverStopped || Adapter->bDriverIsGoingToPnpSetPowerSleep || rtState == eRfOff)
  8263. {
  8264. ODM_RT_TRACE(pDM_Odm, ODM_COMP_INIT, ODM_DBG_LOUD, ("ODM_CheckPowerStatus Return FALSE, due to %d/%d/%d\n",
  8265. Adapter->bDriverStopped, Adapter->bDriverIsGoingToPnpSetPowerSleep, rtState));
  8266. return FALSE;
  8267. }
  8268. return TRUE;
  8269. }
  8270. #endif
  8271. // need to ODM CE Platform
  8272. //move to here for ANT detection mechanism using
  8273. #if ((DM_ODM_SUPPORT_TYPE == ODM_WIN)||(DM_ODM_SUPPORT_TYPE == ODM_CE))
  8274. u4Byte
  8275. GetPSDData(
  8276. IN PDM_ODM_T pDM_Odm,
  8277. unsigned int point,
  8278. u1Byte initial_gain_psd)
  8279. {
  8280. //unsigned int val, rfval;
  8281. //int psd_report;
  8282. u4Byte psd_report;
  8283. //HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  8284. //Debug Message
  8285. //val = PHY_QueryBBReg(Adapter,0x908, bMaskDWord);
  8286. //DbgPrint("Reg908 = 0x%x\n",val);
  8287. //val = PHY_QueryBBReg(Adapter,0xDF4, bMaskDWord);
  8288. //rfval = PHY_QueryRFReg(Adapter, ODM_RF_PATH_A, 0x00, bRFRegOffsetMask);
  8289. //DbgPrint("RegDF4 = 0x%x, RFReg00 = 0x%x\n",val, rfval);
  8290. //DbgPrint("PHYTXON = %x, OFDMCCA_PP = %x, CCKCCA_PP = %x, RFReg00 = %x\n",
  8291. //(val&BIT25)>>25, (val&BIT14)>>14, (val&BIT15)>>15, rfval);
  8292. //Set DCO frequency index, offset=(40MHz/SamplePts)*point
  8293. ODM_SetBBReg(pDM_Odm, 0x808, 0x3FF, point);
  8294. //Start PSD calculation, Reg808[22]=0->1
  8295. ODM_SetBBReg(pDM_Odm, 0x808, BIT22, 1);
  8296. //Need to wait for HW PSD report
  8297. ODM_StallExecution(1000);
  8298. ODM_SetBBReg(pDM_Odm, 0x808, BIT22, 0);
  8299. //Read PSD report, Reg8B4[15:0]
  8300. psd_report = ODM_GetBBReg(pDM_Odm,0x8B4, bMaskDWord) & 0x0000FFFF;
  8301. #if 1//(DEV_BUS_TYPE == RT_PCI_INTERFACE) && ( (RT_PLATFORM == PLATFORM_LINUX) || (RT_PLATFORM == PLATFORM_MACOSX))
  8302. psd_report = (u4Byte) (ConvertTo_dB(psd_report))+(u4Byte)(initial_gain_psd-0x1c);
  8303. #else
  8304. psd_report = (int) (20*log10((double)psd_report))+(int)(initial_gain_psd-0x1c);
  8305. #endif
  8306. return psd_report;
  8307. }
  8308. u4Byte
  8309. ConvertTo_dB(
  8310. u4Byte Value)
  8311. {
  8312. u1Byte i;
  8313. u1Byte j;
  8314. u4Byte dB;
  8315. Value = Value & 0xFFFF;
  8316. for (i=0;i<8;i++)
  8317. {
  8318. if (Value <= dB_Invert_Table[i][11])
  8319. {
  8320. break;
  8321. }
  8322. }
  8323. if (i >= 8)
  8324. {
  8325. return (96); // maximum 96 dB
  8326. }
  8327. for (j=0;j<12;j++)
  8328. {
  8329. if (Value <= dB_Invert_Table[i][j])
  8330. {
  8331. break;
  8332. }
  8333. }
  8334. dB = i*12 + j + 1;
  8335. return (dB);
  8336. }
  8337. #endif
  8338. //
  8339. // LukeLee:
  8340. // PSD function will be moved to FW in future IC, but now is only implemented in MP platform
  8341. // So PSD function will not be incorporated to common ODM
  8342. //
  8343. #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
  8344. #define AFH_PSD 1 //0:normal PSD scan, 1: only do 20 pts PSD
  8345. #define MODE_40M 0 //0:20M, 1:40M
  8346. #define PSD_TH2 3
  8347. #define PSD_CHMIN 20 // Minimum channel number for BT AFH
  8348. #define SIR_STEP_SIZE 3
  8349. #define Smooth_Size_1 5
  8350. #define Smooth_TH_1 3
  8351. #define Smooth_Size_2 10
  8352. #define Smooth_TH_2 4
  8353. #define Smooth_Size_3 20
  8354. #define Smooth_TH_3 4
  8355. #define Smooth_Step_Size 5
  8356. #define Adaptive_SIR 1
  8357. //#if(RTL8723_FPGA_VERIFICATION == 1)
  8358. //#define PSD_RESCAN 1
  8359. //#else
  8360. //#define PSD_RESCAN 4
  8361. //#endif
  8362. #define SCAN_INTERVAL 1500 //ms
  8363. #define SYN_Length 5 // for 92D
  8364. #define LNA_Low_Gain_1 0x64
  8365. #define LNA_Low_Gain_2 0x5A
  8366. #define LNA_Low_Gain_3 0x58
  8367. #define pw_th_10dB 0x0
  8368. #define pw_th_16dB 0x3
  8369. #define FA_RXHP_TH1 5000
  8370. #define FA_RXHP_TH2 1500
  8371. #define FA_RXHP_TH3 800
  8372. #define FA_RXHP_TH4 600
  8373. #define FA_RXHP_TH5 500
  8374. #define Idle_Mode 0
  8375. #define High_TP_Mode 1
  8376. #define Low_TP_Mode 2
  8377. VOID
  8378. odm_PSDMonitorInit(
  8379. IN PDM_ODM_T pDM_Odm)
  8380. {
  8381. #if (DEV_BUS_TYPE == RT_PCI_INTERFACE)|(DEV_BUS_TYPE == RT_USB_INTERFACE)
  8382. //HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  8383. //PSD Monitor Setting
  8384. //Which path in ADC/DAC is turnned on for PSD: both I/Q
  8385. ODM_SetBBReg(pDM_Odm, ODM_PSDREG, BIT10|BIT11, 0x3);
  8386. //Ageraged number: 8
  8387. ODM_SetBBReg(pDM_Odm, ODM_PSDREG, BIT12|BIT13, 0x1);
  8388. pDM_Odm->bPSDinProcess = FALSE;
  8389. pDM_Odm->bUserAssignLevel = FALSE;
  8390. pDM_Odm->bPSDactive = FALSE;
  8391. //pDM_Odm->bDMInitialGainEnable=TRUE; //change the initialization to DIGinit
  8392. //Set Debug Port
  8393. //PHY_SetBBReg(Adapter, 0x908, bMaskDWord, 0x803);
  8394. //PHY_SetBBReg(Adapter, 0xB34, bMaskByte0, 0x00); // pause PSD
  8395. //PHY_SetBBReg(Adapter, 0xB38, bMaskByte0, 10); //rescan
  8396. //PHY_SetBBReg(Adapter, 0xB38, bMaskByte2|bMaskByte3, 100); //interval
  8397. //PlatformSetTimer( Adapter, &pHalData->PSDTriggerTimer, 0); //ms
  8398. #endif
  8399. }
  8400. VOID
  8401. PatchDCTone(
  8402. IN PDM_ODM_T pDM_Odm,
  8403. pu4Byte PSD_report,
  8404. u1Byte initial_gain_psd
  8405. )
  8406. {
  8407. //HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  8408. //PADAPTER pAdapter;
  8409. u4Byte psd_report;
  8410. //2 Switch to CH11 to patch CH9 and CH13 DC tone
  8411. ODM_SetRFReg(pDM_Odm, ODM_RF_PATH_A, RF_CHNLBW, 0x3FF, 11);
  8412. if(pDM_Odm->SupportICType== ODM_RTL8192D)
  8413. {
  8414. if((*(pDM_Odm->pMacPhyMode) == ODM_SMSP)||(*(pDM_Odm->pMacPhyMode) == ODM_DMSP))
  8415. {
  8416. ODM_SetRFReg(pDM_Odm, ODM_RF_PATH_B, RF_CHNLBW, 0x3FF, 11);
  8417. ODM_SetRFReg(pDM_Odm, ODM_RF_PATH_B, 0x25, 0xfffff, 0x643BC);
  8418. ODM_SetRFReg(pDM_Odm, ODM_RF_PATH_B, 0x26, 0xfffff, 0xFC038);
  8419. ODM_SetRFReg(pDM_Odm, ODM_RF_PATH_B, 0x27, 0xfffff, 0x77C1A);
  8420. ODM_SetRFReg(pDM_Odm, ODM_RF_PATH_B, 0x2B, 0xfffff, 0x41289);
  8421. ODM_SetRFReg(pDM_Odm, ODM_RF_PATH_B, 0x2C, 0xfffff, 0x01840);
  8422. }
  8423. else
  8424. {
  8425. ODM_SetRFReg(pDM_Odm, ODM_RF_PATH_A, 0x25, 0xfffff, 0x643BC);
  8426. ODM_SetRFReg(pDM_Odm, ODM_RF_PATH_A, 0x26, 0xfffff, 0xFC038);
  8427. ODM_SetRFReg(pDM_Odm, ODM_RF_PATH_A, 0x27, 0xfffff, 0x77C1A);
  8428. ODM_SetRFReg(pDM_Odm, ODM_RF_PATH_A, 0x2B, 0xfffff, 0x41289);
  8429. ODM_SetRFReg(pDM_Odm, ODM_RF_PATH_A, 0x2C, 0xfffff, 0x01840);
  8430. }
  8431. }
  8432. //Ch9 DC tone patch
  8433. psd_report = GetPSDData(pDM_Odm, 96, initial_gain_psd);
  8434. PSD_report[50] = psd_report;
  8435. //Ch13 DC tone patch
  8436. psd_report = GetPSDData(pDM_Odm, 32, initial_gain_psd);
  8437. PSD_report[70] = psd_report;
  8438. //2 Switch to CH3 to patch CH1 and CH5 DC tone
  8439. ODM_SetRFReg(pDM_Odm, ODM_RF_PATH_A, RF_CHNLBW, 0x3FF, 3);
  8440. if(pDM_Odm->SupportICType==ODM_RTL8192D)
  8441. {
  8442. if((*(pDM_Odm->pMacPhyMode) == ODM_SMSP)||(*(pDM_Odm->pMacPhyMode) == ODM_DMSP))
  8443. {
  8444. ODM_SetRFReg(pDM_Odm, ODM_RF_PATH_B, RF_CHNLBW, 0x3FF, 3);
  8445. //PHY_SetRFReg(Adapter, ODM_RF_PATH_B, 0x25, 0xfffff, 0x643BC);
  8446. //PHY_SetRFReg(Adapter, ODM_RF_PATH_B, 0x26, 0xfffff, 0xFC038);
  8447. ODM_SetRFReg(pDM_Odm, ODM_RF_PATH_B, 0x27, 0xfffff, 0x07C1A);
  8448. //PHY_SetRFReg(Adapter, ODM_RF_PATH_B, 0x2B, 0xfffff, 0x61289);
  8449. //PHY_SetRFReg(Adapter, ODM_RF_PATH_B, 0x2C, 0xfffff, 0x01C41);
  8450. }
  8451. else
  8452. {
  8453. //PHY_SetRFReg(Adapter, ODM_RF_PATH_A, 0x25, 0xfffff, 0x643BC);
  8454. //PHY_SetRFReg(Adapter, ODM_RF_PATH_A, 0x26, 0xfffff, 0xFC038);
  8455. ODM_SetRFReg(pDM_Odm, ODM_RF_PATH_A, 0x27, 0xfffff, 0x07C1A);
  8456. //PHY_SetRFReg(Adapter, ODM_RF_PATH_A, 0x2B, 0xfffff, 0x61289);
  8457. //PHY_SetRFReg(Adapter, ODM_RF_PATH_A, 0x2C, 0xfffff, 0x01C41);
  8458. }
  8459. }
  8460. //Ch1 DC tone patch
  8461. psd_report = GetPSDData(pDM_Odm, 96, initial_gain_psd);
  8462. PSD_report[10] = psd_report;
  8463. //Ch5 DC tone patch
  8464. psd_report = GetPSDData(pDM_Odm, 32, initial_gain_psd);
  8465. PSD_report[30] = psd_report;
  8466. }
  8467. VOID
  8468. GoodChannelDecision(
  8469. PDM_ODM_T pDM_Odm,
  8470. pu4Byte PSD_report,
  8471. pu1Byte PSD_bitmap,
  8472. u1Byte RSSI_BT,
  8473. pu1Byte PSD_bitmap_memory)
  8474. {
  8475. pRXHP_T pRX_HP_Table = &pDM_Odm->DM_RXHP_Table;
  8476. //s4Byte TH1 = SSBT-0x15; // modify TH by Neil Chen
  8477. s4Byte TH1= RSSI_BT+0x14;
  8478. s4Byte TH2 = RSSI_BT+85;
  8479. //u2Byte TH3;
  8480. // s4Byte RegB34;
  8481. u1Byte bitmap, Smooth_size[3], Smooth_TH[3];
  8482. //u1Byte psd_bit;
  8483. u4Byte i,n,j, byte_idx, bit_idx, good_cnt, good_cnt_smoothing, Smooth_Interval[3];
  8484. int start_byte_idx,start_bit_idx,cur_byte_idx, cur_bit_idx,NOW_byte_idx ;
  8485. // RegB34 = PHY_QueryBBReg(Adapter,0xB34, bMaskDWord)&0xFF;
  8486. if((pDM_Odm->SupportICType == ODM_RTL8192C)||(pDM_Odm->SupportICType == ODM_RTL8192D))
  8487. {
  8488. TH1 = RSSI_BT + 0x14;
  8489. }
  8490. Smooth_size[0]=Smooth_Size_1;
  8491. Smooth_size[1]=Smooth_Size_2;
  8492. Smooth_size[2]=Smooth_Size_3;
  8493. Smooth_TH[0]=Smooth_TH_1;
  8494. Smooth_TH[1]=Smooth_TH_2;
  8495. Smooth_TH[2]=Smooth_TH_3;
  8496. Smooth_Interval[0]=16;
  8497. Smooth_Interval[1]=15;
  8498. Smooth_Interval[2]=13;
  8499. good_cnt = 0;
  8500. if(pDM_Odm->SupportICType==ODM_RTL8723A)
  8501. {
  8502. //2 Threshold
  8503. if(RSSI_BT >=41)
  8504. TH1 = 113;
  8505. else if(RSSI_BT >=38) // >= -15dBm
  8506. TH1 = 105; //0x69
  8507. else if((RSSI_BT >=33)&(RSSI_BT <38))
  8508. TH1 = 99+(RSSI_BT-33); //0x63
  8509. else if((RSSI_BT >=26)&(RSSI_BT<33))
  8510. TH1 = 99-(33-RSSI_BT)+2; //0x5e
  8511. else if((RSSI_BT >=24)&(RSSI_BT<26))
  8512. TH1 = 88-((RSSI_BT-24)*3); //0x58
  8513. else if((RSSI_BT >=18)&(RSSI_BT<24))
  8514. TH1 = 77+((RSSI_BT-18)*2);
  8515. else if((RSSI_BT >=14)&(RSSI_BT<18))
  8516. TH1 = 63+((RSSI_BT-14)*2);
  8517. else if((RSSI_BT >=8)&(RSSI_BT<14))
  8518. TH1 = 58+((RSSI_BT-8)*2);
  8519. else if((RSSI_BT >=3)&(RSSI_BT<8))
  8520. TH1 = 52+(RSSI_BT-3);
  8521. else
  8522. TH1 = 51;
  8523. }
  8524. for (i = 0; i< 10; i++)
  8525. PSD_bitmap[i] = 0;
  8526. // Add By Gary
  8527. for (i=0; i<80; i++)
  8528. pRX_HP_Table->PSD_bitmap_RXHP[i] = 0;
  8529. // End
  8530. if(pDM_Odm->SupportICType==ODM_RTL8723A)
  8531. {
  8532. TH1 =TH1-SIR_STEP_SIZE;
  8533. }
  8534. while (good_cnt < PSD_CHMIN)
  8535. {
  8536. good_cnt = 0;
  8537. if(pDM_Odm->SupportICType==ODM_RTL8723A)
  8538. {
  8539. if(TH1 ==TH2)
  8540. break;
  8541. if((TH1+SIR_STEP_SIZE) < TH2)
  8542. TH1 += SIR_STEP_SIZE;
  8543. else
  8544. TH1 = TH2;
  8545. }
  8546. else
  8547. {
  8548. if(TH1==(RSSI_BT+0x1E))
  8549. break;
  8550. if((TH1+2) < (RSSI_BT+0x1E))
  8551. TH1+=3;
  8552. else
  8553. TH1 = RSSI_BT+0x1E;
  8554. }
  8555. ODM_RT_TRACE(pDM_Odm,COMP_PSD,DBG_LOUD,("PSD: decision threshold is: %d", TH1));
  8556. for (i = 0; i< 80; i++)
  8557. {
  8558. if((s4Byte)(PSD_report[i]) < TH1)
  8559. {
  8560. byte_idx = i / 8;
  8561. bit_idx = i -8*byte_idx;
  8562. bitmap = PSD_bitmap[byte_idx];
  8563. PSD_bitmap[byte_idx] = bitmap | (u1Byte) (1 << bit_idx);
  8564. }
  8565. }
  8566. #if DBG
  8567. ODM_RT_TRACE(pDM_Odm,COMP_PSD, DBG_LOUD,("PSD: before smoothing\n"));
  8568. for(n=0;n<10;n++)
  8569. {
  8570. //DbgPrint("PSD_bitmap[%u]=%x\n", n, PSD_bitmap[n]);
  8571. for (i = 0; i<8; i++)
  8572. ODM_RT_TRACE(pDM_Odm,COMP_PSD, DBG_LOUD,("PSD_bitmap[%u] = %d\n", 2402+n*8+i, (PSD_bitmap[n]&BIT(i))>>i));
  8573. }
  8574. #endif
  8575. //1 Start of smoothing function
  8576. for (j=0;j<3;j++)
  8577. {
  8578. start_byte_idx=0;
  8579. start_bit_idx=0;
  8580. for(n=0; n<Smooth_Interval[j]; n++)
  8581. {
  8582. good_cnt_smoothing = 0;
  8583. cur_bit_idx = start_bit_idx;
  8584. cur_byte_idx = start_byte_idx;
  8585. for ( i=0; i < Smooth_size[j]; i++)
  8586. {
  8587. NOW_byte_idx = cur_byte_idx + (i+cur_bit_idx)/8;
  8588. if ( (PSD_bitmap[NOW_byte_idx]& BIT( (cur_bit_idx + i)%8)) != 0)
  8589. good_cnt_smoothing++;
  8590. }
  8591. if( good_cnt_smoothing < Smooth_TH[j] )
  8592. {
  8593. cur_bit_idx = start_bit_idx;
  8594. cur_byte_idx = start_byte_idx;
  8595. for ( i=0; i< Smooth_size[j] ; i++)
  8596. {
  8597. NOW_byte_idx = cur_byte_idx + (i+cur_bit_idx)/8;
  8598. PSD_bitmap[NOW_byte_idx] = PSD_bitmap[NOW_byte_idx] & (~BIT( (cur_bit_idx + i)%8));
  8599. }
  8600. }
  8601. start_bit_idx = start_bit_idx + Smooth_Step_Size;
  8602. while ( (start_bit_idx) > 7 )
  8603. {
  8604. start_byte_idx= start_byte_idx+start_bit_idx/8;
  8605. start_bit_idx = start_bit_idx%8;
  8606. }
  8607. }
  8608. ODM_RT_TRACE( pDM_Odm,COMP_PSD, DBG_LOUD,("PSD: after %u smoothing", j+1));
  8609. for(n=0;n<10;n++)
  8610. {
  8611. for (i = 0; i<8; i++)
  8612. {
  8613. ODM_RT_TRACE(pDM_Odm,COMP_PSD, DBG_LOUD,("PSD_bitmap[%u] = %d\n", 2402+n*8+i, (PSD_bitmap[n]&BIT(i))>>i));
  8614. if ( ((PSD_bitmap[n]&BIT(i))>>i) ==1) //----- Add By Gary
  8615. {
  8616. pRX_HP_Table->PSD_bitmap_RXHP[8*n+i] = 1;
  8617. } // ------end by Gary
  8618. }
  8619. }
  8620. }
  8621. good_cnt = 0;
  8622. for ( i = 0; i < 10; i++)
  8623. {
  8624. for (n = 0; n < 8; n++)
  8625. if((PSD_bitmap[i]& BIT(n)) != 0)
  8626. good_cnt++;
  8627. }
  8628. ODM_RT_TRACE(pDM_Odm,COMP_PSD, DBG_LOUD,("PSD: good channel cnt = %u",good_cnt));
  8629. }
  8630. //RT_TRACE(COMP_PSD, DBG_LOUD,("PSD: SSBT=%d, TH2=%d, TH1=%d",SSBT,TH2,TH1));
  8631. for (i = 0; i <10; i++)
  8632. ODM_RT_TRACE(pDM_Odm,COMP_PSD, DBG_LOUD,("PSD: PSD_bitmap[%u]=%x",i,PSD_bitmap[i]));
  8633. /*
  8634. //Update bitmap memory
  8635. for(i = 0; i < 80; i++)
  8636. {
  8637. byte_idx = i / 8;
  8638. bit_idx = i -8*byte_idx;
  8639. psd_bit = (PSD_bitmap[byte_idx] & BIT(bit_idx)) >> bit_idx;
  8640. bitmap = PSD_bitmap_memory[i];
  8641. PSD_bitmap_memory[i] = (bitmap << 1) |psd_bit;
  8642. }
  8643. */
  8644. }
  8645. VOID
  8646. odm_PSD_Monitor(
  8647. PDM_ODM_T pDM_Odm
  8648. )
  8649. {
  8650. //HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  8651. //PDM_ODM_T pDM_Odm = &pHalData->DM_OutSrc;
  8652. unsigned int pts, start_point, stop_point;
  8653. u1Byte initial_gain ;
  8654. static u1Byte PSD_bitmap_memory[80], init_memory = 0;
  8655. static u1Byte psd_cnt=0;
  8656. static u4Byte PSD_report[80], PSD_report_tmp;
  8657. static u8Byte lastTxOkCnt=0, lastRxOkCnt=0;
  8658. u1Byte H2C_PSD_DATA[5]={0,0,0,0,0};
  8659. static u1Byte H2C_PSD_DATA_last[5] ={0,0,0,0,0};
  8660. u1Byte idx[20]={96,99,102,106,109,112,115,118,122,125,
  8661. 0,3,6,10,13,16,19,22,26,29};
  8662. u1Byte n, i, channel, BBReset,tone_idx;
  8663. u1Byte PSD_bitmap[10], SSBT=0,initial_gain_psd=0, RSSI_BT=0, initialGainUpper;
  8664. s4Byte PSD_skip_start, PSD_skip_stop;
  8665. u4Byte CurrentChannel, RXIQI, RxIdleLowPwr, wlan_channel;
  8666. u4Byte ReScan, Interval, Is40MHz;
  8667. u8Byte curTxOkCnt, curRxOkCnt;
  8668. int cur_byte_idx, cur_bit_idx;
  8669. PADAPTER Adapter = pDM_Odm->Adapter;
  8670. PMGNT_INFO pMgntInfo = &Adapter->MgntInfo;
  8671. if( (*(pDM_Odm->pbScanInProcess)) ||
  8672. pDM_Odm->bLinkInProcess)
  8673. {
  8674. if((pDM_Odm->SupportICType==ODM_RTL8723A)&(pDM_Odm->SupportInterface==ODM_ITRF_PCIE))
  8675. {
  8676. //pHalData->bPSDactive=FALSE;
  8677. //ODM_SetTimer(pDM_Odm,&pDM_SWAT_Table->SwAntennaSwitchTimer, 100 )
  8678. ODM_SetTimer( pDM_Odm, &pDM_Odm->PSDTimer, 1500); //ms
  8679. //psd_cnt=0;
  8680. }
  8681. return;
  8682. }
  8683. if(pDM_Odm->bBtHsOperation)
  8684. {
  8685. ReScan = 1;
  8686. Interval = SCAN_INTERVAL;
  8687. }
  8688. else
  8689. {
  8690. ReScan = PSD_RESCAN;
  8691. Interval = SCAN_INTERVAL;
  8692. }
  8693. //1 Initialization
  8694. if(init_memory == 0)
  8695. {
  8696. ODM_RT_TRACE(pDM_Odm,ODM_COMP_PSD, DBG_LOUD,("Init memory\n"));
  8697. for(i = 0; i < 80; i++)
  8698. PSD_bitmap_memory[i] = 0xFF; // channel is always good
  8699. init_memory = 1;
  8700. }
  8701. if(psd_cnt == 0)
  8702. {
  8703. ODM_RT_TRACE(pDM_Odm,ODM_COMP_PSD, DBG_LOUD,("Enter dm_PSD_Monitor\n"));
  8704. for(i = 0; i < 80; i++)
  8705. PSD_report[i] = 0;
  8706. }
  8707. #if 0 //for test only
  8708. DbgPrint("cosa odm_PSD_Monitor call()\n");
  8709. DbgPrint("cosa pHalData->RSSI_BT = %d\n", pHalData->RSSI_BT);
  8710. DbgPrint("cosa pHalData->bUserAssignLevel = %d\n", pHalData->bUserAssignLevel);
  8711. #if 0
  8712. psd_cnt++;
  8713. if (psd_cnt < ReScan)
  8714. PlatformSetTimer( Adapter, &pHalData->PSDTimer, Interval); //ms
  8715. else
  8716. psd_cnt = 0;
  8717. return;
  8718. #endif
  8719. #endif
  8720. //1 Backup Current Settings
  8721. CurrentChannel = ODM_GetRFReg(pDM_Odm, ODM_RF_PATH_A, RF_CHNLBW, bRFRegOffsetMask);
  8722. /*
  8723. if(pDM_Odm->SupportICType==ODM_RTL8192D)
  8724. {
  8725. //2 Record Current synthesizer parameters based on current channel
  8726. if((*pDM_Odm->MacPhyMode92D == SINGLEMAC_SINGLEPHY)||(*pDM_Odm->MacPhyMode92D == DUALMAC_SINGLEPHY))
  8727. {
  8728. SYN_RF25 = ODM_GetRFReg(Adapter, ODM_RF_PATH_B, 0x25, bMaskDWord);
  8729. SYN_RF26 = ODM_GetRFReg(Adapter, ODM_RF_PATH_B, 0x26, bMaskDWord);
  8730. SYN_RF27 = ODM_GetRFReg(Adapter, ODM_RF_PATH_B, 0x27, bMaskDWord);
  8731. SYN_RF2B = ODM_GetRFReg(Adapter, ODM_RF_PATH_B, 0x2B, bMaskDWord);
  8732. SYN_RF2C = ODM_GetRFReg(Adapter, ODM_RF_PATH_B, 0x2C, bMaskDWord);
  8733. }
  8734. else // DualMAC_DualPHY 2G
  8735. {
  8736. SYN_RF25 = ODM_GetRFReg(Adapter, ODM_RF_PATH_A, 0x25, bMaskDWord);
  8737. SYN_RF26 = ODM_GetRFReg(Adapter, ODM_RF_PATH_A, 0x26, bMaskDWord);
  8738. SYN_RF27 = ODM_GetRFReg(Adapter, ODM_RF_PATH_A, 0x27, bMaskDWord);
  8739. SYN_RF2B = ODM_GetRFReg(Adapter, ODM_RF_PATH_A, 0x2B, bMaskDWord);
  8740. SYN_RF2C = ODM_GetRFReg(Adapter, ODM_RF_PATH_A, 0x2C, bMaskDWord);
  8741. }
  8742. }
  8743. */
  8744. //RXIQI = PHY_QueryBBReg(Adapter, 0xC14, bMaskDWord);
  8745. RXIQI = ODM_GetBBReg(pDM_Odm, 0xC14, bMaskDWord);
  8746. //RxIdleLowPwr = (PHY_QueryBBReg(Adapter, 0x818, bMaskDWord)&BIT28)>>28;
  8747. RxIdleLowPwr = (ODM_GetBBReg(pDM_Odm, 0x818, bMaskDWord)&BIT28)>>28;
  8748. //2???
  8749. if(CHNL_RUN_ABOVE_40MHZ(pMgntInfo))
  8750. Is40MHz = TRUE;
  8751. else
  8752. Is40MHz = FALSE;
  8753. ODM_RT_TRACE(pDM_Odm, ODM_COMP_PSD, DBG_LOUD,("PSD Scan Start\n"));
  8754. //1 Turn off CCK
  8755. //PHY_SetBBReg(Adapter, rFPGA0_RFMOD, BIT24, 0);
  8756. ODM_SetBBReg(pDM_Odm, rFPGA0_RFMOD, BIT24, 0);
  8757. //1 Turn off TX
  8758. //Pause TX Queue
  8759. //PlatformEFIOWrite1Byte(Adapter, REG_TXPAUSE, 0xFF);
  8760. ODM_Write1Byte(pDM_Odm,REG_TXPAUSE, 0xFF);
  8761. //Force RX to stop TX immediately
  8762. //PHY_SetRFReg(Adapter, ODM_RF_PATH_A, RF_AC, bRFRegOffsetMask, 0x32E13);
  8763. ODM_SetRFReg(pDM_Odm, ODM_RF_PATH_A, RF_AC, bRFRegOffsetMask, 0x32E13);
  8764. //1 Turn off RX
  8765. //Rx AGC off RegC70[0]=0, RegC7C[20]=0
  8766. //PHY_SetBBReg(Adapter, 0xC70, BIT0, 0);
  8767. //PHY_SetBBReg(Adapter, 0xC7C, BIT20, 0);
  8768. ODM_SetBBReg(pDM_Odm, 0xC70, BIT0, 0);
  8769. ODM_SetBBReg(pDM_Odm, 0xC7C, BIT20, 0);
  8770. //Turn off CCA
  8771. //PHY_SetBBReg(Adapter, 0xC14, bMaskDWord, 0x0);
  8772. ODM_SetBBReg(pDM_Odm, 0xC14, bMaskDWord, 0x0);
  8773. //BB Reset
  8774. //BBReset = PlatformEFIORead1Byte(Adapter, 0x02);
  8775. BBReset = ODM_Read1Byte(pDM_Odm, 0x02);
  8776. //PlatformEFIOWrite1Byte(Adapter, 0x02, BBReset&(~BIT0));
  8777. //PlatformEFIOWrite1Byte(Adapter, 0x02, BBReset|BIT0);
  8778. ODM_SetBBReg(pDM_Odm, 0x87C, BIT31, 1); //clock gated to prevent from AGC table mess
  8779. ODM_Write1Byte(pDM_Odm, 0x02, BBReset&(~BIT0));
  8780. ODM_Write1Byte(pDM_Odm, 0x02, BBReset|BIT0);
  8781. ODM_SetBBReg(pDM_Odm, 0x87C, BIT31, 0);
  8782. //1 Leave RX idle low power
  8783. //PHY_SetBBReg(Adapter, 0x818, BIT28, 0x0);
  8784. ODM_SetBBReg(pDM_Odm, 0x818, BIT28, 0x0);
  8785. //1 Fix initial gain
  8786. //if (IS_HARDWARE_TYPE_8723AE(Adapter))
  8787. //RSSI_BT = pHalData->RSSI_BT;
  8788. //else if((IS_HARDWARE_TYPE_8192C(Adapter))||(IS_HARDWARE_TYPE_8192D(Adapter))) // Add by Gary
  8789. // RSSI_BT = RSSI_BT_new;
  8790. if((pDM_Odm->SupportICType==ODM_RTL8723A)&(pDM_Odm->SupportInterface==ODM_ITRF_PCIE))
  8791. RSSI_BT=pDM_Odm->RSSI_BT; //need to check C2H to pDM_Odm RSSI BT
  8792. if(RSSI_BT>=47)
  8793. RSSI_BT=47;
  8794. ODM_RT_TRACE(pDM_Odm,ODM_COMP_PSD, DBG_LOUD,("PSD: RSSI_BT= %d\n", RSSI_BT));
  8795. if(pDM_Odm->SupportICType==ODM_RTL8723A)
  8796. {
  8797. //Neil add--2011--10--12
  8798. //2 Initial Gain index
  8799. if(RSSI_BT >=35) // >= -15dBm
  8800. initial_gain_psd = RSSI_BT*2;
  8801. else if((RSSI_BT >=33)&(RSSI_BT<35))
  8802. initial_gain_psd = RSSI_BT*2+6;
  8803. else if((RSSI_BT >=24)&(RSSI_BT<33))
  8804. initial_gain_psd = 70-(33-RSSI_BT);
  8805. else if((RSSI_BT >=19)&(RSSI_BT<24))
  8806. initial_gain_psd = 64-((24-RSSI_BT)*4);
  8807. else if((RSSI_BT >=14)&(RSSI_BT<19))
  8808. initial_gain_psd = 44-((18-RSSI_BT)*2);
  8809. else if((RSSI_BT >=8)&(RSSI_BT<14))
  8810. initial_gain_psd = 35-(14-RSSI_BT);
  8811. else
  8812. initial_gain_psd = 0x1B;
  8813. }
  8814. else
  8815. {
  8816. //need to do
  8817. initial_gain_psd = pDM_Odm->RSSI_Min; // PSD report based on RSSI
  8818. //}
  8819. }
  8820. //if(RSSI_BT<0x17)
  8821. // RSSI_BT +=3;
  8822. //DbgPrint("PSD: RSSI_BT= %d\n", RSSI_BT);
  8823. ODM_RT_TRACE(pDM_Odm,ODM_COMP_PSD, DBG_LOUD,("PSD: RSSI_BT= %d\n", RSSI_BT));
  8824. //initialGainUpper = 0x5E; //Modify by neil chen
  8825. if(pDM_Odm->bUserAssignLevel)
  8826. {
  8827. pDM_Odm->bUserAssignLevel = FALSE;
  8828. initialGainUpper = 0x7f;
  8829. }
  8830. else
  8831. {
  8832. initialGainUpper = 0x5E;
  8833. }
  8834. /*
  8835. if (initial_gain_psd < 0x1a)
  8836. initial_gain_psd = 0x1a;
  8837. if (initial_gain_psd > initialGainUpper)
  8838. initial_gain_psd = initialGainUpper;
  8839. */
  8840. //if(pDM_Odm->SupportICType==ODM_RTL8723A)
  8841. SSBT = RSSI_BT * 2 +0x3E;
  8842. //if(IS_HARDWARE_TYPE_8723AE(Adapter))
  8843. // SSBT = RSSI_BT * 2 +0x3E;
  8844. //else if((IS_HARDWARE_TYPE_8192C(Adapter))||(IS_HARDWARE_TYPE_8192D(Adapter))) // Add by Gary
  8845. //{
  8846. // RSSI_BT = initial_gain_psd;
  8847. // SSBT = RSSI_BT;
  8848. //}
  8849. ODM_RT_TRACE(pDM_Odm,ODM_COMP_PSD, DBG_LOUD,("PSD: SSBT= %d\n", SSBT));
  8850. ODM_RT_TRACE( pDM_Odm,ODM_COMP_PSD, DBG_LOUD,("PSD: initial gain= 0x%x\n", initial_gain_psd));
  8851. //DbgPrint("PSD: SSBT= %d", SSBT);
  8852. //need to do
  8853. //pMgntInfo->bDMInitialGainEnable = FALSE;
  8854. pDM_Odm->bDMInitialGainEnable = FALSE;
  8855. initial_gain =(u1Byte) (ODM_GetBBReg(pDM_Odm, 0xc50, bMaskDWord) & 0x7F);
  8856. // make sure the initial gain is under the correct range.
  8857. //initial_gain_psd &= 0x7f;
  8858. ODM_Write_DIG(pDM_Odm, initial_gain_psd);
  8859. //1 Turn off 3-wire
  8860. ODM_SetBBReg(pDM_Odm, 0x88c, BIT20|BIT21|BIT22|BIT23, 0xF);
  8861. //pts value = 128, 256, 512, 1024
  8862. pts = 128;
  8863. if(pts == 128)
  8864. {
  8865. ODM_SetBBReg(pDM_Odm, 0x808, BIT14|BIT15, 0x0);
  8866. start_point = 64;
  8867. stop_point = 192;
  8868. }
  8869. else if(pts == 256)
  8870. {
  8871. ODM_SetBBReg(pDM_Odm, 0x808, BIT14|BIT15, 0x1);
  8872. start_point = 128;
  8873. stop_point = 384;
  8874. }
  8875. else if(pts == 512)
  8876. {
  8877. ODM_SetBBReg(pDM_Odm, 0x808, BIT14|BIT15, 0x2);
  8878. start_point = 256;
  8879. stop_point = 768;
  8880. }
  8881. else
  8882. {
  8883. ODM_SetBBReg(pDM_Odm, 0x808, BIT14|BIT15, 0x3);
  8884. start_point = 512;
  8885. stop_point = 1536;
  8886. }
  8887. //3 Skip WLAN channels if WLAN busy
  8888. curTxOkCnt = *(pDM_Odm->pNumTxBytesUnicast) - lastTxOkCnt;
  8889. curRxOkCnt = *(pDM_Odm->pNumRxBytesUnicast) - lastRxOkCnt;
  8890. lastTxOkCnt = *(pDM_Odm->pNumTxBytesUnicast);
  8891. lastRxOkCnt = *(pDM_Odm->pNumRxBytesUnicast);
  8892. PSD_skip_start=80;
  8893. PSD_skip_stop = 0;
  8894. wlan_channel = CurrentChannel & 0x0f;
  8895. ODM_RT_TRACE(pDM_Odm,ODM_COMP_PSD,DBG_LOUD,("PSD: current channel: %x, BW:%d \n", wlan_channel, Is40MHz));
  8896. if(pDM_Odm->SupportICType==ODM_RTL8723A)
  8897. {
  8898. if(pDM_Odm->bBtHsOperation)
  8899. {
  8900. if(pDM_Odm->bLinked)
  8901. {
  8902. if(Is40MHz)
  8903. {
  8904. PSD_skip_start = ((wlan_channel-1)*5 -Is40MHz*10)-2; // Modify by Neil to add 10 chs to mask
  8905. PSD_skip_stop = (PSD_skip_start + (1+Is40MHz)*20)+4;
  8906. }
  8907. else
  8908. {
  8909. PSD_skip_start = ((wlan_channel-1)*5 -Is40MHz*10)-10; // Modify by Neil to add 10 chs to mask
  8910. PSD_skip_stop = (PSD_skip_start + (1+Is40MHz)*20)+18;
  8911. }
  8912. }
  8913. else
  8914. {
  8915. // mask for 40MHz
  8916. PSD_skip_start = ((wlan_channel-1)*5 -Is40MHz*10)-2; // Modify by Neil to add 10 chs to mask
  8917. PSD_skip_stop = (PSD_skip_start + (1+Is40MHz)*20)+4;
  8918. }
  8919. if(PSD_skip_start < 0)
  8920. PSD_skip_start = 0;
  8921. if(PSD_skip_stop >80)
  8922. PSD_skip_stop = 80;
  8923. }
  8924. else
  8925. {
  8926. if((curRxOkCnt+curTxOkCnt) > 5)
  8927. {
  8928. if(Is40MHz)
  8929. {
  8930. PSD_skip_start = ((wlan_channel-1)*5 -Is40MHz*10)-2; // Modify by Neil to add 10 chs to mask
  8931. PSD_skip_stop = (PSD_skip_start + (1+Is40MHz)*20)+4;
  8932. }
  8933. else
  8934. {
  8935. PSD_skip_start = ((wlan_channel-1)*5 -Is40MHz*10)-10; // Modify by Neil to add 10 chs to mask
  8936. PSD_skip_stop = (PSD_skip_start + (1+Is40MHz)*20)+18;
  8937. }
  8938. if(PSD_skip_start < 0)
  8939. PSD_skip_start = 0;
  8940. if(PSD_skip_stop >80)
  8941. PSD_skip_stop = 80;
  8942. }
  8943. }
  8944. }
  8945. #if 0
  8946. else
  8947. {
  8948. if((curRxOkCnt+curTxOkCnt) > 1000)
  8949. {
  8950. PSD_skip_start = (wlan_channel-1)*5 -Is40MHz*10;
  8951. PSD_skip_stop = PSD_skip_start + (1+Is40MHz)*20;
  8952. }
  8953. }
  8954. #endif //Reove RXHP Issue
  8955. ODM_RT_TRACE(pDM_Odm,ODM_COMP_PSD,DBG_LOUD,("PSD: Skip tone from %d to %d \n", PSD_skip_start, PSD_skip_stop));
  8956. for (n=0;n<80;n++)
  8957. {
  8958. if((n%20)==0)
  8959. {
  8960. channel = (n/20)*4 + 1;
  8961. ODM_SetRFReg(pDM_Odm, ODM_RF_PATH_A, RF_CHNLBW, 0x3FF, channel);
  8962. }
  8963. tone_idx = n%20;
  8964. if ((n>=PSD_skip_start) && (n<PSD_skip_stop))
  8965. {
  8966. PSD_report[n] = SSBT;
  8967. ODM_RT_TRACE(pDM_Odm,ODM_COMP_PSD,DBG_LOUD,("PSD:Tone %d skipped \n", n));
  8968. }
  8969. else
  8970. {
  8971. PSD_report_tmp = GetPSDData(pDM_Odm, idx[tone_idx], initial_gain_psd);
  8972. if ( PSD_report_tmp > PSD_report[n])
  8973. PSD_report[n] = PSD_report_tmp;
  8974. }
  8975. }
  8976. PatchDCTone(pDM_Odm, PSD_report, initial_gain_psd);
  8977. //----end
  8978. //1 Turn on RX
  8979. //Rx AGC on
  8980. ODM_SetBBReg(pDM_Odm, 0xC70, BIT0, 1);
  8981. ODM_SetBBReg(pDM_Odm, 0xC7C, BIT20, 1);
  8982. //CCK on
  8983. ODM_SetBBReg(pDM_Odm, rFPGA0_RFMOD, BIT24, 1);
  8984. //1 Turn on TX
  8985. //Resume TX Queue
  8986. ODM_Write1Byte(pDM_Odm,REG_TXPAUSE, 0x00);
  8987. //Turn on 3-wire
  8988. ODM_SetBBReg(pDM_Odm, 0x88c, BIT20|BIT21|BIT22|BIT23, 0x0);
  8989. //1 Restore Current Settings
  8990. //Resume DIG
  8991. pDM_Odm->bDMInitialGainEnable = TRUE;
  8992. ODM_Write_DIG(pDM_Odm, initial_gain);
  8993. // restore originl center frequency
  8994. ODM_SetRFReg(pDM_Odm, ODM_RF_PATH_A, RF_CHNLBW, bRFRegOffsetMask, CurrentChannel);
  8995. //Turn on CCA
  8996. ODM_SetBBReg(pDM_Odm, 0xC14, bMaskDWord, RXIQI);
  8997. //Restore RX idle low power
  8998. if(RxIdleLowPwr == TRUE)
  8999. ODM_SetBBReg(pDM_Odm, 0x818, BIT28, 1);
  9000. psd_cnt++;
  9001. ODM_RT_TRACE(pDM_Odm,ODM_COMP_PSD, DBG_LOUD,("PSD:psd_cnt = %d \n",psd_cnt));
  9002. if (psd_cnt < ReScan)
  9003. ODM_SetTimer(pDM_Odm, &pDM_Odm->PSDTimer, Interval);
  9004. else
  9005. {
  9006. psd_cnt = 0;
  9007. for(i=0;i<80;i++)
  9008. //DbgPrint("psd_report[%d]= %d \n", 2402+i, PSD_report[i]);
  9009. RT_TRACE( COMP_PSD, DBG_LOUD,("psd_report[%d]= %d \n", 2402+i, PSD_report[i]));
  9010. GoodChannelDecision(pDM_Odm, PSD_report, PSD_bitmap,RSSI_BT, PSD_bitmap_memory);
  9011. if(pDM_Odm->SupportICType==ODM_RTL8723A)
  9012. {
  9013. cur_byte_idx=0;
  9014. cur_bit_idx=0;
  9015. //2 Restore H2C PSD Data to Last Data
  9016. H2C_PSD_DATA_last[0] = H2C_PSD_DATA[0];
  9017. H2C_PSD_DATA_last[1] = H2C_PSD_DATA[1];
  9018. H2C_PSD_DATA_last[2] = H2C_PSD_DATA[2];
  9019. H2C_PSD_DATA_last[3] = H2C_PSD_DATA[3];
  9020. H2C_PSD_DATA_last[4] = H2C_PSD_DATA[4];
  9021. //2 Translate 80bit channel map to 40bit channel
  9022. for ( i=0;i<5;i++)
  9023. {
  9024. for(n=0;n<8;n++)
  9025. {
  9026. cur_byte_idx = i*2 + n/4;
  9027. cur_bit_idx = (n%4)*2;
  9028. if ( ((PSD_bitmap[cur_byte_idx]& BIT(cur_bit_idx)) != 0) && ((PSD_bitmap[cur_byte_idx]& BIT(cur_bit_idx+1)) != 0))
  9029. H2C_PSD_DATA[i] = H2C_PSD_DATA[i] | (u1Byte) (1 << n);
  9030. }
  9031. ODM_RT_TRACE(pDM_Odm,ODM_COMP_PSD, DBG_LOUD,("H2C_PSD_DATA[%d]=0x%x\n" ,i, H2C_PSD_DATA[i]));
  9032. }
  9033. //3 To Compare the difference
  9034. for ( i=0;i<5;i++)
  9035. {
  9036. if(H2C_PSD_DATA[i] !=H2C_PSD_DATA_last[i])
  9037. {
  9038. FillH2CCmd(Adapter, H2C_92C_PSD_RESULT, 5, H2C_PSD_DATA);
  9039. ODM_RT_TRACE(pDM_Odm, ODM_COMP_PSD, DBG_LOUD,("Need to Update the AFH Map \n"));
  9040. break;
  9041. }
  9042. else
  9043. {
  9044. if(i==5)
  9045. ODM_RT_TRACE(pDM_Odm,ODM_COMP_PSD, DBG_LOUD,("Not need to Update\n"));
  9046. }
  9047. }
  9048. //pHalData->bPSDactive=FALSE;
  9049. if(pDM_Odm->bBtHsOperation)
  9050. {
  9051. ODM_SetTimer(pDM_Odm, &pDM_Odm->PSDTimer, 10000);
  9052. ODM_RT_TRACE( pDM_Odm,ODM_COMP_PSD, DBG_LOUD,("Leave dm_PSD_Monitor\n"));
  9053. }
  9054. else
  9055. {
  9056. ODM_SetTimer(pDM_Odm, &pDM_Odm->PSDTimer, 1500);
  9057. ODM_RT_TRACE( pDM_Odm,ODM_COMP_PSD, DBG_LOUD,("Leave dm_PSD_Monitor\n"));
  9058. }
  9059. }
  9060. }
  9061. }
  9062. /*
  9063. //Neil for Get BT RSSI
  9064. // Be Triggered by BT C2H CMD
  9065. VOID
  9066. ODM_PSDGetRSSI(
  9067. IN u1Byte RSSI_BT)
  9068. {
  9069. }
  9070. */
  9071. VOID
  9072. ODM_PSDMonitor(
  9073. IN PDM_ODM_T pDM_Odm
  9074. )
  9075. {
  9076. //HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  9077. //if(IS_HARDWARE_TYPE_8723AE(Adapter))
  9078. if(pDM_Odm->SupportICType == ODM_RTL8723A) //may need to add other IC type
  9079. {
  9080. if(pDM_Odm->SupportInterface==ODM_ITRF_PCIE)
  9081. {
  9082. if(pDM_Odm->bBtDisabled) //need to check upper layer connection
  9083. {
  9084. pDM_Odm->bPSDactive=FALSE;
  9085. ODM_RT_TRACE(pDM_Odm,ODM_COMP_PSD, DBG_LOUD, ("odm_PSDMonitor, return for BT is disabled!!!\n"));
  9086. return;
  9087. }
  9088. ODM_RT_TRACE(pDM_Odm,ODM_COMP_PSD, DBG_LOUD, ("odm_PSDMonitor\n"));
  9089. //if(pHalData->bPSDactive ==FALSE)
  9090. //{
  9091. pDM_Odm->bPSDinProcess = TRUE;
  9092. //pHalData->bPSDactive=TRUE;
  9093. pDM_Odm->bPSDactive=TRUE;
  9094. odm_PSD_Monitor(pDM_Odm);
  9095. pDM_Odm->bPSDinProcess = FALSE;
  9096. }
  9097. }
  9098. }
  9099. VOID
  9100. odm_PSDMonitorCallback(
  9101. PRT_TIMER pTimer
  9102. )
  9103. {
  9104. PADAPTER Adapter = (PADAPTER)pTimer->Adapter;
  9105. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  9106. PlatformScheduleWorkItem(&pHalData->PSDMonitorWorkitem);
  9107. }
  9108. VOID
  9109. odm_PSDMonitorWorkItemCallback(
  9110. IN PVOID pContext
  9111. )
  9112. {
  9113. PADAPTER Adapter = (PADAPTER)pContext;
  9114. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  9115. PDM_ODM_T pDM_Odm = &pHalData->DM_OutSrc;
  9116. ODM_PSDMonitor(pDM_Odm);
  9117. }
  9118. // <20130108, Kordan> E.g., With LNA used, we make the Rx power smaller to have a better EVM. (Asked by Willis)
  9119. VOID
  9120. odm_RFEControl(
  9121. IN PDM_ODM_T pDM_Odm,
  9122. IN u8Byte RSSIVal
  9123. )
  9124. {
  9125. PADAPTER Adapter = (PADAPTER)pDM_Odm->Adapter;
  9126. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  9127. static u1Byte TRSW_HighPwr = 0;
  9128. ODM_RT_TRACE(pDM_Odm, ODM_COMP_DIG, DBG_LOUD, ("===> odm_RFEControl, RSSI = %d, TRSW_HighPwr = 0x%X, pHalData->RFEType = %d\n",
  9129. RSSIVal, TRSW_HighPwr, pHalData->RFEType ));
  9130. if (pHalData->RFEType == 3) {
  9131. pDM_Odm->RSSI_TRSW = RSSIVal;
  9132. if (pDM_Odm->RSSI_TRSW >= pDM_Odm->RSSI_TRSW_H)
  9133. {
  9134. TRSW_HighPwr = 1; // Switch to
  9135. PHY_SetBBReg(Adapter, r_ANTSEL_SW_Jaguar, BIT1|BIT0, 0x1); // Set ANTSW=1/ANTSWB=0 for SW control
  9136. PHY_SetBBReg(Adapter, r_ANTSEL_SW_Jaguar, BIT9|BIT8, 0x3); // Set ANTSW=1/ANTSWB=0 for SW control
  9137. }
  9138. else if (pDM_Odm->RSSI_TRSW <= pDM_Odm->RSSI_TRSW_L)
  9139. {
  9140. TRSW_HighPwr = 0; // Switched back
  9141. PHY_SetBBReg(Adapter, r_ANTSEL_SW_Jaguar, BIT1|BIT0, 0x1); // Set ANTSW=1/ANTSWB=0 for SW control
  9142. PHY_SetBBReg(Adapter, r_ANTSEL_SW_Jaguar, BIT9|BIT8, 0x0); // Set ANTSW=1/ANTSWB=0 for SW control
  9143. }
  9144. }
  9145. ODM_RT_TRACE(pDM_Odm, ODM_COMP_DIG, DBG_LOUD, ("(pDM_Odm->RSSI_TRSW_H, pDM_Odm->RSSI_TRSW_L) = (%d, %d)\n", pDM_Odm->RSSI_TRSW_H, pDM_Odm->RSSI_TRSW_L));
  9146. ODM_RT_TRACE(pDM_Odm, ODM_COMP_DIG, DBG_LOUD, ("(RSSIVal, RSSIVal, pDM_Odm->RSSI_TRSW_iso) = (%d, %d, %d)\n",
  9147. RSSIVal, pDM_Odm->RSSI_TRSW_iso, pDM_Odm->RSSI_TRSW));
  9148. ODM_RT_TRACE(pDM_Odm, ODM_COMP_DIG, DBG_LOUD, ("<=== odm_RFEControl, RSSI = %d, TRSW_HighPwr = 0x%X\n", RSSIVal, TRSW_HighPwr));
  9149. }
  9150. VOID
  9151. ODM_MPT_DIG(
  9152. IN PDM_ODM_T pDM_Odm
  9153. )
  9154. {
  9155. pDIG_T pDM_DigTable = &pDM_Odm->DM_DigTable;
  9156. PFALSE_ALARM_STATISTICS pFalseAlmCnt = &pDM_Odm->FalseAlmCnt;
  9157. u1Byte CurrentIGI = (u1Byte)pDM_DigTable->CurIGValue;
  9158. u1Byte DIG_Upper = 0x40, DIG_Lower = 0x20, C50, E50;
  9159. u8Byte RXOK_cal;
  9160. u1Byte IGI_A = 0x20, IGI_B = 0x20;
  9161. #if ODM_FIX_2G_DIG
  9162. IGI_A = 0x22;
  9163. IGI_B = 0x24;
  9164. #endif
  9165. ODM_RT_TRACE(pDM_Odm,ODM_COMP_MP, DBG_LOUD, ("===> ODM_MPT_DIG, pBandType = %d\n", *pDM_Odm->pBandType));
  9166. odm_FalseAlarmCounterStatistics( pDM_Odm);
  9167. pDM_Odm->LastNumQryPhyStatusAll = pDM_Odm->NumQryPhyStatusAll;
  9168. pDM_Odm->NumQryPhyStatusAll = pDM_Odm->PhyDbgInfo.NumQryPhyStatusCCK + pDM_Odm->PhyDbgInfo.NumQryPhyStatusOFDM;
  9169. RXOK_cal = pDM_Odm->NumQryPhyStatusAll - pDM_Odm->LastNumQryPhyStatusAll;
  9170. if (RXOK_cal == 0)
  9171. pDM_Odm->RxPWDBAve_final= 0;
  9172. else
  9173. pDM_Odm->RxPWDBAve_final= pDM_Odm->RxPWDBAve/RXOK_cal;
  9174. pDM_Odm->RxPWDBAve = 0;
  9175. ODM_RT_TRACE(pDM_Odm,ODM_COMP_DIG, DBG_LOUD, ("RX OK = %d\n", RXOK_cal));
  9176. ODM_RT_TRACE(pDM_Odm,ODM_COMP_DIG, DBG_LOUD, ("pDM_Odm->RxPWDBAve_final = %d\n", pDM_Odm->RxPWDBAve_final));
  9177. // <20130315, Kordan> Except Cameo, we should always trun on 2.4G/5G DIG.
  9178. // (Cameo fixes the IGI of 2.4G, so only DIG on 5G. Asked by James.)
  9179. #if ODM_FIX_2G_DIG
  9180. if (*pDM_Odm->pBandType == BAND_ON_5G){ // for 5G
  9181. #else
  9182. if (1){ // for both 2G/5G
  9183. #endif
  9184. pDM_Odm->MPDIG_2G = FALSE;
  9185. pDM_Odm->Times_2G = 0;
  9186. if (RXOK_cal >= 70 && pDM_Odm->RxPWDBAve_final<= 30)
  9187. {
  9188. if (CurrentIGI > 0x24){
  9189. ODM_Write1Byte( pDM_Odm, rA_IGI_Jaguar, 0x24);
  9190. ODM_Write1Byte( pDM_Odm, rB_IGI_Jaguar, 0x24);
  9191. }
  9192. }
  9193. else
  9194. {
  9195. if(pFalseAlmCnt->Cnt_all > 1000){
  9196. CurrentIGI = CurrentIGI + 8;
  9197. }
  9198. else if(pFalseAlmCnt->Cnt_all > 200){
  9199. CurrentIGI = CurrentIGI + 4;
  9200. }
  9201. else if (pFalseAlmCnt->Cnt_all > 50){
  9202. CurrentIGI = CurrentIGI + 2;
  9203. }
  9204. else if (pFalseAlmCnt->Cnt_all < 2){
  9205. CurrentIGI = CurrentIGI - 2;
  9206. }
  9207. if (CurrentIGI < DIG_Lower ){
  9208. CurrentIGI = DIG_Lower;
  9209. }
  9210. else if(CurrentIGI > DIG_Upper){
  9211. CurrentIGI = DIG_Upper;
  9212. }
  9213. pDM_DigTable->CurIGValue = CurrentIGI;
  9214. ODM_Write1Byte( pDM_Odm, rA_IGI_Jaguar, (u1Byte)CurrentIGI);
  9215. ODM_Write1Byte( pDM_Odm, rB_IGI_Jaguar, (u1Byte)CurrentIGI);
  9216. C50 = ODM_Read1Byte( pDM_Odm, 0xc50);
  9217. E50 = ODM_Read1Byte( pDM_Odm, 0xe50);
  9218. //pDM_Odm->MPDIG_2G = FALSE;
  9219. ODM_RT_TRACE(pDM_Odm,ODM_COMP_MP, DBG_LOUD, ("DIG = (%x, %x), Cnt_all = %d, Cnt_Ofdm_fail = %d, Cnt_Cck_fail = %d\n", C50, E50, pFalseAlmCnt->Cnt_all, pFalseAlmCnt->Cnt_Ofdm_fail, pFalseAlmCnt->Cnt_Cck_fail));
  9220. }
  9221. }
  9222. else
  9223. { //2G
  9224. ODM_RT_TRACE(pDM_Odm,ODM_COMP_MP, DBG_LOUD, ("MPDIG_2G = %d,\n", pDM_Odm->MPDIG_2G));
  9225. if(pDM_Odm->MPDIG_2G == FALSE){
  9226. ODM_RT_TRACE(pDM_Odm,ODM_COMP_MP, DBG_LOUD, ("===> Fix IGI\n"));
  9227. ODM_Write1Byte( pDM_Odm, rA_IGI_Jaguar, (u1Byte)IGI_A);
  9228. ODM_Write1Byte( pDM_Odm, rB_IGI_Jaguar, (u1Byte)IGI_B);
  9229. }
  9230. if (pDM_Odm->Times_2G == 2)
  9231. pDM_Odm->MPDIG_2G = TRUE;
  9232. pDM_Odm->Times_2G++;
  9233. }
  9234. ODM_RT_TRACE(pDM_Odm,ODM_COMP_DIG, DBG_LOUD, ("pDM_Odm->RxPWDBAve_final = %d\n", pDM_Odm->RxPWDBAve_final));
  9235. if (pDM_Odm->SupportICType == ODM_RTL8812)
  9236. odm_RFEControl(pDM_Odm, pDM_Odm->RxPWDBAve_final);
  9237. ODM_SetTimer(pDM_Odm, &pDM_Odm->MPT_DIGTimer, 700);
  9238. }
  9239. VOID
  9240. odm_MPT_DIGCallback(
  9241. PRT_TIMER pTimer
  9242. )
  9243. {
  9244. PADAPTER Adapter = (PADAPTER)pTimer->Adapter;
  9245. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  9246. PDM_ODM_T pDM_Odm = &pHalData->DM_OutSrc;
  9247. #if DEV_BUS_TYPE==RT_PCI_INTERFACE
  9248. #if USE_WORKITEM
  9249. PlatformScheduleWorkItem(&pDM_Odm->MPT_DIGWorkitem);
  9250. #else
  9251. ODM_MPT_DIG(pDM_Odm);
  9252. #endif
  9253. #else
  9254. PlatformScheduleWorkItem(&pDM_Odm->MPT_DIGWorkitem);
  9255. #endif
  9256. }
  9257. VOID
  9258. odm_MPT_DIGWorkItemCallback(
  9259. IN PVOID pContext
  9260. )
  9261. {
  9262. PADAPTER Adapter = (PADAPTER)pContext;
  9263. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  9264. PDM_ODM_T pDM_Odm = &pHalData->DM_OutSrc;
  9265. ODM_MPT_DIG(pDM_Odm);
  9266. }
  9267. //cosa debug tool need to modify
  9268. VOID
  9269. ODM_PSDDbgControl(
  9270. IN PADAPTER Adapter,
  9271. IN u4Byte mode,
  9272. IN u4Byte btRssi
  9273. )
  9274. {
  9275. #if (DEV_BUS_TYPE == RT_PCI_INTERFACE)
  9276. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  9277. PDM_ODM_T pDM_Odm = &pHalData->DM_OutSrc;
  9278. ODM_RT_TRACE(pDM_Odm,COMP_PSD, DBG_LOUD, (" Monitor mode=%d, btRssi=%d\n", mode, btRssi));
  9279. if(mode)
  9280. {
  9281. pDM_Odm->RSSI_BT = (u1Byte)btRssi;
  9282. pDM_Odm->bUserAssignLevel = TRUE;
  9283. ODM_SetTimer( pDM_Odm, &pDM_Odm->PSDTimer, 0); //ms
  9284. }
  9285. else
  9286. {
  9287. ODM_CancelTimer(pDM_Odm, &pDM_Odm->PSDTimer);
  9288. }
  9289. #endif
  9290. }
  9291. //#if(DEV_BUS_TYPE == RT_PCI_INTERFACE)|(DEV_BUS_TYPE == RT_USB_INTERFACE)
  9292. void odm_RXHPInit(
  9293. IN PDM_ODM_T pDM_Odm)
  9294. {
  9295. #if (DEV_BUS_TYPE == RT_PCI_INTERFACE)|(DEV_BUS_TYPE == RT_USB_INTERFACE)
  9296. pRXHP_T pRX_HP_Table = &pDM_Odm->DM_RXHP_Table;
  9297. u1Byte index;
  9298. pRX_HP_Table->RXHP_enable = TRUE;
  9299. pRX_HP_Table->RXHP_flag = 0;
  9300. pRX_HP_Table->PSD_func_trigger = 0;
  9301. pRX_HP_Table->Pre_IGI = 0x20;
  9302. pRX_HP_Table->Cur_IGI = 0x20;
  9303. pRX_HP_Table->Cur_pw_th = pw_th_10dB;
  9304. pRX_HP_Table->Pre_pw_th = pw_th_10dB;
  9305. for(index=0; index<80; index++)
  9306. pRX_HP_Table->PSD_bitmap_RXHP[index] = 1;
  9307. #if(DEV_BUS_TYPE == RT_USB_INTERFACE)
  9308. pRX_HP_Table->TP_Mode = Idle_Mode;
  9309. #endif
  9310. #endif
  9311. }
  9312. void odm_RXHP(
  9313. IN PDM_ODM_T pDM_Odm)
  9314. {
  9315. #if( DM_ODM_SUPPORT_TYPE & (ODM_WIN))
  9316. #if (DEV_BUS_TYPE == RT_PCI_INTERFACE) | (DEV_BUS_TYPE == RT_USB_INTERFACE)
  9317. PADAPTER Adapter = pDM_Odm->Adapter;
  9318. PMGNT_INFO pMgntInfo = &(Adapter->MgntInfo);
  9319. pDIG_T pDM_DigTable = &pDM_Odm->DM_DigTable;
  9320. pRXHP_T pRX_HP_Table = &pDM_Odm->DM_RXHP_Table;
  9321. PFALSE_ALARM_STATISTICS FalseAlmCnt = &(pDM_Odm->FalseAlmCnt);
  9322. u1Byte i, j, sum;
  9323. u1Byte Is40MHz;
  9324. s1Byte Intf_diff_idx, MIN_Intf_diff_idx = 16;
  9325. s4Byte cur_channel;
  9326. u1Byte ch_map_intf_5M[17] = {0};
  9327. static u4Byte FA_TH = 0;
  9328. static u1Byte psd_intf_flag = 0;
  9329. static s4Byte curRssi = 0;
  9330. static s4Byte preRssi = 0;
  9331. static u1Byte PSDTriggerCnt = 1;
  9332. u1Byte RX_HP_enable = (u1Byte)(ODM_GetBBReg(pDM_Odm, rOFDM0_XAAGCCore2, bMaskDWord)>>31); // for debug!!
  9333. #if(DEV_BUS_TYPE == RT_USB_INTERFACE)
  9334. static s8Byte lastTxOkCnt = 0, lastRxOkCnt = 0;
  9335. s8Byte curTxOkCnt, curRxOkCnt;
  9336. s8Byte curTPOkCnt;
  9337. s8Byte TP_Acc3, TP_Acc5;
  9338. static s8Byte TP_Buff[5] = {0};
  9339. static u1Byte pre_state = 0, pre_state_flag = 0;
  9340. static u1Byte Intf_HighTP_flag = 0, De_counter = 16;
  9341. static u1Byte TP_Degrade_flag = 0;
  9342. #endif
  9343. static u1Byte LatchCnt = 0;
  9344. if(pDM_Odm->SupportICType & (ODM_RTL8723A|ODM_RTL8188E))
  9345. return;
  9346. //AGC RX High Power Mode is only applied on 2G band in 92D!!!
  9347. if(pDM_Odm->SupportICType == ODM_RTL8192D)
  9348. {
  9349. if(*(pDM_Odm->pBandType) != ODM_BAND_2_4G)
  9350. return;
  9351. }
  9352. if(!(pDM_Odm->SupportAbility==ODM_BB_RXHP))
  9353. return;
  9354. //RX HP ON/OFF
  9355. if(RX_HP_enable == 1)
  9356. pRX_HP_Table->RXHP_enable = FALSE;
  9357. else
  9358. pRX_HP_Table->RXHP_enable = TRUE;
  9359. if(pRX_HP_Table->RXHP_enable == FALSE)
  9360. {
  9361. if(pRX_HP_Table->RXHP_flag == 1)
  9362. {
  9363. pRX_HP_Table->RXHP_flag = 0;
  9364. psd_intf_flag = 0;
  9365. }
  9366. return;
  9367. }
  9368. #if(DEV_BUS_TYPE == RT_USB_INTERFACE)
  9369. //2 Record current TP for USB interface
  9370. curTxOkCnt = *(pDM_Odm->pNumTxBytesUnicast)-lastTxOkCnt;
  9371. curRxOkCnt = *(pDM_Odm->pNumRxBytesUnicast)-lastRxOkCnt;
  9372. lastTxOkCnt = *(pDM_Odm->pNumTxBytesUnicast);
  9373. lastRxOkCnt = *(pDM_Odm->pNumRxBytesUnicast);
  9374. curTPOkCnt = curTxOkCnt+curRxOkCnt;
  9375. TP_Buff[0] = curTPOkCnt; // current TP
  9376. TP_Acc3 = PlatformDivision64((TP_Buff[1]+TP_Buff[2]+TP_Buff[3]), 3);
  9377. TP_Acc5 = PlatformDivision64((TP_Buff[0]+TP_Buff[1]+TP_Buff[2]+TP_Buff[3]+TP_Buff[4]), 5);
  9378. if(TP_Acc5 < 1000)
  9379. pRX_HP_Table->TP_Mode = Idle_Mode;
  9380. else if((1000 < TP_Acc5)&&(TP_Acc5 < 3750000))
  9381. pRX_HP_Table->TP_Mode = Low_TP_Mode;
  9382. else
  9383. pRX_HP_Table->TP_Mode = High_TP_Mode;
  9384. ODM_RT_TRACE(pDM_Odm, ODM_COMP_RXHP, ODM_DBG_LOUD, ("RX HP TP Mode = %d\n", pRX_HP_Table->TP_Mode));
  9385. // Since TP result would be sampled every 2 sec, it needs to delay 4sec to wait PSD processing.
  9386. // When LatchCnt = 0, we would Get PSD result.
  9387. if(TP_Degrade_flag == 1)
  9388. {
  9389. LatchCnt--;
  9390. if(LatchCnt == 0)
  9391. {
  9392. TP_Degrade_flag = 0;
  9393. }
  9394. }
  9395. // When PSD function triggered by TP degrade 20%, and Interference Flag = 1
  9396. // Set a De_counter to wait IGI = upper bound. If time is UP, the Interference flag will be pull down.
  9397. if(Intf_HighTP_flag == 1)
  9398. {
  9399. De_counter--;
  9400. if(De_counter == 0)
  9401. {
  9402. Intf_HighTP_flag = 0;
  9403. psd_intf_flag = 0;
  9404. }
  9405. }
  9406. #endif
  9407. //2 AGC RX High Power Mode by PSD only applied to STA Mode
  9408. //3 NOT applied 1. Ad Hoc Mode.
  9409. //3 NOT applied 2. AP Mode
  9410. if ((pMgntInfo->mAssoc) && (!pMgntInfo->mIbss) && (!ACTING_AS_AP(Adapter)))
  9411. {
  9412. Is40MHz = *(pDM_Odm->pBandWidth);
  9413. curRssi = pDM_Odm->RSSI_Min;
  9414. cur_channel = ODM_GetRFReg(pDM_Odm, ODM_RF_PATH_A, RF_CHNLBW, 0x0fff) & 0x0f;
  9415. ODM_RT_TRACE(pDM_Odm, ODM_COMP_RXHP, ODM_DBG_LOUD, ("RXHP RX HP flag = %d\n", pRX_HP_Table->RXHP_flag));
  9416. ODM_RT_TRACE(pDM_Odm, ODM_COMP_RXHP, ODM_DBG_LOUD, ("RXHP FA = %d\n", FalseAlmCnt->Cnt_all));
  9417. ODM_RT_TRACE(pDM_Odm, ODM_COMP_RXHP, ODM_DBG_LOUD, ("RXHP cur RSSI = %d, pre RSSI=%d\n", curRssi, preRssi));
  9418. ODM_RT_TRACE(pDM_Odm, ODM_COMP_RXHP, ODM_DBG_LOUD, ("RXHP current CH = %d\n", cur_channel));
  9419. ODM_RT_TRACE(pDM_Odm, ODM_COMP_RXHP, ODM_DBG_LOUD, ("RXHP Is 40MHz = %d\n", Is40MHz));
  9420. //2 PSD function would be triggered
  9421. //3 1. Every 4 sec for PCIE
  9422. //3 2. Before TP Mode (Idle TP<4kbps) for USB
  9423. //3 3. After TP Mode (High TP) for USB
  9424. if((curRssi > 68) && (pRX_HP_Table->RXHP_flag == 0)) // Only RSSI>TH and RX_HP_flag=0 will Do PSD process
  9425. {
  9426. #if (DEV_BUS_TYPE == RT_USB_INTERFACE)
  9427. //2 Before TP Mode ==> PSD would be trigger every 4 sec
  9428. if(pRX_HP_Table->TP_Mode == Idle_Mode) //2.1 less wlan traffic <4kbps
  9429. {
  9430. #endif
  9431. if(PSDTriggerCnt == 1)
  9432. {
  9433. odm_PSD_RXHP(pDM_Odm);
  9434. pRX_HP_Table->PSD_func_trigger = 1;
  9435. PSDTriggerCnt = 0;
  9436. }
  9437. else
  9438. {
  9439. PSDTriggerCnt++;
  9440. }
  9441. #if(DEV_BUS_TYPE == RT_USB_INTERFACE)
  9442. }
  9443. //2 After TP Mode ==> Check if TP degrade larger than 20% would trigger PSD function
  9444. if(pRX_HP_Table->TP_Mode == High_TP_Mode)
  9445. {
  9446. if((pre_state_flag == 0)&&(LatchCnt == 0))
  9447. {
  9448. // TP var < 5%
  9449. if((((curTPOkCnt-TP_Acc3)*20)<(TP_Acc3))&&(((curTPOkCnt-TP_Acc3)*20)>(-TP_Acc3)))
  9450. {
  9451. pre_state++;
  9452. if(pre_state == 3) // hit pre_state condition => consecutive 3 times
  9453. {
  9454. pre_state_flag = 1;
  9455. pre_state = 0;
  9456. }
  9457. }
  9458. else
  9459. {
  9460. pre_state = 0;
  9461. }
  9462. }
  9463. //3 If pre_state_flag=1 ==> start to monitor TP degrade 20%
  9464. if(pre_state_flag == 1)
  9465. {
  9466. if(((TP_Acc3-curTPOkCnt)*5)>(TP_Acc3)) // degrade 20%
  9467. {
  9468. odm_PSD_RXHP(pDM_Odm);
  9469. pRX_HP_Table->PSD_func_trigger = 1;
  9470. TP_Degrade_flag = 1;
  9471. LatchCnt = 2;
  9472. pre_state_flag = 0;
  9473. }
  9474. else if(((TP_Buff[2]-curTPOkCnt)*5)>TP_Buff[2])
  9475. {
  9476. odm_PSD_RXHP(pDM_Odm);
  9477. pRX_HP_Table->PSD_func_trigger = 1;
  9478. TP_Degrade_flag = 1;
  9479. LatchCnt = 2;
  9480. pre_state_flag = 0;
  9481. }
  9482. else if(((TP_Buff[3]-curTPOkCnt)*5)>TP_Buff[3])
  9483. {
  9484. odm_PSD_RXHP(pDM_Odm);
  9485. pRX_HP_Table->PSD_func_trigger = 1;
  9486. TP_Degrade_flag = 1;
  9487. LatchCnt = 2;
  9488. pre_state_flag = 0;
  9489. }
  9490. }
  9491. }
  9492. #endif
  9493. }
  9494. #if (DEV_BUS_TYPE == RT_USB_INTERFACE)
  9495. for (i=0;i<4;i++)
  9496. {
  9497. TP_Buff[4-i] = TP_Buff[3-i];
  9498. }
  9499. #endif
  9500. //2 Update PSD bitmap according to PSD report
  9501. if((pRX_HP_Table->PSD_func_trigger == 1)&&(LatchCnt == 0))
  9502. {
  9503. //2 Separate 80M bandwidth into 16 group with smaller 5M BW.
  9504. for (i = 0 ; i < 16 ; i++)
  9505. {
  9506. sum = 0;
  9507. for(j = 0; j < 5 ; j++)
  9508. sum += pRX_HP_Table->PSD_bitmap_RXHP[5*i + j];
  9509. if(sum < 5)
  9510. {
  9511. ch_map_intf_5M[i] = 1; // interference flag
  9512. }
  9513. }
  9514. //=============just for debug=========================
  9515. //for(i=0;i<16;i++)
  9516. //DbgPrint("RX HP: ch_map_intf_5M[%d] = %d\n", i, ch_map_intf_5M[i]);
  9517. //===============================================
  9518. //2 Mask target channel 5M index
  9519. for(i = 0; i < (4+4*Is40MHz) ; i++)
  9520. {
  9521. ch_map_intf_5M[cur_channel - (1+2*Is40MHz) + i] = 0;
  9522. }
  9523. psd_intf_flag = 0;
  9524. for(i = 0; i < 16; i++)
  9525. {
  9526. if(ch_map_intf_5M[i] == 1)
  9527. {
  9528. psd_intf_flag = 1; // interference is detected!!!
  9529. break;
  9530. }
  9531. }
  9532. #if (DEV_BUS_TYPE == RT_USB_INTERFACE)
  9533. if(pRX_HP_Table->TP_Mode!=Idle_Mode)
  9534. {
  9535. if(psd_intf_flag == 1) // to avoid psd_intf_flag always 1
  9536. {
  9537. Intf_HighTP_flag = 1;
  9538. De_counter = 32; // 0x1E -> 0x3E needs 32 times by each IGI step =1
  9539. }
  9540. }
  9541. #endif
  9542. ODM_RT_TRACE(pDM_Odm, ODM_COMP_RXHP, ODM_DBG_LOUD, ("RX HP psd_intf_flag = %d\n", psd_intf_flag));
  9543. //2 Distance between target channel and interference
  9544. for(i = 0; i < 16; i++)
  9545. {
  9546. if(ch_map_intf_5M[i] == 1)
  9547. {
  9548. Intf_diff_idx = ((cur_channel+Is40MHz-(i+1))>0) ? (s1Byte)(cur_channel-2*Is40MHz-(i-2)) : (s1Byte)((i+1)-(cur_channel+2*Is40MHz));
  9549. if(Intf_diff_idx < MIN_Intf_diff_idx)
  9550. MIN_Intf_diff_idx = Intf_diff_idx; // the min difference index between interference and target
  9551. }
  9552. }
  9553. ODM_RT_TRACE(pDM_Odm, ODM_COMP_RXHP, ODM_DBG_LOUD, ("RX HP MIN_Intf_diff_idx = %d\n", MIN_Intf_diff_idx));
  9554. //2 Choose False Alarm Threshold
  9555. switch (MIN_Intf_diff_idx){
  9556. case 0:
  9557. case 1:
  9558. case 2:
  9559. case 3:
  9560. FA_TH = FA_RXHP_TH1;
  9561. break;
  9562. case 4: // CH5
  9563. case 5: // CH6
  9564. FA_TH = FA_RXHP_TH2;
  9565. break;
  9566. case 6: // CH7
  9567. case 7: // CH8
  9568. FA_TH = FA_RXHP_TH3;
  9569. break;
  9570. case 8: // CH9
  9571. case 9: //CH10
  9572. FA_TH = FA_RXHP_TH4;
  9573. break;
  9574. case 10:
  9575. case 11:
  9576. case 12:
  9577. case 13:
  9578. case 14:
  9579. case 15:
  9580. FA_TH = FA_RXHP_TH5;
  9581. break;
  9582. }
  9583. ODM_RT_TRACE(pDM_Odm, ODM_COMP_RXHP, ODM_DBG_LOUD, ("RX HP FA_TH = %d\n", FA_TH));
  9584. pRX_HP_Table->PSD_func_trigger = 0;
  9585. }
  9586. //1 Monitor RSSI variation to choose the suitable IGI or Exit AGC RX High Power Mode
  9587. if(pRX_HP_Table->RXHP_flag == 1)
  9588. {
  9589. if ((curRssi > 80)&&(preRssi < 80))
  9590. {
  9591. pRX_HP_Table->Cur_IGI = LNA_Low_Gain_1;
  9592. }
  9593. else if ((curRssi < 80)&&(preRssi > 80))
  9594. {
  9595. pRX_HP_Table->Cur_IGI = LNA_Low_Gain_2;
  9596. }
  9597. else if ((curRssi > 72)&&(preRssi < 72))
  9598. {
  9599. pRX_HP_Table->Cur_IGI = LNA_Low_Gain_2;
  9600. }
  9601. else if ((curRssi < 72)&&( preRssi > 72))
  9602. {
  9603. pRX_HP_Table->Cur_IGI = LNA_Low_Gain_3;
  9604. }
  9605. else if (curRssi < 68) //RSSI is NOT large enough!!==> Exit AGC RX High Power Mode
  9606. {
  9607. pRX_HP_Table->Cur_pw_th = pw_th_10dB;
  9608. pRX_HP_Table->RXHP_flag = 0; // Back to Normal DIG Mode
  9609. psd_intf_flag = 0;
  9610. }
  9611. }
  9612. else // pRX_HP_Table->RXHP_flag == 0
  9613. {
  9614. //1 Decide whether to enter AGC RX High Power Mode
  9615. if ((curRssi > 70) && (psd_intf_flag == 1) && (FalseAlmCnt->Cnt_all > FA_TH) &&
  9616. (pDM_DigTable->CurIGValue == pDM_DigTable->rx_gain_range_max))
  9617. {
  9618. if (curRssi > 80)
  9619. {
  9620. pRX_HP_Table->Cur_IGI = LNA_Low_Gain_1;
  9621. }
  9622. else if (curRssi > 72)
  9623. {
  9624. pRX_HP_Table->Cur_IGI = LNA_Low_Gain_2;
  9625. }
  9626. else
  9627. {
  9628. pRX_HP_Table->Cur_IGI = LNA_Low_Gain_3;
  9629. }
  9630. pRX_HP_Table->Cur_pw_th = pw_th_16dB; //RegC54[9:8]=2'b11: to enter AGC Flow 3
  9631. pRX_HP_Table->First_time_enter = TRUE;
  9632. pRX_HP_Table->RXHP_flag = 1; // RXHP_flag=1: AGC RX High Power Mode, RXHP_flag=0: Normal DIG Mode
  9633. }
  9634. }
  9635. preRssi = curRssi;
  9636. odm_Write_RXHP(pDM_Odm);
  9637. }
  9638. #endif //#if( DM_ODM_SUPPORT_TYPE & (ODM_WIN))
  9639. #endif //#if (DEV_BUS_TYPE == RT_PCI_INTERFACE) | (DEV_BUS_TYPE == RT_USB_INTERFACE)
  9640. }
  9641. void odm_Write_RXHP(
  9642. IN PDM_ODM_T pDM_Odm)
  9643. {
  9644. pRXHP_T pRX_HP_Table = &pDM_Odm->DM_RXHP_Table;
  9645. u4Byte currentIGI;
  9646. if(pRX_HP_Table->Cur_IGI != pRX_HP_Table->Pre_IGI)
  9647. {
  9648. ODM_SetBBReg(pDM_Odm, rOFDM0_XAAGCCore1, bMaskByte0, pRX_HP_Table->Cur_IGI);
  9649. ODM_SetBBReg(pDM_Odm, rOFDM0_XBAGCCore1, bMaskByte0, pRX_HP_Table->Cur_IGI);
  9650. }
  9651. if(pRX_HP_Table->Cur_pw_th != pRX_HP_Table->Pre_pw_th)
  9652. {
  9653. ODM_SetBBReg(pDM_Odm, rOFDM0_XAAGCCore2, BIT8|BIT9, pRX_HP_Table->Cur_pw_th); // RegC54[9:8]=2'b11: AGC Flow 3
  9654. }
  9655. if(pRX_HP_Table->RXHP_flag == 0)
  9656. {
  9657. pRX_HP_Table->Cur_IGI = 0x20;
  9658. }
  9659. else
  9660. {
  9661. currentIGI = ODM_GetBBReg(pDM_Odm, rOFDM0_XAAGCCore1, bMaskByte0);
  9662. if(currentIGI<0x50)
  9663. {
  9664. ODM_SetBBReg(pDM_Odm, rOFDM0_XAAGCCore1, bMaskByte0, pRX_HP_Table->Cur_IGI);
  9665. ODM_SetBBReg(pDM_Odm, rOFDM0_XBAGCCore1, bMaskByte0, pRX_HP_Table->Cur_IGI);
  9666. }
  9667. }
  9668. pRX_HP_Table->Pre_IGI = pRX_HP_Table->Cur_IGI;
  9669. pRX_HP_Table->Pre_pw_th = pRX_HP_Table->Cur_pw_th;
  9670. }
  9671. VOID
  9672. odm_PSD_RXHP(
  9673. IN PDM_ODM_T pDM_Odm
  9674. )
  9675. {
  9676. pRXHP_T pRX_HP_Table = &pDM_Odm->DM_RXHP_Table;
  9677. PADAPTER Adapter = pDM_Odm->Adapter;
  9678. PMGNT_INFO pMgntInfo = &(Adapter->MgntInfo);
  9679. unsigned int pts, start_point, stop_point, initial_gain ;
  9680. static u1Byte PSD_bitmap_memory[80], init_memory = 0;
  9681. static u1Byte psd_cnt=0;
  9682. static u4Byte PSD_report[80], PSD_report_tmp;
  9683. static u8Byte lastTxOkCnt=0, lastRxOkCnt=0;
  9684. u1Byte idx[20]={96,99,102,106,109,112,115,118,122,125,
  9685. 0,3,6,10,13,16,19,22,26,29};
  9686. u1Byte n, i, channel, BBReset,tone_idx;
  9687. u1Byte PSD_bitmap[10]/*, SSBT=0*/,initial_gain_psd=0, RSSI_BT=0, initialGainUpper;
  9688. s4Byte PSD_skip_start, PSD_skip_stop;
  9689. u4Byte CurrentChannel, RXIQI, RxIdleLowPwr, wlan_channel;
  9690. u4Byte ReScan, Interval, Is40MHz;
  9691. u8Byte curTxOkCnt, curRxOkCnt;
  9692. //--------------2G band synthesizer for 92D switch RF channel using-----------------
  9693. u1Byte group_idx=0;
  9694. u4Byte SYN_RF25=0, SYN_RF26=0, SYN_RF27=0, SYN_RF2B=0, SYN_RF2C=0;
  9695. u4Byte SYN[5] = {0x25, 0x26, 0x27, 0x2B, 0x2C}; // synthesizer RF register for 2G channel
  9696. u4Byte SYN_group[3][5] = {{0x643BC, 0xFC038, 0x77C1A, 0x41289, 0x01840}, // For CH1,2,4,9,10.11.12 {0x643BC, 0xFC038, 0x77C1A, 0x41289, 0x01840}
  9697. {0x643BC, 0xFC038, 0x07C1A, 0x41289, 0x01840}, // For CH3,13,14
  9698. {0x243BC, 0xFC438, 0x07C1A, 0x4128B, 0x0FC41}}; // For Ch5,6,7,8
  9699. //--------------------- Add by Gary for Debug setting ----------------------
  9700. u1Byte RSSI_BT_new = (u1Byte) ODM_GetBBReg(pDM_Odm, 0xB9C, 0xFF);
  9701. u1Byte rssi_ctrl = (u1Byte) ODM_GetBBReg(pDM_Odm, 0xB38, 0xFF);
  9702. //---------------------------------------------------------------------
  9703. if(pMgntInfo->bScanInProgress)
  9704. {
  9705. return;
  9706. }
  9707. ReScan = PSD_RESCAN;
  9708. Interval = SCAN_INTERVAL;
  9709. //1 Initialization
  9710. if(init_memory == 0)
  9711. {
  9712. RT_TRACE( COMP_PSD, DBG_LOUD,("Init memory\n"));
  9713. for(i = 0; i < 80; i++)
  9714. PSD_bitmap_memory[i] = 0xFF; // channel is always good
  9715. init_memory = 1;
  9716. }
  9717. if(psd_cnt == 0)
  9718. {
  9719. RT_TRACE(COMP_PSD, DBG_LOUD,("Enter dm_PSD_Monitor\n"));
  9720. for(i = 0; i < 80; i++)
  9721. PSD_report[i] = 0;
  9722. }
  9723. //1 Backup Current Settings
  9724. CurrentChannel = ODM_GetRFReg(pDM_Odm, ODM_RF_PATH_A, RF_CHNLBW, bRFRegOffsetMask);
  9725. if(pDM_Odm->SupportICType == ODM_RTL8192D)
  9726. {
  9727. //2 Record Current synthesizer parameters based on current channel
  9728. if((*(pDM_Odm->pMacPhyMode)==ODM_SMSP)||(*(pDM_Odm->pMacPhyMode)==ODM_DMSP))
  9729. {
  9730. SYN_RF25 = ODM_GetRFReg(pDM_Odm, ODM_RF_PATH_B, 0x25, bMaskDWord);
  9731. SYN_RF26 = ODM_GetRFReg(pDM_Odm, ODM_RF_PATH_B, 0x26, bMaskDWord);
  9732. SYN_RF27 = ODM_GetRFReg(pDM_Odm, ODM_RF_PATH_B, 0x27, bMaskDWord);
  9733. SYN_RF2B = ODM_GetRFReg(pDM_Odm, ODM_RF_PATH_B, 0x2B, bMaskDWord);
  9734. SYN_RF2C = ODM_GetRFReg(pDM_Odm, ODM_RF_PATH_B, 0x2C, bMaskDWord);
  9735. }
  9736. else // DualMAC_DualPHY 2G
  9737. {
  9738. SYN_RF25 = ODM_GetRFReg(pDM_Odm, ODM_RF_PATH_A, 0x25, bMaskDWord);
  9739. SYN_RF26 = ODM_GetRFReg(pDM_Odm, ODM_RF_PATH_A, 0x26, bMaskDWord);
  9740. SYN_RF27 = ODM_GetRFReg(pDM_Odm, ODM_RF_PATH_A, 0x27, bMaskDWord);
  9741. SYN_RF2B = ODM_GetRFReg(pDM_Odm, ODM_RF_PATH_A, 0x2B, bMaskDWord);
  9742. SYN_RF2C = ODM_GetRFReg(pDM_Odm, ODM_RF_PATH_A, 0x2C, bMaskDWord);
  9743. }
  9744. }
  9745. RXIQI = ODM_GetBBReg(pDM_Odm, 0xC14, bMaskDWord);
  9746. RxIdleLowPwr = (ODM_GetBBReg(pDM_Odm, 0x818, bMaskDWord)&BIT28)>>28;
  9747. Is40MHz = *(pDM_Odm->pBandWidth);
  9748. ODM_RT_TRACE(pDM_Odm, COMP_PSD, DBG_LOUD,("PSD Scan Start\n"));
  9749. //1 Turn off CCK
  9750. ODM_SetBBReg(pDM_Odm, rFPGA0_RFMOD, BIT24, 0);
  9751. //1 Turn off TX
  9752. //Pause TX Queue
  9753. ODM_Write1Byte(pDM_Odm, REG_TXPAUSE, 0xFF);
  9754. //Force RX to stop TX immediately
  9755. ODM_SetRFReg(pDM_Odm, ODM_RF_PATH_A, RF_AC, bRFRegOffsetMask, 0x32E13);
  9756. //1 Turn off RX
  9757. //Rx AGC off RegC70[0]=0, RegC7C[20]=0
  9758. ODM_SetBBReg(pDM_Odm, 0xC70, BIT0, 0);
  9759. ODM_SetBBReg(pDM_Odm, 0xC7C, BIT20, 0);
  9760. //Turn off CCA
  9761. ODM_SetBBReg(pDM_Odm, 0xC14, bMaskDWord, 0x0);
  9762. //BB Reset
  9763. ODM_SetBBReg(pDM_Odm, 0x87C, BIT31, 1); //clock gated to prevent from AGC table mess
  9764. BBReset = ODM_Read1Byte(pDM_Odm, 0x02);
  9765. ODM_Write1Byte(pDM_Odm, 0x02, BBReset&(~BIT0));
  9766. ODM_Write1Byte(pDM_Odm, 0x02, BBReset|BIT0);
  9767. ODM_SetBBReg(pDM_Odm, 0x87C, BIT31, 0);
  9768. //1 Leave RX idle low power
  9769. ODM_SetBBReg(pDM_Odm, 0x818, BIT28, 0x0);
  9770. //1 Fix initial gain
  9771. RSSI_BT = RSSI_BT_new;
  9772. RT_TRACE(COMP_PSD, DBG_LOUD,("PSD: RSSI_BT= %d\n", RSSI_BT));
  9773. if(rssi_ctrl == 1) // just for debug!!
  9774. initial_gain_psd = RSSI_BT_new;
  9775. else
  9776. initial_gain_psd = pDM_Odm->RSSI_Min; // PSD report based on RSSI
  9777. RT_TRACE(COMP_PSD, DBG_LOUD,("PSD: RSSI_BT= %d\n", RSSI_BT));
  9778. initialGainUpper = 0x54;
  9779. RSSI_BT = initial_gain_psd;
  9780. //SSBT = RSSI_BT;
  9781. //RT_TRACE( COMP_PSD, DBG_LOUD,("PSD: SSBT= %d\n", SSBT));
  9782. RT_TRACE( COMP_PSD, DBG_LOUD,("PSD: initial gain= 0x%x\n", initial_gain_psd));
  9783. pDM_Odm->bDMInitialGainEnable = FALSE;
  9784. initial_gain = ODM_GetBBReg(pDM_Odm, 0xc50, bMaskDWord) & 0x7F;
  9785. //ODM_SetBBReg(pDM_Odm, 0xc50, 0x7F, initial_gain_psd);
  9786. ODM_Write_DIG(pDM_Odm, initial_gain_psd);
  9787. //1 Turn off 3-wire
  9788. ODM_SetBBReg(pDM_Odm, 0x88c, BIT20|BIT21|BIT22|BIT23, 0xF);
  9789. //pts value = 128, 256, 512, 1024
  9790. pts = 128;
  9791. if(pts == 128)
  9792. {
  9793. ODM_SetBBReg(pDM_Odm, 0x808, BIT14|BIT15, 0x0);
  9794. start_point = 64;
  9795. stop_point = 192;
  9796. }
  9797. else if(pts == 256)
  9798. {
  9799. ODM_SetBBReg(pDM_Odm, 0x808, BIT14|BIT15, 0x1);
  9800. start_point = 128;
  9801. stop_point = 384;
  9802. }
  9803. else if(pts == 512)
  9804. {
  9805. ODM_SetBBReg(pDM_Odm, 0x808, BIT14|BIT15, 0x2);
  9806. start_point = 256;
  9807. stop_point = 768;
  9808. }
  9809. else
  9810. {
  9811. ODM_SetBBReg(pDM_Odm, 0x808, BIT14|BIT15, 0x3);
  9812. start_point = 512;
  9813. stop_point = 1536;
  9814. }
  9815. //3 Skip WLAN channels if WLAN busy
  9816. curTxOkCnt = *(pDM_Odm->pNumTxBytesUnicast) - lastTxOkCnt;
  9817. curRxOkCnt = *(pDM_Odm->pNumRxBytesUnicast) - lastRxOkCnt;
  9818. lastTxOkCnt = *(pDM_Odm->pNumTxBytesUnicast);
  9819. lastRxOkCnt = *(pDM_Odm->pNumRxBytesUnicast);
  9820. PSD_skip_start=80;
  9821. PSD_skip_stop = 0;
  9822. wlan_channel = CurrentChannel & 0x0f;
  9823. RT_TRACE(COMP_PSD,DBG_LOUD,("PSD: current channel: %x, BW:%d \n", wlan_channel, Is40MHz));
  9824. if((curRxOkCnt+curTxOkCnt) > 1000)
  9825. {
  9826. PSD_skip_start = (wlan_channel-1)*5 -Is40MHz*10;
  9827. PSD_skip_stop = PSD_skip_start + (1+Is40MHz)*20;
  9828. }
  9829. RT_TRACE(COMP_PSD,DBG_LOUD,("PSD: Skip tone from %d to %d \n", PSD_skip_start, PSD_skip_stop));
  9830. for (n=0;n<80;n++)
  9831. {
  9832. if((n%20)==0)
  9833. {
  9834. channel = (n/20)*4 + 1;
  9835. if(pDM_Odm->SupportICType == ODM_RTL8192D)
  9836. {
  9837. switch(channel)
  9838. {
  9839. case 1:
  9840. case 9:
  9841. group_idx = 0;
  9842. break;
  9843. case 5:
  9844. group_idx = 2;
  9845. break;
  9846. case 13:
  9847. group_idx = 1;
  9848. break;
  9849. }
  9850. if((*(pDM_Odm->pMacPhyMode)==ODM_SMSP)||(*(pDM_Odm->pMacPhyMode)==ODM_DMSP))
  9851. {
  9852. for(i = 0; i < SYN_Length; i++)
  9853. ODM_SetRFReg(pDM_Odm, ODM_RF_PATH_B, SYN[i], bMaskDWord, SYN_group[group_idx][i]);
  9854. ODM_SetRFReg(pDM_Odm, ODM_RF_PATH_A, RF_CHNLBW, 0x3FF, channel);
  9855. ODM_SetRFReg(pDM_Odm, ODM_RF_PATH_B, RF_CHNLBW, 0x3FF, channel);
  9856. }
  9857. else // DualMAC_DualPHY 2G
  9858. {
  9859. for(i = 0; i < SYN_Length; i++)
  9860. ODM_SetRFReg(pDM_Odm, ODM_RF_PATH_A, SYN[i], bMaskDWord, SYN_group[group_idx][i]);
  9861. ODM_SetRFReg(pDM_Odm, ODM_RF_PATH_A, RF_CHNLBW, 0x3FF, channel);
  9862. }
  9863. }
  9864. else
  9865. ODM_SetRFReg(pDM_Odm, ODM_RF_PATH_A, RF_CHNLBW, 0x3FF, channel);
  9866. }
  9867. tone_idx = n%20;
  9868. if ((n>=PSD_skip_start) && (n<PSD_skip_stop))
  9869. {
  9870. PSD_report[n] = initial_gain_psd;//SSBT;
  9871. ODM_RT_TRACE(pDM_Odm,COMP_PSD,DBG_LOUD,("PSD:Tone %d skipped \n", n));
  9872. }
  9873. else
  9874. {
  9875. PSD_report_tmp = GetPSDData(pDM_Odm, idx[tone_idx], initial_gain_psd);
  9876. if ( PSD_report_tmp > PSD_report[n])
  9877. PSD_report[n] = PSD_report_tmp;
  9878. }
  9879. }
  9880. PatchDCTone(pDM_Odm, PSD_report, initial_gain_psd);
  9881. //----end
  9882. //1 Turn on RX
  9883. //Rx AGC on
  9884. ODM_SetBBReg(pDM_Odm, 0xC70, BIT0, 1);
  9885. ODM_SetBBReg(pDM_Odm, 0xC7C, BIT20, 1);
  9886. //CCK on
  9887. ODM_SetBBReg(pDM_Odm, rFPGA0_RFMOD, BIT24, 1);
  9888. //1 Turn on TX
  9889. //Resume TX Queue
  9890. ODM_Write1Byte(pDM_Odm, REG_TXPAUSE, 0x00);
  9891. //Turn on 3-wire
  9892. ODM_SetBBReg(pDM_Odm, 0x88c, BIT20|BIT21|BIT22|BIT23, 0x0);
  9893. //1 Restore Current Settings
  9894. //Resume DIG
  9895. pDM_Odm->bDMInitialGainEnable= TRUE;
  9896. //ODM_SetBBReg(pDM_Odm, 0xc50, 0x7F, initial_gain);
  9897. ODM_Write_DIG(pDM_Odm,(u1Byte) initial_gain);
  9898. // restore originl center frequency
  9899. ODM_SetRFReg(pDM_Odm, ODM_RF_PATH_A, RF_CHNLBW, bRFRegOffsetMask, CurrentChannel);
  9900. if(pDM_Odm->SupportICType == ODM_RTL8192D)
  9901. {
  9902. if((*(pDM_Odm->pMacPhyMode)==ODM_SMSP)||(*(pDM_Odm->pMacPhyMode)==ODM_DMSP))
  9903. {
  9904. ODM_SetRFReg(pDM_Odm, ODM_RF_PATH_B, RF_CHNLBW, bMaskDWord, CurrentChannel);
  9905. ODM_SetRFReg(pDM_Odm, ODM_RF_PATH_B, 0x25, bMaskDWord, SYN_RF25);
  9906. ODM_SetRFReg(pDM_Odm, ODM_RF_PATH_B, 0x26, bMaskDWord, SYN_RF26);
  9907. ODM_SetRFReg(pDM_Odm, ODM_RF_PATH_B, 0x27, bMaskDWord, SYN_RF27);
  9908. ODM_SetRFReg(pDM_Odm, ODM_RF_PATH_B, 0x2B, bMaskDWord, SYN_RF2B);
  9909. ODM_SetRFReg(pDM_Odm, ODM_RF_PATH_B, 0x2C, bMaskDWord, SYN_RF2C);
  9910. }
  9911. else // DualMAC_DualPHY
  9912. {
  9913. ODM_SetRFReg(pDM_Odm, ODM_RF_PATH_A, 0x25, bMaskDWord, SYN_RF25);
  9914. ODM_SetRFReg(pDM_Odm, ODM_RF_PATH_A, 0x26, bMaskDWord, SYN_RF26);
  9915. ODM_SetRFReg(pDM_Odm, ODM_RF_PATH_A, 0x27, bMaskDWord, SYN_RF27);
  9916. ODM_SetRFReg(pDM_Odm, ODM_RF_PATH_A, 0x2B, bMaskDWord, SYN_RF2B);
  9917. ODM_SetRFReg(pDM_Odm, ODM_RF_PATH_A, 0x2C, bMaskDWord, SYN_RF2C);
  9918. }
  9919. }
  9920. //Turn on CCA
  9921. ODM_SetBBReg(pDM_Odm, 0xC14, bMaskDWord, RXIQI);
  9922. //Restore RX idle low power
  9923. if(RxIdleLowPwr == TRUE)
  9924. ODM_SetBBReg(pDM_Odm, 0x818, BIT28, 1);
  9925. psd_cnt++;
  9926. //gPrint("psd cnt=%d\n", psd_cnt);
  9927. ODM_RT_TRACE(pDM_Odm,COMP_PSD, DBG_LOUD,("PSD:psd_cnt = %d \n",psd_cnt));
  9928. if (psd_cnt < ReScan)
  9929. {
  9930. ODM_SetTimer(pDM_Odm, &pRX_HP_Table->PSDTimer, Interval); //ms
  9931. }
  9932. else
  9933. {
  9934. psd_cnt = 0;
  9935. for(i=0;i<80;i++)
  9936. RT_TRACE( COMP_PSD, DBG_LOUD,("psd_report[%d]= %d \n", 2402+i, PSD_report[i]));
  9937. //DbgPrint("psd_report[%d]= %d \n", 2402+i, PSD_report[i]);
  9938. GoodChannelDecision(pDM_Odm, PSD_report, PSD_bitmap,RSSI_BT, PSD_bitmap_memory);
  9939. }
  9940. }
  9941. VOID
  9942. odm_PSD_RXHPCallback(
  9943. PRT_TIMER pTimer
  9944. )
  9945. {
  9946. PADAPTER Adapter = (PADAPTER)pTimer->Adapter;
  9947. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  9948. PDM_ODM_T pDM_Odm = &pHalData->DM_OutSrc;
  9949. pRXHP_T pRX_HP_Table = &pDM_Odm->DM_RXHP_Table;
  9950. #if DEV_BUS_TYPE==RT_PCI_INTERFACE
  9951. #if USE_WORKITEM
  9952. ODM_ScheduleWorkItem(&pRX_HP_Table->PSDTimeWorkitem);
  9953. #else
  9954. odm_PSD_RXHP(pDM_Odm);
  9955. #endif
  9956. #else
  9957. ODM_ScheduleWorkItem(&pRX_HP_Table->PSDTimeWorkitem);
  9958. #endif
  9959. }
  9960. VOID
  9961. odm_PSD_RXHPWorkitemCallback(
  9962. IN PVOID pContext
  9963. )
  9964. {
  9965. PADAPTER pAdapter = (PADAPTER)pContext;
  9966. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(pAdapter);
  9967. PDM_ODM_T pDM_Odm = &pHalData->DM_OutSrc;
  9968. odm_PSD_RXHP(pDM_Odm);
  9969. }
  9970. #endif //#if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
  9971. VOID
  9972. odm_PathDiversityInit(
  9973. IN PDM_ODM_T pDM_Odm
  9974. )
  9975. {
  9976. if(!(pDM_Odm->SupportAbility & ODM_BB_PATH_DIV))
  9977. {
  9978. ODM_RT_TRACE(pDM_Odm, ODM_COMP_PATH_DIV,ODM_DBG_LOUD,("Return: Not Support PathDiv\n"));
  9979. return;
  9980. }
  9981. #if (RTL8812A_SUPPORT == 1)
  9982. // if(pDM_Odm->SupportICType & ODM_RTL8812)
  9983. // ODM_PathDiversityInit_8812A(pDM_Odm);
  9984. #endif
  9985. }
  9986. VOID
  9987. odm_PathDiversity(
  9988. IN PDM_ODM_T pDM_Odm
  9989. )
  9990. {
  9991. if(!(pDM_Odm->SupportAbility & ODM_BB_PATH_DIV))
  9992. {
  9993. ODM_RT_TRACE(pDM_Odm, ODM_COMP_PATH_DIV,ODM_DBG_LOUD,("Return: Not Support PathDiv\n"));
  9994. return;
  9995. }
  9996. #if (RTL8812A_SUPPORT == 1)
  9997. // if(pDM_Odm->SupportICType & ODM_RTL8812)
  9998. // ODM_PathDiversity_8812A(pDM_Odm);
  9999. #endif
  10000. }
  10001. //
  10002. // 2011/12/02 MH Copy from MP oursrc for temporarily test.
  10003. //
  10004. #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
  10005. VOID
  10006. odm_OFDMTXPathDiversity_92C(
  10007. IN PADAPTER Adapter)
  10008. {
  10009. // HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  10010. PMGNT_INFO pMgntInfo = &(Adapter->MgntInfo);
  10011. PRT_WLAN_STA pEntry;
  10012. u1Byte i, DefaultRespPath = 0;
  10013. s4Byte MinRSSI = 0xFF;
  10014. pPD_T pDM_PDTable = &Adapter->DM_PDTable;
  10015. pDM_PDTable->OFDMTXPath = 0;
  10016. //1 Default Port
  10017. if(pMgntInfo->mAssoc)
  10018. {
  10019. RT_TRACE( COMP_SWAS, DBG_LOUD, ("odm_OFDMTXPathDiversity_92C: Default port RSSI[0]=%d, RSSI[1]=%d\n",
  10020. Adapter->RxStats.RxRSSIPercentage[0], Adapter->RxStats.RxRSSIPercentage[1]));
  10021. if(Adapter->RxStats.RxRSSIPercentage[0] > Adapter->RxStats.RxRSSIPercentage[1])
  10022. {
  10023. pDM_PDTable->OFDMTXPath = pDM_PDTable->OFDMTXPath & (~BIT0);
  10024. MinRSSI = Adapter->RxStats.RxRSSIPercentage[1];
  10025. DefaultRespPath = 0;
  10026. RT_TRACE( COMP_SWAS, DBG_LOUD, ("odm_OFDMTXPathDiversity_92C: Default port Select Path-0\n"));
  10027. }
  10028. else
  10029. {
  10030. pDM_PDTable->OFDMTXPath = pDM_PDTable->OFDMTXPath | BIT0;
  10031. MinRSSI = Adapter->RxStats.RxRSSIPercentage[0];
  10032. DefaultRespPath = 1;
  10033. RT_TRACE( COMP_SWAS, DBG_LOUD, ("odm_OFDMTXPathDiversity_92C: Default port Select Path-1\n"));
  10034. }
  10035. //RT_TRACE( COMP_SWAS, DBG_LOUD, ("pDM_PDTable->OFDMTXPath =0x%x\n",pDM_PDTable->OFDMTXPath));
  10036. }
  10037. //1 Extension Port
  10038. for(i = 0; i < ODM_ASSOCIATE_ENTRY_NUM; i++)
  10039. {
  10040. if(IsAPModeExist(Adapter) && GetFirstExtAdapter(Adapter) != NULL)
  10041. pEntry = AsocEntry_EnumStation(GetFirstExtAdapter(Adapter), i);
  10042. else
  10043. pEntry = AsocEntry_EnumStation(GetDefaultAdapter(Adapter), i);
  10044. if(pEntry!=NULL)
  10045. {
  10046. if(pEntry->bAssociated)
  10047. {
  10048. RT_TRACE( COMP_SWAS, DBG_LOUD, ("odm_OFDMTXPathDiversity_92C: MACID=%d, RSSI_0=%d, RSSI_1=%d\n",
  10049. pEntry->AssociatedMacId, pEntry->rssi_stat.RxRSSIPercentage[0], pEntry->rssi_stat.RxRSSIPercentage[1]));
  10050. if(pEntry->rssi_stat.RxRSSIPercentage[0] > pEntry->rssi_stat.RxRSSIPercentage[1])
  10051. {
  10052. pDM_PDTable->OFDMTXPath = pDM_PDTable->OFDMTXPath & ~(BIT(pEntry->AssociatedMacId));
  10053. //pHalData->TXPath = pHalData->TXPath & ~(1<<(pEntry->AssociatedMacId));
  10054. RT_TRACE( COMP_SWAS, DBG_LOUD, ("odm_OFDMTXPathDiversity_92C: MACID=%d Select Path-0\n", pEntry->AssociatedMacId));
  10055. if(pEntry->rssi_stat.RxRSSIPercentage[1] < MinRSSI)
  10056. {
  10057. MinRSSI = pEntry->rssi_stat.RxRSSIPercentage[1];
  10058. DefaultRespPath = 0;
  10059. }
  10060. }
  10061. else
  10062. {
  10063. pDM_PDTable->OFDMTXPath = pDM_PDTable->OFDMTXPath | BIT(pEntry->AssociatedMacId);
  10064. //pHalData->TXPath = pHalData->TXPath | (1 << (pEntry->AssociatedMacId));
  10065. RT_TRACE( COMP_SWAS, DBG_LOUD, ("odm_OFDMTXPathDiversity_92C: MACID=%d Select Path-1\n", pEntry->AssociatedMacId));
  10066. if(pEntry->rssi_stat.RxRSSIPercentage[0] < MinRSSI)
  10067. {
  10068. MinRSSI = pEntry->rssi_stat.RxRSSIPercentage[0];
  10069. DefaultRespPath = 1;
  10070. }
  10071. }
  10072. }
  10073. }
  10074. else
  10075. {
  10076. break;
  10077. }
  10078. }
  10079. pDM_PDTable->OFDMDefaultRespPath = DefaultRespPath;
  10080. }
  10081. BOOLEAN
  10082. odm_IsConnected_92C(
  10083. IN PADAPTER Adapter
  10084. )
  10085. {
  10086. PRT_WLAN_STA pEntry;
  10087. PMGNT_INFO pMgntInfo = &(Adapter->MgntInfo);
  10088. u4Byte i;
  10089. BOOLEAN bConnected=FALSE;
  10090. if(pMgntInfo->mAssoc)
  10091. {
  10092. bConnected = TRUE;
  10093. }
  10094. else
  10095. {
  10096. for(i = 0; i < ODM_ASSOCIATE_ENTRY_NUM; i++)
  10097. {
  10098. if(IsAPModeExist(Adapter) && GetFirstExtAdapter(Adapter) != NULL)
  10099. pEntry = AsocEntry_EnumStation(GetFirstExtAdapter(Adapter), i);
  10100. else
  10101. pEntry = AsocEntry_EnumStation(GetDefaultAdapter(Adapter), i);
  10102. if(pEntry!=NULL)
  10103. {
  10104. if(pEntry->bAssociated)
  10105. {
  10106. bConnected = TRUE;
  10107. break;
  10108. }
  10109. }
  10110. else
  10111. {
  10112. break;
  10113. }
  10114. }
  10115. }
  10116. return bConnected;
  10117. }
  10118. VOID
  10119. odm_ResetPathDiversity_92C(
  10120. IN PADAPTER Adapter
  10121. )
  10122. {
  10123. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  10124. pPD_T pDM_PDTable = &Adapter->DM_PDTable;
  10125. PRT_WLAN_STA pEntry;
  10126. u4Byte i,j;
  10127. pHalData->RSSI_test = FALSE;
  10128. pDM_PDTable->CCK_Pkt_Cnt = 0;
  10129. pDM_PDTable->OFDM_Pkt_Cnt = 0;
  10130. pHalData->CCK_Pkt_Cnt =0;
  10131. pHalData->OFDM_Pkt_Cnt =0;
  10132. if(pDM_PDTable->CCKPathDivEnable == TRUE)
  10133. PHY_SetBBReg(Adapter, rCCK0_AFESetting , 0x0F000000, 0x01); //RX path = PathAB
  10134. for(i=0; i<2; i++)
  10135. {
  10136. pDM_PDTable->RSSI_CCK_Path_cnt[i]=0;
  10137. pDM_PDTable->RSSI_CCK_Path[i] = 0;
  10138. }
  10139. for(i = 0; i < ODM_ASSOCIATE_ENTRY_NUM; i++)
  10140. {
  10141. if(IsAPModeExist(Adapter) && GetFirstExtAdapter(Adapter) != NULL)
  10142. pEntry = AsocEntry_EnumStation(GetFirstExtAdapter(Adapter), i);
  10143. else
  10144. pEntry = AsocEntry_EnumStation(GetDefaultAdapter(Adapter), i);
  10145. if(pEntry!=NULL)
  10146. {
  10147. pEntry->rssi_stat.CCK_Pkt_Cnt = 0;
  10148. pEntry->rssi_stat.OFDM_Pkt_Cnt = 0;
  10149. for(j=0; j<2; j++)
  10150. {
  10151. pEntry->rssi_stat.RSSI_CCK_Path_cnt[j] = 0;
  10152. pEntry->rssi_stat.RSSI_CCK_Path[j] = 0;
  10153. }
  10154. }
  10155. else
  10156. break;
  10157. }
  10158. }
  10159. VOID
  10160. odm_CCKTXPathDiversity_92C(
  10161. IN PADAPTER Adapter
  10162. )
  10163. {
  10164. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  10165. PMGNT_INFO pMgntInfo = &(Adapter->MgntInfo);
  10166. PRT_WLAN_STA pEntry;
  10167. s4Byte MinRSSI = 0xFF;
  10168. u1Byte i, DefaultRespPath = 0;
  10169. // BOOLEAN bBModePathDiv = FALSE;
  10170. pPD_T pDM_PDTable = &Adapter->DM_PDTable;
  10171. //1 Default Port
  10172. if(pMgntInfo->mAssoc)
  10173. {
  10174. if(pHalData->OFDM_Pkt_Cnt == 0)
  10175. {
  10176. for(i=0; i<2; i++)
  10177. {
  10178. if(pDM_PDTable->RSSI_CCK_Path_cnt[i] > 1) //Because the first packet is discarded
  10179. pDM_PDTable->RSSI_CCK_Path[i] = pDM_PDTable->RSSI_CCK_Path[i] / (pDM_PDTable->RSSI_CCK_Path_cnt[i]-1);
  10180. else
  10181. pDM_PDTable->RSSI_CCK_Path[i] = 0;
  10182. }
  10183. RT_TRACE( COMP_SWAS, DBG_LOUD, ("odm_CCKTXPathDiversity_92C: pDM_PDTable->RSSI_CCK_Path[0]=%d, pDM_PDTable->RSSI_CCK_Path[1]=%d\n",
  10184. pDM_PDTable->RSSI_CCK_Path[0], pDM_PDTable->RSSI_CCK_Path[1]));
  10185. RT_TRACE( COMP_SWAS, DBG_LOUD, ("odm_CCKTXPathDiversity_92C: pDM_PDTable->RSSI_CCK_Path_cnt[0]=%d, pDM_PDTable->RSSI_CCK_Path_cnt[1]=%d\n",
  10186. pDM_PDTable->RSSI_CCK_Path_cnt[0], pDM_PDTable->RSSI_CCK_Path_cnt[1]));
  10187. if(pDM_PDTable->RSSI_CCK_Path[0] > pDM_PDTable->RSSI_CCK_Path[1])
  10188. {
  10189. pDM_PDTable->CCKTXPath = pDM_PDTable->CCKTXPath & (~BIT0);
  10190. MinRSSI = pDM_PDTable->RSSI_CCK_Path[1];
  10191. DefaultRespPath = 0;
  10192. RT_TRACE( COMP_SWAS, DBG_LOUD, ("odm_CCKTXPathDiversity_92C: Default port Select CCK Path-0\n"));
  10193. }
  10194. else if(pDM_PDTable->RSSI_CCK_Path[0] < pDM_PDTable->RSSI_CCK_Path[1])
  10195. {
  10196. pDM_PDTable->CCKTXPath = pDM_PDTable->CCKTXPath | BIT0;
  10197. MinRSSI = pDM_PDTable->RSSI_CCK_Path[0];
  10198. DefaultRespPath = 1;
  10199. RT_TRACE( COMP_SWAS, DBG_LOUD, ("odm_CCKTXPathDiversity_92C: Default port Select CCK Path-1\n"));
  10200. }
  10201. else
  10202. {
  10203. if((pDM_PDTable->RSSI_CCK_Path[0] != 0) && (pDM_PDTable->RSSI_CCK_Path[0] < MinRSSI))
  10204. {
  10205. pDM_PDTable->CCKTXPath = pDM_PDTable->CCKTXPath & (~BIT0);
  10206. RT_TRACE( COMP_SWAS, DBG_LOUD, ("odm_CCKTXPathDiversity_92C: Default port Select CCK Path-0\n"));
  10207. MinRSSI = pDM_PDTable->RSSI_CCK_Path[1];
  10208. DefaultRespPath = 0;
  10209. }
  10210. else
  10211. {
  10212. RT_TRACE( COMP_SWAS, DBG_LOUD, ("odm_CCKTXPathDiversity_92C: Default port unchange CCK Path\n"));
  10213. }
  10214. }
  10215. }
  10216. else //Follow OFDM decision
  10217. {
  10218. pDM_PDTable->CCKTXPath = (pDM_PDTable->CCKTXPath & (~BIT0)) | (pDM_PDTable->OFDMTXPath &BIT0);
  10219. RT_TRACE( COMP_SWAS, DBG_LOUD, ("odm_CCKTXPathDiversity_92C: Follow OFDM decision, Default port Select CCK Path-%d\n",
  10220. pDM_PDTable->CCKTXPath &BIT0));
  10221. }
  10222. }
  10223. //1 Extension Port
  10224. for(i = 0; i < ODM_ASSOCIATE_ENTRY_NUM; i++)
  10225. {
  10226. if(IsAPModeExist(Adapter) && GetFirstExtAdapter(Adapter) != NULL)
  10227. pEntry = AsocEntry_EnumStation(GetFirstExtAdapter(Adapter), i);
  10228. else
  10229. pEntry = AsocEntry_EnumStation(GetDefaultAdapter(Adapter), i);
  10230. if(pEntry!=NULL)
  10231. {
  10232. if(pEntry->bAssociated)
  10233. {
  10234. if(pEntry->rssi_stat.OFDM_Pkt_Cnt == 0)
  10235. {
  10236. u1Byte j=0;
  10237. for(j=0; j<2; j++)
  10238. {
  10239. if(pEntry->rssi_stat.RSSI_CCK_Path_cnt[j] > 1)
  10240. pEntry->rssi_stat.RSSI_CCK_Path[j] = pEntry->rssi_stat.RSSI_CCK_Path[j] / (pEntry->rssi_stat.RSSI_CCK_Path_cnt[j]-1);
  10241. else
  10242. pEntry->rssi_stat.RSSI_CCK_Path[j] = 0;
  10243. }
  10244. RT_TRACE( COMP_SWAS, DBG_LOUD, ("odm_CCKTXPathDiversity_92C: MACID=%d, RSSI_CCK0=%d, RSSI_CCK1=%d\n",
  10245. pEntry->AssociatedMacId, pEntry->rssi_stat.RSSI_CCK_Path[0], pEntry->rssi_stat.RSSI_CCK_Path[1]));
  10246. if(pEntry->rssi_stat.RSSI_CCK_Path[0] >pEntry->rssi_stat.RSSI_CCK_Path[1])
  10247. {
  10248. pDM_PDTable->CCKTXPath = pDM_PDTable->CCKTXPath & ~(BIT(pEntry->AssociatedMacId));
  10249. RT_TRACE( COMP_SWAS, DBG_LOUD, ("odm_CCKTXPathDiversity_92C: MACID=%d Select CCK Path-0\n", pEntry->AssociatedMacId));
  10250. if(pEntry->rssi_stat.RSSI_CCK_Path[1] < MinRSSI)
  10251. {
  10252. MinRSSI = pEntry->rssi_stat.RSSI_CCK_Path[1];
  10253. DefaultRespPath = 0;
  10254. }
  10255. }
  10256. else if(pEntry->rssi_stat.RSSI_CCK_Path[0] <pEntry->rssi_stat.RSSI_CCK_Path[1])
  10257. {
  10258. pDM_PDTable->CCKTXPath = pDM_PDTable->CCKTXPath | BIT(pEntry->AssociatedMacId);
  10259. RT_TRACE( COMP_SWAS, DBG_LOUD, ("odm_CCKTXPathDiversity_92C: MACID=%d Select CCK Path-1\n", pEntry->AssociatedMacId));
  10260. if(pEntry->rssi_stat.RSSI_CCK_Path[0] < MinRSSI)
  10261. {
  10262. MinRSSI = pEntry->rssi_stat.RSSI_CCK_Path[0];
  10263. DefaultRespPath = 1;
  10264. }
  10265. }
  10266. else
  10267. {
  10268. if((pEntry->rssi_stat.RSSI_CCK_Path[0] != 0) && (pEntry->rssi_stat.RSSI_CCK_Path[0] < MinRSSI))
  10269. {
  10270. pDM_PDTable->CCKTXPath = pDM_PDTable->CCKTXPath & ~(BIT(pEntry->AssociatedMacId));
  10271. MinRSSI = pEntry->rssi_stat.RSSI_CCK_Path[1];
  10272. DefaultRespPath = 0;
  10273. RT_TRACE( COMP_SWAS, DBG_LOUD, ("odm_CCKTXPathDiversity_92C: MACID=%d Select CCK Path-0\n", pEntry->AssociatedMacId));
  10274. }
  10275. else
  10276. {
  10277. RT_TRACE( COMP_SWAS, DBG_LOUD, ("odm_CCKTXPathDiversity_92C: MACID=%d unchange CCK Path\n", pEntry->AssociatedMacId));
  10278. }
  10279. }
  10280. }
  10281. else //Follow OFDM decision
  10282. {
  10283. pDM_PDTable->CCKTXPath = (pDM_PDTable->CCKTXPath & (~(BIT(pEntry->AssociatedMacId)))) | (pDM_PDTable->OFDMTXPath & BIT(pEntry->AssociatedMacId));
  10284. RT_TRACE( COMP_SWAS, DBG_LOUD, ("odm_CCKTXPathDiversity_92C: Follow OFDM decision, MACID=%d Select CCK Path-%d\n",
  10285. pEntry->AssociatedMacId, (pDM_PDTable->CCKTXPath & BIT(pEntry->AssociatedMacId))>>(pEntry->AssociatedMacId)));
  10286. }
  10287. }
  10288. }
  10289. else
  10290. {
  10291. break;
  10292. }
  10293. }
  10294. RT_TRACE( COMP_SWAS, DBG_LOUD, ("odm_CCKTXPathDiversity_92C:MinRSSI=%d\n",MinRSSI));
  10295. if(MinRSSI == 0xFF)
  10296. DefaultRespPath = pDM_PDTable->CCKDefaultRespPath;
  10297. pDM_PDTable->CCKDefaultRespPath = DefaultRespPath;
  10298. }
  10299. VOID
  10300. odm_PathDiversityAfterLink_92C(
  10301. IN PADAPTER Adapter
  10302. )
  10303. {
  10304. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  10305. PDM_ODM_T pDM_Odm = &pHalData->DM_OutSrc;
  10306. pPD_T pDM_PDTable = &Adapter->DM_PDTable;
  10307. u1Byte DefaultRespPath=0;
  10308. if((!IS_92C_SERIAL(pHalData->VersionID)) || (pHalData->PathDivCfg != 1) || (pHalData->eRFPowerState == eRfOff))
  10309. {
  10310. if(pHalData->PathDivCfg == 0)
  10311. {
  10312. RT_TRACE( COMP_SWAS, DBG_LOUD, ("No ODM_TXPathDiversity()\n"));
  10313. }
  10314. else
  10315. {
  10316. RT_TRACE( COMP_SWAS, DBG_LOUD, ("2T ODM_TXPathDiversity()\n"));
  10317. }
  10318. return;
  10319. }
  10320. if(!odm_IsConnected_92C(Adapter))
  10321. {
  10322. RT_TRACE( COMP_SWAS, DBG_LOUD, ("ODM_TXPathDiversity(): No Connections\n"));
  10323. return;
  10324. }
  10325. if(pDM_PDTable->TrainingState == 0)
  10326. {
  10327. RT_TRACE( COMP_SWAS, DBG_LOUD, ("ODM_TXPathDiversity() ==>\n"));
  10328. odm_OFDMTXPathDiversity_92C(Adapter);
  10329. if((pDM_PDTable->CCKPathDivEnable == TRUE) && (pDM_PDTable->OFDM_Pkt_Cnt < 100))
  10330. {
  10331. //RT_TRACE( COMP_SWAS, DBG_LOUD, ("odm_CCKTXPathDiversity_92C: TrainingState=0\n"));
  10332. if(pDM_PDTable->CCK_Pkt_Cnt > 300)
  10333. pDM_PDTable->Timer = 20;
  10334. else if(pDM_PDTable->CCK_Pkt_Cnt > 100)
  10335. pDM_PDTable->Timer = 60;
  10336. else
  10337. pDM_PDTable->Timer = 250;
  10338. RT_TRACE( COMP_SWAS, DBG_LOUD, ("odm_CCKTXPathDiversity_92C: timer=%d\n",pDM_PDTable->Timer));
  10339. PHY_SetBBReg(Adapter, rCCK0_AFESetting , 0x0F000000, 0x00); // RX path = PathA
  10340. pDM_PDTable->TrainingState = 1;
  10341. pHalData->RSSI_test = TRUE;
  10342. ODM_SetTimer( pDM_Odm, &pDM_Odm->CCKPathDiversityTimer, pDM_PDTable->Timer); //ms
  10343. }
  10344. else
  10345. {
  10346. pDM_PDTable->CCKTXPath = pDM_PDTable->OFDMTXPath;
  10347. DefaultRespPath = pDM_PDTable->OFDMDefaultRespPath;
  10348. RT_TRACE( COMP_SWAS, DBG_LOUD, ("odm_SetRespPath_92C: Skip odm_CCKTXPathDiversity_92C, DefaultRespPath is OFDM\n"));
  10349. odm_SetRespPath_92C(Adapter, DefaultRespPath);
  10350. odm_ResetPathDiversity_92C(Adapter);
  10351. RT_TRACE( COMP_SWAS, DBG_LOUD, ("ODM_TXPathDiversity() <==\n"));
  10352. }
  10353. }
  10354. else if(pDM_PDTable->TrainingState == 1)
  10355. {
  10356. //RT_TRACE( COMP_SWAS, DBG_LOUD, ("odm_CCKTXPathDiversity_92C: TrainingState=1\n"));
  10357. PHY_SetBBReg(Adapter, rCCK0_AFESetting , 0x0F000000, 0x05); // RX path = PathB
  10358. pDM_PDTable->TrainingState = 2;
  10359. ODM_SetTimer( pDM_Odm, &pDM_Odm->CCKPathDiversityTimer, pDM_PDTable->Timer); //ms
  10360. }
  10361. else
  10362. {
  10363. //RT_TRACE( COMP_SWAS, DBG_LOUD, ("odm_CCKTXPathDiversity_92C: TrainingState=2\n"));
  10364. pDM_PDTable->TrainingState = 0;
  10365. odm_CCKTXPathDiversity_92C(Adapter);
  10366. if(pDM_PDTable->OFDM_Pkt_Cnt != 0)
  10367. {
  10368. DefaultRespPath = pDM_PDTable->OFDMDefaultRespPath;
  10369. RT_TRACE( COMP_SWAS, DBG_LOUD, ("odm_SetRespPath_92C: DefaultRespPath is OFDM\n"));
  10370. }
  10371. else
  10372. {
  10373. DefaultRespPath = pDM_PDTable->CCKDefaultRespPath;
  10374. RT_TRACE( COMP_SWAS, DBG_LOUD, ("odm_SetRespPath_92C: DefaultRespPath is CCK\n"));
  10375. }
  10376. odm_SetRespPath_92C(Adapter, DefaultRespPath);
  10377. odm_ResetPathDiversity_92C(Adapter);
  10378. RT_TRACE( COMP_SWAS, DBG_LOUD, ("ODM_TXPathDiversity() <==\n"));
  10379. }
  10380. }
  10381. VOID
  10382. odm_CCKTXPathDiversityCallback(
  10383. PRT_TIMER pTimer
  10384. )
  10385. {
  10386. #if USE_WORKITEM
  10387. PADAPTER Adapter = (PADAPTER)pTimer->Adapter;
  10388. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  10389. PDM_ODM_T pDM_Odm = &pHalData->DM_OutSrc;
  10390. #else
  10391. PADAPTER Adapter = (PADAPTER)pTimer->Adapter;
  10392. #endif
  10393. #if DEV_BUS_TYPE==RT_PCI_INTERFACE
  10394. #if USE_WORKITEM
  10395. PlatformScheduleWorkItem(&pDM_Odm->CCKPathDiversityWorkitem);
  10396. #else
  10397. odm_PathDiversityAfterLink_92C(Adapter);
  10398. #endif
  10399. #else
  10400. PlatformScheduleWorkItem(&pDM_Odm->CCKPathDiversityWorkitem);
  10401. #endif
  10402. }
  10403. VOID
  10404. odm_CCKTXPathDiversityWorkItemCallback(
  10405. IN PVOID pContext
  10406. )
  10407. {
  10408. PADAPTER Adapter = (PADAPTER)pContext;
  10409. odm_CCKTXPathDiversity_92C(Adapter);
  10410. }
  10411. VOID
  10412. ODM_CCKPathDiversityChkPerPktRssi(
  10413. PADAPTER Adapter,
  10414. BOOLEAN bIsDefPort,
  10415. BOOLEAN bMatchBSSID,
  10416. PRT_WLAN_STA pEntry,
  10417. PRT_RFD pRfd,
  10418. pu1Byte pDesc
  10419. )
  10420. {
  10421. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  10422. BOOLEAN bCount = FALSE;
  10423. pPD_T pDM_PDTable = &Adapter->DM_PDTable;
  10424. //BOOLEAN isCCKrate = RX_HAL_IS_CCK_RATE_92C(pDesc);
  10425. #if DEV_BUS_TYPE != RT_SDIO_INTERFACE
  10426. BOOLEAN isCCKrate = RX_HAL_IS_CCK_RATE(Adapter, pDesc);
  10427. #else //below code would be removed if we have verified SDIO
  10428. BOOLEAN isCCKrate = IS_HARDWARE_TYPE_8188E(Adapter) ? RX_HAL_IS_CCK_RATE_88E(pDesc) : RX_HAL_IS_CCK_RATE_92C(pDesc);
  10429. #endif
  10430. if((pHalData->PathDivCfg != 1) || (pHalData->RSSI_test == FALSE))
  10431. return;
  10432. if(pHalData->RSSI_target==NULL && bIsDefPort && bMatchBSSID)
  10433. bCount = TRUE;
  10434. else if(pHalData->RSSI_target!=NULL && pEntry!=NULL && pHalData->RSSI_target==pEntry)
  10435. bCount = TRUE;
  10436. if(bCount && isCCKrate)
  10437. {
  10438. if(pDM_PDTable->TrainingState == 1 )
  10439. {
  10440. if(pEntry)
  10441. {
  10442. if(pEntry->rssi_stat.RSSI_CCK_Path_cnt[0] != 0)
  10443. pEntry->rssi_stat.RSSI_CCK_Path[0] += pRfd->Status.RxPWDBAll;
  10444. pEntry->rssi_stat.RSSI_CCK_Path_cnt[0]++;
  10445. }
  10446. else
  10447. {
  10448. if(pDM_PDTable->RSSI_CCK_Path_cnt[0] != 0)
  10449. pDM_PDTable->RSSI_CCK_Path[0] += pRfd->Status.RxPWDBAll;
  10450. pDM_PDTable->RSSI_CCK_Path_cnt[0]++;
  10451. }
  10452. }
  10453. else if(pDM_PDTable->TrainingState == 2 )
  10454. {
  10455. if(pEntry)
  10456. {
  10457. if(pEntry->rssi_stat.RSSI_CCK_Path_cnt[1] != 0)
  10458. pEntry->rssi_stat.RSSI_CCK_Path[1] += pRfd->Status.RxPWDBAll;
  10459. pEntry->rssi_stat.RSSI_CCK_Path_cnt[1]++;
  10460. }
  10461. else
  10462. {
  10463. if(pDM_PDTable->RSSI_CCK_Path_cnt[1] != 0)
  10464. pDM_PDTable->RSSI_CCK_Path[1] += pRfd->Status.RxPWDBAll;
  10465. pDM_PDTable->RSSI_CCK_Path_cnt[1]++;
  10466. }
  10467. }
  10468. }
  10469. }
  10470. BOOLEAN
  10471. ODM_PathDiversityBeforeLink92C(
  10472. //IN PADAPTER Adapter
  10473. IN PDM_ODM_T pDM_Odm
  10474. )
  10475. {
  10476. #if (RT_MEM_SIZE_LEVEL != RT_MEM_SIZE_MINIMUM)
  10477. PADAPTER Adapter = pDM_Odm->Adapter;
  10478. HAL_DATA_TYPE* pHalData = NULL;
  10479. PMGNT_INFO pMgntInfo = NULL;
  10480. //pSWAT_T pDM_SWAT_Table = &Adapter->DM_SWAT_Table;
  10481. pPD_T pDM_PDTable = NULL;
  10482. s1Byte Score = 0;
  10483. PRT_WLAN_BSS pTmpBssDesc;
  10484. PRT_WLAN_BSS pTestBssDesc;
  10485. u1Byte target_chnl = 0;
  10486. u1Byte index;
  10487. if (pDM_Odm->Adapter == NULL) //For BSOD when plug/unplug fast. //By YJ,120413
  10488. { // The ODM structure is not initialized.
  10489. return FALSE;
  10490. }
  10491. pHalData = GET_HAL_DATA(Adapter);
  10492. pMgntInfo = &Adapter->MgntInfo;
  10493. pDM_PDTable = &Adapter->DM_PDTable;
  10494. // Condition that does not need to use path diversity.
  10495. if((!IS_92C_SERIAL(pHalData->VersionID)) || (pHalData->PathDivCfg!=1) || pMgntInfo->AntennaTest )
  10496. {
  10497. RT_TRACE(COMP_SWAS, DBG_LOUD,
  10498. ("ODM_PathDiversityBeforeLink92C(): No PathDiv Mechanism before link.\n"));
  10499. return FALSE;
  10500. }
  10501. // Since driver is going to set BB register, it shall check if there is another thread controlling BB/RF.
  10502. PlatformAcquireSpinLock(Adapter, RT_RF_STATE_SPINLOCK);
  10503. if(pHalData->eRFPowerState!=eRfOn || pMgntInfo->RFChangeInProgress || pMgntInfo->bMediaConnect)
  10504. {
  10505. PlatformReleaseSpinLock(Adapter, RT_RF_STATE_SPINLOCK);
  10506. RT_TRACE(COMP_SWAS, DBG_LOUD,
  10507. ("ODM_PathDiversityBeforeLink92C(): RFChangeInProgress(%x), eRFPowerState(%x)\n",
  10508. pMgntInfo->RFChangeInProgress,
  10509. pHalData->eRFPowerState));
  10510. //pDM_SWAT_Table->SWAS_NoLink_State = 0;
  10511. pDM_PDTable->PathDiv_NoLink_State = 0;
  10512. return FALSE;
  10513. }
  10514. else
  10515. {
  10516. PlatformReleaseSpinLock(Adapter, RT_RF_STATE_SPINLOCK);
  10517. }
  10518. //1 Run AntDiv mechanism "Before Link" part.
  10519. //if(pDM_SWAT_Table->SWAS_NoLink_State == 0)
  10520. if(pDM_PDTable->PathDiv_NoLink_State == 0)
  10521. {
  10522. //1 Prepare to do Scan again to check current antenna state.
  10523. // Set check state to next step.
  10524. //pDM_SWAT_Table->SWAS_NoLink_State = 1;
  10525. pDM_PDTable->PathDiv_NoLink_State = 1;
  10526. // Copy Current Scan list.
  10527. Adapter->MgntInfo.tmpNumBssDesc = pMgntInfo->NumBssDesc;
  10528. PlatformMoveMemory((PVOID)Adapter->MgntInfo.tmpbssDesc, (PVOID)pMgntInfo->bssDesc, sizeof(RT_WLAN_BSS)*MAX_BSS_DESC);
  10529. // Switch Antenna to another one.
  10530. if(pDM_PDTable->DefaultRespPath == 0)
  10531. {
  10532. PHY_SetBBReg(Adapter, rCCK0_AFESetting , 0x0F000000, 0x05); // TRX path = PathB
  10533. odm_SetRespPath_92C(Adapter, 1);
  10534. pDM_PDTable->OFDMTXPath = 0xFFFFFFFF;
  10535. pDM_PDTable->CCKTXPath = 0xFFFFFFFF;
  10536. }
  10537. else
  10538. {
  10539. PHY_SetBBReg(Adapter, rCCK0_AFESetting , 0x0F000000, 0x00); // TRX path = PathA
  10540. odm_SetRespPath_92C(Adapter, 0);
  10541. pDM_PDTable->OFDMTXPath = 0x0;
  10542. pDM_PDTable->CCKTXPath = 0x0;
  10543. }
  10544. #if 0
  10545. pDM_SWAT_Table->PreAntenna = pDM_SWAT_Table->CurAntenna;
  10546. pDM_SWAT_Table->CurAntenna = (pDM_SWAT_Table->CurAntenna==Antenna_A)?Antenna_B:Antenna_A;
  10547. RT_TRACE(COMP_SWAS, DBG_LOUD,
  10548. ("ODM_SwAntDivCheckBeforeLink8192C: Change to Ant(%s) for testing.\n", (pDM_SWAT_Table->CurAntenna==Antenna_A)?"A":"B"));
  10549. //PHY_SetBBReg(Adapter, rFPGA0_XA_RFInterfaceOE, 0x300, DM_SWAT_Table.CurAntenna);
  10550. pDM_SWAT_Table->SWAS_NoLink_BK_Reg860 = ((pDM_SWAT_Table->SWAS_NoLink_BK_Reg860 & 0xfffffcff) | (pDM_SWAT_Table->CurAntenna<<8));
  10551. PHY_SetBBReg(Adapter, rFPGA0_XA_RFInterfaceOE, bMaskDWord, pDM_SWAT_Table->SWAS_NoLink_BK_Reg860);
  10552. #endif
  10553. // Go back to scan function again.
  10554. RT_TRACE(COMP_SWAS, DBG_LOUD, ("ODM_PathDiversityBeforeLink92C: Scan one more time\n"));
  10555. pMgntInfo->ScanStep=0;
  10556. target_chnl = odm_SwAntDivSelectChkChnl(Adapter);
  10557. odm_SwAntDivConsructChkScanChnl(Adapter, target_chnl);
  10558. CHNL_ReleaseOpLock(Adapter);
  10559. PlatformSetTimer(Adapter, &pMgntInfo->ScanTimer, 5);
  10560. return TRUE;
  10561. }
  10562. else
  10563. {
  10564. //1 ScanComple() is called after antenna swiched.
  10565. //1 Check scan result and determine which antenna is going
  10566. //1 to be used.
  10567. for(index=0; index<Adapter->MgntInfo.tmpNumBssDesc; index++)
  10568. {
  10569. pTmpBssDesc = &(Adapter->MgntInfo.tmpbssDesc[index]);
  10570. pTestBssDesc = &(pMgntInfo->bssDesc[index]);
  10571. if(PlatformCompareMemory(pTestBssDesc->bdBssIdBuf, pTmpBssDesc->bdBssIdBuf, 6)!=0)
  10572. {
  10573. RT_TRACE(COMP_SWAS, DBG_LOUD, ("ODM_PathDiversityBeforeLink92C(): ERROR!! This shall not happen.\n"));
  10574. continue;
  10575. }
  10576. if(pTmpBssDesc->RecvSignalPower > pTestBssDesc->RecvSignalPower)
  10577. {
  10578. RT_TRACE(COMP_SWAS, DBG_LOUD, ("ODM_PathDiversityBeforeLink92C: Compare scan entry: Score++\n"));
  10579. RT_PRINT_STR(COMP_SWAS, DBG_LOUD, "SSID: ", pTestBssDesc->bdSsIdBuf, pTestBssDesc->bdSsIdLen);
  10580. RT_TRACE(COMP_SWAS, DBG_LOUD, ("Original: %d, Test: %d\n", pTmpBssDesc->RecvSignalPower, pTestBssDesc->RecvSignalPower));
  10581. Score++;
  10582. PlatformMoveMemory(pTestBssDesc, pTmpBssDesc, sizeof(RT_WLAN_BSS));
  10583. }
  10584. else if(pTmpBssDesc->RecvSignalPower < pTestBssDesc->RecvSignalPower)
  10585. {
  10586. RT_TRACE(COMP_SWAS, DBG_LOUD, ("ODM_PathDiversityBeforeLink92C: Compare scan entry: Score--\n"));
  10587. RT_PRINT_STR(COMP_SWAS, DBG_LOUD, "SSID: ", pTestBssDesc->bdSsIdBuf, pTestBssDesc->bdSsIdLen);
  10588. RT_TRACE(COMP_SWAS, DBG_LOUD, ("Original: %d, Test: %d\n", pTmpBssDesc->RecvSignalPower, pTestBssDesc->RecvSignalPower));
  10589. Score--;
  10590. }
  10591. }
  10592. if(pMgntInfo->NumBssDesc!=0 && Score<=0)
  10593. {
  10594. RT_TRACE(COMP_SWAS, DBG_LOUD,
  10595. ("ODM_PathDiversityBeforeLink92C(): DefaultRespPath=%d\n", pDM_PDTable->DefaultRespPath));
  10596. //pDM_SWAT_Table->PreAntenna = pDM_SWAT_Table->CurAntenna;
  10597. }
  10598. else
  10599. {
  10600. RT_TRACE(COMP_SWAS, DBG_LOUD,
  10601. ("ODM_PathDiversityBeforeLink92C(): DefaultRespPath=%d\n", pDM_PDTable->DefaultRespPath));
  10602. if(pDM_PDTable->DefaultRespPath == 0)
  10603. {
  10604. pDM_PDTable->OFDMTXPath = 0xFFFFFFFF;
  10605. pDM_PDTable->CCKTXPath = 0xFFFFFFFF;
  10606. odm_SetRespPath_92C(Adapter, 1);
  10607. }
  10608. else
  10609. {
  10610. pDM_PDTable->OFDMTXPath = 0x0;
  10611. pDM_PDTable->CCKTXPath = 0x0;
  10612. odm_SetRespPath_92C(Adapter, 0);
  10613. }
  10614. PHY_SetBBReg(Adapter, rCCK0_AFESetting , 0x0F000000, 0x01); // RX path = PathAB
  10615. //pDM_SWAT_Table->CurAntenna = pDM_SWAT_Table->PreAntenna;
  10616. //PHY_SetBBReg(Adapter, rFPGA0_XA_RFInterfaceOE, 0x300, DM_SWAT_Table.CurAntenna);
  10617. //pDM_SWAT_Table->SWAS_NoLink_BK_Reg860 = ((pDM_SWAT_Table->SWAS_NoLink_BK_Reg860 & 0xfffffcff) | (pDM_SWAT_Table->CurAntenna<<8));
  10618. //PHY_SetBBReg(Adapter, rFPGA0_XA_RFInterfaceOE, bMaskDWord, pDM_SWAT_Table->SWAS_NoLink_BK_Reg860);
  10619. }
  10620. // Check state reset to default and wait for next time.
  10621. //pDM_SWAT_Table->SWAS_NoLink_State = 0;
  10622. pDM_PDTable->PathDiv_NoLink_State = 0;
  10623. return FALSE;
  10624. }
  10625. #else
  10626. return FALSE;
  10627. #endif
  10628. }
  10629. //Neil Chen---2011--06--22
  10630. //----92D Path Diversity----//
  10631. //#ifdef PathDiv92D
  10632. //==================================
  10633. //3 Path Diversity
  10634. //==================================
  10635. //
  10636. // 20100514 Luke/Joseph:
  10637. // Add new function for antenna diversity after link.
  10638. // This is the main function of antenna diversity after link.
  10639. // This function is called in HalDmWatchDog() and ODM_SwAntDivChkAntSwitchCallback().
  10640. // HalDmWatchDog() calls this function with SWAW_STEP_PEAK to initialize the antenna test.
  10641. // In SWAW_STEP_PEAK, another antenna and a 500ms timer will be set for testing.
  10642. // After 500ms, ODM_SwAntDivChkAntSwitchCallback() calls this function to compare the signal just
  10643. // listened on the air with the RSSI of original antenna.
  10644. // It chooses the antenna with better RSSI.
  10645. // There is also a aged policy for error trying. Each error trying will cost more 5 seconds waiting
  10646. // penalty to get next try.
  10647. //
  10648. //
  10649. // 20100503 Joseph:
  10650. // Add new function SwAntDivCheck8192C().
  10651. // This is the main function of Antenna diversity function before link.
  10652. // Mainly, it just retains last scan result and scan again.
  10653. // After that, it compares the scan result to see which one gets better RSSI.
  10654. // It selects antenna with better receiving power and returns better scan result.
  10655. //
  10656. //
  10657. // 20100514 Luke/Joseph:
  10658. // This function is used to gather the RSSI information for antenna testing.
  10659. // It selects the RSSI of the peer STA that we want to know.
  10660. //
  10661. VOID
  10662. ODM_PathDivChkPerPktRssi(
  10663. PADAPTER Adapter,
  10664. BOOLEAN bIsDefPort,
  10665. BOOLEAN bMatchBSSID,
  10666. PRT_WLAN_STA pEntry,
  10667. PRT_RFD pRfd
  10668. )
  10669. {
  10670. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  10671. BOOLEAN bCount = FALSE;
  10672. PDM_ODM_T pDM_Odm = &pHalData->DM_OutSrc;
  10673. pSWAT_T pDM_SWAT_Table = &pDM_Odm->DM_SWAT_Table;
  10674. if(pHalData->RSSI_target==NULL && bIsDefPort && bMatchBSSID)
  10675. bCount = TRUE;
  10676. else if(pHalData->RSSI_target!=NULL && pEntry!=NULL && pHalData->RSSI_target==pEntry)
  10677. bCount = TRUE;
  10678. if(bCount)
  10679. {
  10680. //1 RSSI for SW Antenna Switch
  10681. if(pDM_SWAT_Table->CurAntenna == MAIN_ANT)
  10682. {
  10683. pHalData->RSSI_sum_A += pRfd->Status.RxPWDBAll;
  10684. pHalData->RSSI_cnt_A++;
  10685. }
  10686. else
  10687. {
  10688. pHalData->RSSI_sum_B += pRfd->Status.RxPWDBAll;
  10689. pHalData->RSSI_cnt_B++;
  10690. }
  10691. }
  10692. }
  10693. //
  10694. // 20100514 Luke/Joseph:
  10695. // Add new function to reset antenna diversity state after link.
  10696. //
  10697. VOID
  10698. ODM_PathDivRestAfterLink(
  10699. IN PDM_ODM_T pDM_Odm
  10700. )
  10701. {
  10702. PADAPTER Adapter=pDM_Odm->Adapter;
  10703. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  10704. pSWAT_T pDM_SWAT_Table = &pDM_Odm->DM_SWAT_Table;
  10705. pHalData->RSSI_cnt_A = 0;
  10706. pHalData->RSSI_cnt_B = 0;
  10707. pHalData->RSSI_test = FALSE;
  10708. pDM_SWAT_Table->try_flag = 0x0; // NOT 0xff
  10709. pDM_SWAT_Table->RSSI_Trying = 0;
  10710. pDM_SWAT_Table->SelectAntennaMap=0xAA;
  10711. pDM_SWAT_Table->CurAntenna = MAIN_ANT;
  10712. }
  10713. //
  10714. // 20100514 Luke/Joseph:
  10715. // Callback function for 500ms antenna test trying.
  10716. //
  10717. VOID
  10718. odm_PathDivChkAntSwitchCallback(
  10719. PRT_TIMER pTimer
  10720. )
  10721. {
  10722. PADAPTER Adapter = (PADAPTER)pTimer->Adapter;
  10723. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  10724. PDM_ODM_T pDM_Odm = &pHalData->DM_OutSrc;
  10725. #if DEV_BUS_TYPE==RT_PCI_INTERFACE
  10726. #if USE_WORKITEM
  10727. PlatformScheduleWorkItem(&pDM_Odm->PathDivSwitchWorkitem);
  10728. #else
  10729. odm_PathDivChkAntSwitch(pDM_Odm);
  10730. #endif
  10731. #else
  10732. PlatformScheduleWorkItem(&pDM_Odm->PathDivSwitchWorkitem);
  10733. #endif
  10734. //odm_SwAntDivChkAntSwitch(Adapter, SWAW_STEP_DETERMINE);
  10735. }
  10736. VOID
  10737. odm_PathDivChkAntSwitchWorkitemCallback(
  10738. IN PVOID pContext
  10739. )
  10740. {
  10741. PADAPTER pAdapter = (PADAPTER)pContext;
  10742. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(pAdapter);
  10743. PDM_ODM_T pDM_Odm = &pHalData->DM_OutSrc;
  10744. odm_PathDivChkAntSwitch(pDM_Odm);
  10745. }
  10746. //MAC0_ACCESS_PHY1
  10747. // 2011-06-22 Neil Chen & Gary Hsin
  10748. // Refer to Jr.Luke's SW ANT DIV
  10749. // 92D Path Diversity Main function
  10750. // refer to 88C software antenna diversity
  10751. //
  10752. VOID
  10753. odm_PathDivChkAntSwitch(
  10754. PDM_ODM_T pDM_Odm
  10755. //PADAPTER Adapter,
  10756. //u1Byte Step
  10757. )
  10758. {
  10759. PADAPTER Adapter = pDM_Odm->Adapter;
  10760. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  10761. PMGNT_INFO pMgntInfo = &Adapter->MgntInfo;
  10762. pSWAT_T pDM_SWAT_Table = &pDM_Odm->DM_SWAT_Table;
  10763. s4Byte curRSSI=100, RSSI_A, RSSI_B;
  10764. u1Byte nextAntenna=AUX_ANT;
  10765. static u8Byte lastTxOkCnt=0, lastRxOkCnt=0;
  10766. u8Byte curTxOkCnt, curRxOkCnt;
  10767. static u8Byte TXByteCnt_A=0, TXByteCnt_B=0, RXByteCnt_A=0, RXByteCnt_B=0;
  10768. u8Byte CurByteCnt=0, PreByteCnt=0;
  10769. static u1Byte TrafficLoad = TRAFFIC_LOW;
  10770. u1Byte Score_A=0, Score_B=0;
  10771. u1Byte i=0x0;
  10772. // Neil Chen
  10773. static u1Byte pathdiv_para=0x0;
  10774. static u1Byte switchfirsttime=0x00;
  10775. // u1Byte regB33 = (u1Byte) PHY_QueryBBReg(Adapter, 0xB30,BIT27);
  10776. u1Byte regB33 = (u1Byte)ODM_GetBBReg(pDM_Odm, PATHDIV_REG, BIT27);
  10777. //u1Byte reg637 =0x0;
  10778. static u1Byte fw_value=0x0;
  10779. //u8Byte curTxOkCnt_tmp, curRxOkCnt_tmp;
  10780. PADAPTER BuddyAdapter = Adapter->BuddyAdapter; // another adapter MAC
  10781. // Path Diversity //Neil Chen--2011--06--22
  10782. //u1Byte PathDiv_Trigger = (u1Byte) PHY_QueryBBReg(Adapter, 0xBA0,BIT31);
  10783. u1Byte PathDiv_Trigger = (u1Byte) ODM_GetBBReg(pDM_Odm, PATHDIV_TRI,BIT31);
  10784. u1Byte PathDiv_Enable = pHalData->bPathDiv_Enable;
  10785. //DbgPrint("Path Div PG Value:%x \n",PathDiv_Enable);
  10786. if((BuddyAdapter==NULL)||(!PathDiv_Enable)||(PathDiv_Trigger)||(pHalData->CurrentBandType == BAND_ON_2_4G))
  10787. {
  10788. return;
  10789. }
  10790. ODM_RT_TRACE(pDM_Odm,ODM_COMP_PATH_DIV, ODM_DBG_LOUD,("===================>odm_PathDivChkAntSwitch()\n"));
  10791. // The first time to switch path excluding 2nd, 3rd, ....etc....
  10792. if(switchfirsttime==0)
  10793. {
  10794. if(regB33==0)
  10795. {
  10796. pDM_SWAT_Table->CurAntenna = MAIN_ANT; // Default MAC0_5G-->Path A (current antenna)
  10797. }
  10798. }
  10799. // Condition that does not need to use antenna diversity.
  10800. if(pDM_Odm->SupportICType != ODM_RTL8192D)
  10801. {
  10802. ODM_RT_TRACE(pDM_Odm,ODM_COMP_PATH_DIV, ODM_DBG_LOUD, ("odm_PathDiversityMechanims(): No PathDiv Mechanism.\n"));
  10803. return;
  10804. }
  10805. // Radio off: Status reset to default and return.
  10806. if(pHalData->eRFPowerState==eRfOff)
  10807. {
  10808. //ODM_SwAntDivRestAfterLink(Adapter);
  10809. return;
  10810. }
  10811. /*
  10812. // Handling step mismatch condition.
  10813. // Peak step is not finished at last time. Recover the variable and check again.
  10814. if( Step != pDM_SWAT_Table->try_flag )
  10815. {
  10816. ODM_SwAntDivRestAfterLink(Adapter);
  10817. } */
  10818. if(pDM_SWAT_Table->try_flag == 0xff)
  10819. {
  10820. // Select RSSI checking target
  10821. if(pMgntInfo->mAssoc && !ACTING_AS_AP(Adapter))
  10822. {
  10823. // Target: Infrastructure mode AP.
  10824. pHalData->RSSI_target = NULL;
  10825. ODM_RT_TRACE(pDM_Odm,ODM_COMP_PATH_DIV, ODM_DBG_LOUD, ("odm_PathDivMechanism(): RSSI_target is DEF AP!\n"));
  10826. }
  10827. else
  10828. {
  10829. u1Byte index = 0;
  10830. PRT_WLAN_STA pEntry = NULL;
  10831. PADAPTER pTargetAdapter = NULL;
  10832. if( pMgntInfo->mIbss || ACTING_AS_AP(Adapter) )
  10833. {
  10834. // Target: AP/IBSS peer.
  10835. pTargetAdapter = Adapter;
  10836. }
  10837. else if(IsAPModeExist(Adapter) && GetFirstExtAdapter(Adapter) != NULL)
  10838. {
  10839. // Target: VWIFI peer.
  10840. pTargetAdapter = GetFirstExtAdapter(Adapter);
  10841. }
  10842. if(pTargetAdapter != NULL)
  10843. {
  10844. for(index=0; index<ODM_ASSOCIATE_ENTRY_NUM; index++)
  10845. {
  10846. pEntry = AsocEntry_EnumStation(pTargetAdapter, index);
  10847. if(pEntry != NULL)
  10848. {
  10849. if(pEntry->bAssociated)
  10850. break;
  10851. }
  10852. }
  10853. }
  10854. if(pEntry == NULL)
  10855. {
  10856. ODM_PathDivRestAfterLink(pDM_Odm);
  10857. ODM_RT_TRACE(pDM_Odm,ODM_COMP_PATH_DIV, ODM_DBG_LOUD, ("odm_SwAntDivChkAntSwitch(): No Link.\n"));
  10858. return;
  10859. }
  10860. else
  10861. {
  10862. pHalData->RSSI_target = pEntry;
  10863. ODM_RT_TRACE(pDM_Odm,ODM_COMP_PATH_DIV, ODM_DBG_LOUD, ("odm_SwAntDivChkAntSwitch(): RSSI_target is PEER STA\n"));
  10864. }
  10865. }
  10866. pHalData->RSSI_cnt_A = 0;
  10867. pHalData->RSSI_cnt_B = 0;
  10868. pDM_SWAT_Table->try_flag = 0;
  10869. ODM_RT_TRACE(pDM_Odm,ODM_COMP_PATH_DIV, ODM_DBG_LOUD, ("odm_SwAntDivChkAntSwitch(): Set try_flag to 0 prepare for peak!\n"));
  10870. return;
  10871. }
  10872. else
  10873. {
  10874. // 1st step
  10875. curTxOkCnt = Adapter->TxStats.NumTxBytesUnicast - lastTxOkCnt;
  10876. curRxOkCnt = Adapter->RxStats.NumRxBytesUnicast - lastRxOkCnt;
  10877. lastTxOkCnt = Adapter->TxStats.NumTxBytesUnicast;
  10878. lastRxOkCnt = Adapter->RxStats.NumRxBytesUnicast;
  10879. if(pDM_SWAT_Table->try_flag == 1) // Training State
  10880. {
  10881. if(pDM_SWAT_Table->CurAntenna == MAIN_ANT)
  10882. {
  10883. TXByteCnt_A += curTxOkCnt;
  10884. RXByteCnt_A += curRxOkCnt;
  10885. }
  10886. else
  10887. {
  10888. TXByteCnt_B += curTxOkCnt;
  10889. RXByteCnt_B += curRxOkCnt;
  10890. }
  10891. nextAntenna = (pDM_SWAT_Table->CurAntenna == MAIN_ANT)? AUX_ANT : MAIN_ANT;
  10892. pDM_SWAT_Table->RSSI_Trying--;
  10893. ODM_RT_TRACE(pDM_Odm,ODM_COMP_PATH_DIV, ODM_DBG_LOUD, ("=PATH DIV=: RSSI_Trying = %d\n",pDM_SWAT_Table->RSSI_Trying));
  10894. if(pDM_SWAT_Table->RSSI_Trying == 0)
  10895. {
  10896. CurByteCnt = (pDM_SWAT_Table->CurAntenna == MAIN_ANT)? (TXByteCnt_A+RXByteCnt_A) : (TXByteCnt_B+RXByteCnt_B);
  10897. PreByteCnt = (pDM_SWAT_Table->CurAntenna == MAIN_ANT)? (TXByteCnt_B+RXByteCnt_B) : (TXByteCnt_A+RXByteCnt_A);
  10898. if(TrafficLoad == TRAFFIC_HIGH)
  10899. {
  10900. //CurByteCnt = PlatformDivision64(CurByteCnt, 9);
  10901. PreByteCnt =PreByteCnt*9;
  10902. }
  10903. else if(TrafficLoad == TRAFFIC_LOW)
  10904. {
  10905. //CurByteCnt = PlatformDivision64(CurByteCnt, 2);
  10906. PreByteCnt =PreByteCnt*2;
  10907. }
  10908. if(pHalData->RSSI_cnt_A > 0)
  10909. RSSI_A = pHalData->RSSI_sum_A/pHalData->RSSI_cnt_A;
  10910. else
  10911. RSSI_A = 0;
  10912. if(pHalData->RSSI_cnt_B > 0)
  10913. RSSI_B = pHalData->RSSI_sum_B/pHalData->RSSI_cnt_B;
  10914. else
  10915. RSSI_B = 0;
  10916. curRSSI = (pDM_SWAT_Table->CurAntenna == MAIN_ANT)? RSSI_A : RSSI_B;
  10917. pDM_SWAT_Table->PreRSSI = (pDM_SWAT_Table->CurAntenna == MAIN_ANT)? RSSI_B : RSSI_A;
  10918. ODM_RT_TRACE(pDM_Odm,ODM_COMP_PATH_DIV, ODM_DBG_LOUD, ("=PATH DIV=: PreRSSI = %d, CurRSSI = %d\n",pDM_SWAT_Table->PreRSSI, curRSSI));
  10919. ODM_RT_TRACE(pDM_Odm,ODM_COMP_PATH_DIV, ODM_DBG_LOUD, ("=PATH DIV=: preAntenna= %s, curAntenna= %s \n",
  10920. (pDM_SWAT_Table->PreAntenna == MAIN_ANT?"MAIN":"AUX"), (pDM_SWAT_Table->CurAntenna == MAIN_ANT?"MAIN":"AUX")));
  10921. ODM_RT_TRACE(pDM_Odm,ODM_COMP_PATH_DIV, ODM_DBG_LOUD, ("=PATH DIV=: RSSI_A= %d, RSSI_cnt_A = %d, RSSI_B= %d, RSSI_cnt_B = %d\n",
  10922. RSSI_A, pHalData->RSSI_cnt_A, RSSI_B, pHalData->RSSI_cnt_B));
  10923. }
  10924. }
  10925. else // try_flag=0
  10926. {
  10927. if(pHalData->RSSI_cnt_A > 0)
  10928. RSSI_A = pHalData->RSSI_sum_A/pHalData->RSSI_cnt_A;
  10929. else
  10930. RSSI_A = 0;
  10931. if(pHalData->RSSI_cnt_B > 0)
  10932. RSSI_B = pHalData->RSSI_sum_B/pHalData->RSSI_cnt_B;
  10933. else
  10934. RSSI_B = 0;
  10935. curRSSI = (pDM_SWAT_Table->CurAntenna == MAIN_ANT)? RSSI_A : RSSI_B;
  10936. pDM_SWAT_Table->PreRSSI = (pDM_SWAT_Table->PreAntenna == MAIN_ANT)? RSSI_A : RSSI_B;
  10937. ODM_RT_TRACE(pDM_Odm,ODM_COMP_PATH_DIV, ODM_DBG_LOUD, ("=PATH DIV=: PreRSSI = %d, CurRSSI = %d\n", pDM_SWAT_Table->PreRSSI, curRSSI));
  10938. ODM_RT_TRACE(pDM_Odm,ODM_COMP_PATH_DIV, ODM_DBG_LOUD, ("=PATH DIV=: preAntenna= %s, curAntenna= %s \n",
  10939. (pDM_SWAT_Table->PreAntenna == MAIN_ANT?"MAIN":"AUX"), (pDM_SWAT_Table->CurAntenna == MAIN_ANT?"MAIN":"AUX")));
  10940. ODM_RT_TRACE(pDM_Odm,ODM_COMP_PATH_DIV, ODM_DBG_LOUD, ("=PATH DIV=: RSSI_A= %d, RSSI_cnt_A = %d, RSSI_B= %d, RSSI_cnt_B = %d\n",
  10941. RSSI_A, pHalData->RSSI_cnt_A, RSSI_B, pHalData->RSSI_cnt_B));
  10942. //RT_TRACE(COMP_SWAS, DBG_LOUD, ("Ekul:curTxOkCnt = %d\n", curTxOkCnt));
  10943. //RT_TRACE(COMP_SWAS, DBG_LOUD, ("Ekul:curRxOkCnt = %d\n", curRxOkCnt));
  10944. }
  10945. //1 Trying State
  10946. if((pDM_SWAT_Table->try_flag == 1)&&(pDM_SWAT_Table->RSSI_Trying == 0))
  10947. {
  10948. if(pDM_SWAT_Table->TestMode == TP_MODE)
  10949. {
  10950. ODM_RT_TRACE(pDM_Odm,ODM_COMP_PATH_DIV, ODM_DBG_LOUD, ("=PATH=: TestMode = TP_MODE"));
  10951. ODM_RT_TRACE(pDM_Odm,ODM_COMP_PATH_DIV, ODM_DBG_LOUD, ("=PATH= TRY:CurByteCnt = %"i64fmt"d,", CurByteCnt));
  10952. ODM_RT_TRACE(pDM_Odm,ODM_COMP_PATH_DIV, ODM_DBG_LOUD, ("=PATH= TRY:PreByteCnt = %"i64fmt"d\n",PreByteCnt));
  10953. if(CurByteCnt < PreByteCnt)
  10954. {
  10955. if(pDM_SWAT_Table->CurAntenna == MAIN_ANT)
  10956. pDM_SWAT_Table->SelectAntennaMap=pDM_SWAT_Table->SelectAntennaMap<<1;
  10957. else
  10958. pDM_SWAT_Table->SelectAntennaMap=(pDM_SWAT_Table->SelectAntennaMap<<1)+1;
  10959. }
  10960. else
  10961. {
  10962. if(pDM_SWAT_Table->CurAntenna == MAIN_ANT)
  10963. pDM_SWAT_Table->SelectAntennaMap=(pDM_SWAT_Table->SelectAntennaMap<<1)+1;
  10964. else
  10965. pDM_SWAT_Table->SelectAntennaMap=pDM_SWAT_Table->SelectAntennaMap<<1;
  10966. }
  10967. for (i= 0; i<8; i++)
  10968. {
  10969. if(((pDM_SWAT_Table->SelectAntennaMap>>i)&BIT0) == 1)
  10970. Score_A++;
  10971. else
  10972. Score_B++;
  10973. }
  10974. ODM_RT_TRACE(pDM_Odm,ODM_COMP_PATH_DIV, ODM_DBG_LOUD, ("SelectAntennaMap=%x\n ",pDM_SWAT_Table->SelectAntennaMap));
  10975. ODM_RT_TRACE(pDM_Odm,ODM_COMP_PATH_DIV, ODM_DBG_LOUD, ("=PATH=: Score_A=%d, Score_B=%d\n", Score_A, Score_B));
  10976. if(pDM_SWAT_Table->CurAntenna == MAIN_ANT)
  10977. {
  10978. nextAntenna = (Score_A >= Score_B)?MAIN_ANT:AUX_ANT;
  10979. }
  10980. else
  10981. {
  10982. nextAntenna = (Score_B >= Score_A)?AUX_ANT:MAIN_ANT;
  10983. }
  10984. ODM_RT_TRACE(pDM_Odm,ODM_COMP_PATH_DIV, ODM_DBG_LOUD, ("=PATH=: nextAntenna=%s\n",(nextAntenna==MAIN_ANT)?"MAIN":"AUX"));
  10985. ODM_RT_TRACE(pDM_Odm,ODM_COMP_PATH_DIV, ODM_DBG_LOUD, ("=PATH=: preAntenna= %s, curAntenna= %s \n",
  10986. (pDM_SWAT_Table->PreAntenna == MAIN_ANT?"MAIN":"AUX"), (pDM_SWAT_Table->CurAntenna == MAIN_ANT?"MAIN":"AUX")));
  10987. if(nextAntenna != pDM_SWAT_Table->CurAntenna)
  10988. {
  10989. ODM_RT_TRACE(pDM_Odm,ODM_COMP_PATH_DIV, ODM_DBG_LOUD, ("=PATH=: Switch back to another antenna"));
  10990. }
  10991. else
  10992. {
  10993. ODM_RT_TRACE(pDM_Odm,ODM_COMP_PATH_DIV, ODM_DBG_LOUD, ("=PATH=: current anntena is good\n"));
  10994. }
  10995. }
  10996. if(pDM_SWAT_Table->TestMode == RSSI_MODE)
  10997. {
  10998. ODM_RT_TRACE(pDM_Odm,ODM_COMP_PATH_DIV, ODM_DBG_LOUD, ("=PATH=: TestMode = RSSI_MODE"));
  10999. pDM_SWAT_Table->SelectAntennaMap=0xAA;
  11000. if(curRSSI < pDM_SWAT_Table->PreRSSI) //Current antenna is worse than previous antenna
  11001. {
  11002. //RT_TRACE(COMP_SWAS, DBG_LOUD, ("SWAS: Switch back to another antenna"));
  11003. nextAntenna = (pDM_SWAT_Table->CurAntenna == MAIN_ANT)?AUX_ANT : MAIN_ANT;
  11004. }
  11005. else // current anntena is good
  11006. {
  11007. nextAntenna =pDM_SWAT_Table->CurAntenna;
  11008. //RT_TRACE(COMP_SWAS, DBG_LOUD, ("SWAS: current anntena is good\n"));
  11009. }
  11010. }
  11011. pDM_SWAT_Table->try_flag = 0;
  11012. pHalData->RSSI_test = FALSE;
  11013. pHalData->RSSI_sum_A = 0;
  11014. pHalData->RSSI_cnt_A = 0;
  11015. pHalData->RSSI_sum_B = 0;
  11016. pHalData->RSSI_cnt_B = 0;
  11017. TXByteCnt_A = 0;
  11018. TXByteCnt_B = 0;
  11019. RXByteCnt_A = 0;
  11020. RXByteCnt_B = 0;
  11021. }
  11022. //1 Normal State
  11023. else if(pDM_SWAT_Table->try_flag == 0)
  11024. {
  11025. if(TrafficLoad == TRAFFIC_HIGH)
  11026. {
  11027. if ((curTxOkCnt+curRxOkCnt) > 3750000)//if(PlatformDivision64(curTxOkCnt+curRxOkCnt, 2) > 1875000)
  11028. TrafficLoad = TRAFFIC_HIGH;
  11029. else
  11030. TrafficLoad = TRAFFIC_LOW;
  11031. }
  11032. else if(TrafficLoad == TRAFFIC_LOW)
  11033. {
  11034. if ((curTxOkCnt+curRxOkCnt) > 3750000)//if(PlatformDivision64(curTxOkCnt+curRxOkCnt, 2) > 1875000)
  11035. TrafficLoad = TRAFFIC_HIGH;
  11036. else
  11037. TrafficLoad = TRAFFIC_LOW;
  11038. }
  11039. if(TrafficLoad == TRAFFIC_HIGH)
  11040. pDM_SWAT_Table->bTriggerAntennaSwitch = 0;
  11041. //RT_TRACE(COMP_SWAS, DBG_LOUD, ("Normal:TrafficLoad = %llu\n", curTxOkCnt+curRxOkCnt));
  11042. //Prepare To Try Antenna
  11043. nextAntenna = (pDM_SWAT_Table->CurAntenna == MAIN_ANT)? AUX_ANT : MAIN_ANT;
  11044. pDM_SWAT_Table->try_flag = 1;
  11045. pHalData->RSSI_test = TRUE;
  11046. if((curRxOkCnt+curTxOkCnt) > 1000)
  11047. {
  11048. #if DEV_BUS_TYPE==RT_PCI_INTERFACE
  11049. pDM_SWAT_Table->RSSI_Trying = 4;
  11050. #else
  11051. pDM_SWAT_Table->RSSI_Trying = 2;
  11052. #endif
  11053. pDM_SWAT_Table->TestMode = TP_MODE;
  11054. }
  11055. else
  11056. {
  11057. pDM_SWAT_Table->RSSI_Trying = 2;
  11058. pDM_SWAT_Table->TestMode = RSSI_MODE;
  11059. }
  11060. //RT_TRACE(COMP_SWAS, DBG_LOUD, ("SWAS: Normal State -> Begin Trying!\n"));
  11061. pHalData->RSSI_sum_A = 0;
  11062. pHalData->RSSI_cnt_A = 0;
  11063. pHalData->RSSI_sum_B = 0;
  11064. pHalData->RSSI_cnt_B = 0;
  11065. } // end of try_flag=0
  11066. }
  11067. //1 4.Change TRX antenna
  11068. if(nextAntenna != pDM_SWAT_Table->CurAntenna)
  11069. {
  11070. ODM_RT_TRACE(pDM_Odm,ODM_COMP_PATH_DIV, ODM_DBG_LOUD, ("=PATH=: Change TX Antenna!\n "));
  11071. //PHY_SetBBReg(Adapter, rFPGA0_XA_RFInterfaceOE, 0x300, nextAntenna); for 88C
  11072. if(nextAntenna==MAIN_ANT)
  11073. {
  11074. ODM_RT_TRACE(pDM_Odm,ODM_COMP_PATH_DIV, ODM_DBG_LOUD, ("=PATH=: Next Antenna is RF PATH A\n "));
  11075. pathdiv_para = 0x02; //02 to switchback to RF path A
  11076. fw_value = 0x03;
  11077. #if DEV_BUS_TYPE==RT_PCI_INTERFACE
  11078. odm_PathDiversity_8192D(pDM_Odm, pathdiv_para);
  11079. #else
  11080. ODM_FillH2CCmd(Adapter, ODM_H2C_PathDiv,1,(pu1Byte)(&fw_value));
  11081. #endif
  11082. }
  11083. else if(nextAntenna==AUX_ANT)
  11084. {
  11085. ODM_RT_TRACE(pDM_Odm,ODM_COMP_PATH_DIV, ODM_DBG_LOUD, ("=PATH=: Next Antenna is RF PATH B\n "));
  11086. if(switchfirsttime==0) // First Time To Enter Path Diversity
  11087. {
  11088. switchfirsttime=0x01;
  11089. pathdiv_para = 0x00;
  11090. fw_value=0x00; // to backup RF Path A Releated Registers
  11091. #if DEV_BUS_TYPE==RT_PCI_INTERFACE
  11092. odm_PathDiversity_8192D(pDM_Odm, pathdiv_para);
  11093. #else
  11094. ODM_FillH2CCmd(Adapter, ODM_H2C_PathDiv,1,(pu1Byte)(&fw_value));
  11095. //for(u1Byte n=0; n<80,n++)
  11096. //{
  11097. //delay_us(500);
  11098. ODM_delay_ms(500);
  11099. odm_PathDiversity_8192D(pDM_Odm, pathdiv_para);
  11100. fw_value=0x01; // to backup RF Path A Releated Registers
  11101. ODM_FillH2CCmd(Adapter, ODM_H2C_PathDiv,1,(pu1Byte)(&fw_value));
  11102. #endif
  11103. ODM_RT_TRACE(pDM_Odm,ODM_COMP_PATH_DIV, ODM_DBG_LOUD, ("=PATH=: FIRST TIME To DO PATH SWITCH!\n "));
  11104. }
  11105. else
  11106. {
  11107. pathdiv_para = 0x01;
  11108. fw_value = 0x02;
  11109. #if DEV_BUS_TYPE==RT_PCI_INTERFACE
  11110. odm_PathDiversity_8192D(pDM_Odm, pathdiv_para);
  11111. #else
  11112. ODM_FillH2CCmd(Adapter, ODM_H2C_PathDiv,1,(pu1Byte)(&fw_value));
  11113. #endif
  11114. }
  11115. }
  11116. // odm_PathDiversity_8192D(Adapter, pathdiv_para);
  11117. }
  11118. //1 5.Reset Statistics
  11119. pDM_SWAT_Table->PreAntenna = pDM_SWAT_Table->CurAntenna;
  11120. pDM_SWAT_Table->CurAntenna = nextAntenna;
  11121. pDM_SWAT_Table->PreRSSI = curRSSI;
  11122. //1 6.Set next timer
  11123. if(pDM_SWAT_Table->RSSI_Trying == 0)
  11124. return;
  11125. if(pDM_SWAT_Table->RSSI_Trying%2 == 0)
  11126. {
  11127. if(pDM_SWAT_Table->TestMode == TP_MODE)
  11128. {
  11129. if(TrafficLoad == TRAFFIC_HIGH)
  11130. {
  11131. #if DEV_BUS_TYPE==RT_PCI_INTERFACE
  11132. ODM_SetTimer( pDM_Odm, &pDM_Odm->PathDivSwitchTimer, 10 ); //ms
  11133. ODM_RT_TRACE(pDM_Odm,ODM_COMP_PATH_DIV, ODM_DBG_LOUD, ("=PATH=: Test another antenna for 10 ms\n"));
  11134. #else
  11135. ODM_SetTimer( pDM_Odm, &pDM_Odm->PathDivSwitchTimer, 20 ); //ms
  11136. ODM_RT_TRACE(pDM_Odm,ODM_COMP_PATH_DIV, ODM_DBG_LOUD, ("=PATH=: Test another antenna for 20 ms\n"));
  11137. #endif
  11138. }
  11139. else if(TrafficLoad == TRAFFIC_LOW)
  11140. {
  11141. ODM_SetTimer( pDM_Odm, &pDM_Odm->PathDivSwitchTimer, 50 ); //ms
  11142. ODM_RT_TRACE(pDM_Odm,ODM_COMP_PATH_DIV, ODM_DBG_LOUD, ("=PATH=: Test another antenna for 50 ms\n"));
  11143. }
  11144. }
  11145. else // TestMode == RSSI_MODE
  11146. {
  11147. ODM_SetTimer( pDM_Odm, &pDM_Odm->PathDivSwitchTimer, 500 ); //ms
  11148. ODM_RT_TRACE(pDM_Odm,ODM_COMP_PATH_DIV, ODM_DBG_LOUD, ("=PATH=: Test another antenna for 500 ms\n"));
  11149. }
  11150. }
  11151. else
  11152. {
  11153. if(pDM_SWAT_Table->TestMode == TP_MODE)
  11154. {
  11155. if(TrafficLoad == TRAFFIC_HIGH)
  11156. #if DEV_BUS_TYPE==RT_PCI_INTERFACE
  11157. ODM_SetTimer( pDM_Odm, &pDM_Odm->PathDivSwitchTimer, 90 ); //ms
  11158. //ODM_RT_TRACE(pDM_Odm,ODM_COMP_PATH_DIV, ODM_DBG_LOUD, ("=PATH=: Test another antenna for 90 ms\n"));
  11159. #else
  11160. ODM_SetTimer( pDM_Odm, &pDM_Odm->PathDivSwitchTimer, 180); //ms
  11161. #endif
  11162. else if(TrafficLoad == TRAFFIC_LOW)
  11163. ODM_SetTimer( pDM_Odm, &pDM_Odm->PathDivSwitchTimer, 100 ); //ms
  11164. }
  11165. else
  11166. ODM_SetTimer( pDM_Odm, &pDM_Odm->PathDivSwitchTimer, 500 ); //ms
  11167. }
  11168. }
  11169. //==================================================
  11170. //3 PathDiv End
  11171. //==================================================
  11172. VOID
  11173. odm_SetRespPath_92C(
  11174. IN PADAPTER Adapter,
  11175. IN u1Byte DefaultRespPath
  11176. )
  11177. {
  11178. pPD_T pDM_PDTable = &Adapter->DM_PDTable;
  11179. RT_TRACE( COMP_SWAS, DBG_LOUD, ("odm_SetRespPath_92C: Select Response Path=%d\n",DefaultRespPath));
  11180. if(DefaultRespPath != pDM_PDTable->DefaultRespPath)
  11181. {
  11182. if(DefaultRespPath == 0)
  11183. {
  11184. PlatformEFIOWrite1Byte(Adapter, 0x6D8, (PlatformEFIORead1Byte(Adapter, 0x6D8)&0xc0)|0x15);
  11185. }
  11186. else
  11187. {
  11188. PlatformEFIOWrite1Byte(Adapter, 0x6D8, (PlatformEFIORead1Byte(Adapter, 0x6D8)&0xc0)|0x2A);
  11189. }
  11190. }
  11191. pDM_PDTable->DefaultRespPath = DefaultRespPath;
  11192. }
  11193. VOID
  11194. ODM_FillTXPathInTXDESC(
  11195. IN PADAPTER Adapter,
  11196. IN PRT_TCB pTcb,
  11197. IN pu1Byte pDesc
  11198. )
  11199. {
  11200. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  11201. u4Byte TXPath;
  11202. pPD_T pDM_PDTable = &Adapter->DM_PDTable;
  11203. //2011.09.05 Add by Luke Lee for path diversity
  11204. if(pHalData->PathDivCfg == 1)
  11205. {
  11206. TXPath = (pDM_PDTable->OFDMTXPath >> pTcb->macId) & BIT0;
  11207. //RT_TRACE( COMP_SWAS, DBG_LOUD, ("Fill TXDESC: macID=%d, TXPath=%d\n", pTcb->macId, TXPath));
  11208. //SET_TX_DESC_TX_ANT_CCK(pDesc,TXPath);
  11209. if(TXPath == 0)
  11210. {
  11211. SET_TX_DESC_TX_ANTL_92C(pDesc,1);
  11212. SET_TX_DESC_TX_ANT_HT_92C(pDesc,1);
  11213. }
  11214. else
  11215. {
  11216. SET_TX_DESC_TX_ANTL_92C(pDesc,2);
  11217. SET_TX_DESC_TX_ANT_HT_92C(pDesc,2);
  11218. }
  11219. TXPath = (pDM_PDTable->CCKTXPath >> pTcb->macId) & BIT0;
  11220. if(TXPath == 0)
  11221. {
  11222. SET_TX_DESC_TX_ANT_CCK_92C(pDesc,1);
  11223. }
  11224. else
  11225. {
  11226. SET_TX_DESC_TX_ANT_CCK_92C(pDesc,2);
  11227. }
  11228. }
  11229. }
  11230. //Only for MP //Neil Chen--2012--0502--
  11231. VOID
  11232. odm_PathDivInit_92D(
  11233. IN PDM_ODM_T pDM_Odm)
  11234. {
  11235. pPATHDIV_PARA pathIQK = &pDM_Odm->pathIQK;
  11236. pathIQK->org_2g_RegC14=0x0;
  11237. pathIQK->org_2g_RegC4C=0x0;
  11238. pathIQK->org_2g_RegC80=0x0;
  11239. pathIQK->org_2g_RegC94=0x0;
  11240. pathIQK->org_2g_RegCA0=0x0;
  11241. pathIQK->org_5g_RegC14=0x0;
  11242. pathIQK->org_5g_RegCA0=0x0;
  11243. pathIQK->org_5g_RegE30=0x0;
  11244. pathIQK->swt_2g_RegC14=0x0;
  11245. pathIQK->swt_2g_RegC4C=0x0;
  11246. pathIQK->swt_2g_RegC80=0x0;
  11247. pathIQK->swt_2g_RegC94=0x0;
  11248. pathIQK->swt_2g_RegCA0=0x0;
  11249. pathIQK->swt_5g_RegC14=0x0;
  11250. pathIQK->swt_5g_RegCA0=0x0;
  11251. pathIQK->swt_5g_RegE30=0x0;
  11252. }
  11253. #endif // #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
  11254. #if (DM_ODM_SUPPORT_TYPE & (ODM_WIN| ODM_CE))
  11255. VOID
  11256. odm_PHY_SaveAFERegisters(
  11257. IN PDM_ODM_T pDM_Odm,
  11258. IN pu4Byte AFEReg,
  11259. IN pu4Byte AFEBackup,
  11260. IN u4Byte RegisterNum
  11261. )
  11262. {
  11263. u4Byte i;
  11264. //RT_DISP(FINIT, INIT_IQK, ("Save ADDA parameters.\n"));
  11265. for( i = 0 ; i < RegisterNum ; i++){
  11266. AFEBackup[i] = ODM_GetBBReg(pDM_Odm, AFEReg[i], bMaskDWord);
  11267. }
  11268. }
  11269. VOID
  11270. odm_PHY_ReloadAFERegisters(
  11271. IN PDM_ODM_T pDM_Odm,
  11272. IN pu4Byte AFEReg,
  11273. IN pu4Byte AFEBackup,
  11274. IN u4Byte RegiesterNum
  11275. )
  11276. {
  11277. u4Byte i;
  11278. //RT_DISP(FINIT, INIT_IQK, ("Reload ADDA power saving parameters !\n"));
  11279. for(i = 0 ; i < RegiesterNum; i++)
  11280. {
  11281. ODM_SetBBReg(pDM_Odm, AFEReg[i], bMaskDWord, AFEBackup[i]);
  11282. }
  11283. }
  11284. //
  11285. // Description:
  11286. // Set Single/Dual Antenna default setting for products that do not do detection in advance.
  11287. //
  11288. // Added by Joseph, 2012.03.22
  11289. //
  11290. VOID
  11291. ODM_SingleDualAntennaDefaultSetting(
  11292. IN PDM_ODM_T pDM_Odm
  11293. )
  11294. {
  11295. pSWAT_T pDM_SWAT_Table = &pDM_Odm->DM_SWAT_Table;
  11296. pDM_SWAT_Table->ANTA_ON=TRUE;
  11297. pDM_SWAT_Table->ANTB_ON=TRUE;
  11298. }
  11299. //2 8723A ANT DETECT
  11300. //
  11301. // Description:
  11302. // Implement IQK single tone for RF DPK loopback and BB PSD scanning.
  11303. // This function is cooperated with BB team Neil.
  11304. //
  11305. // Added by Roger, 2011.12.15
  11306. //
  11307. BOOLEAN
  11308. ODM_SingleDualAntennaDetection(
  11309. IN PDM_ODM_T pDM_Odm,
  11310. IN u1Byte mode
  11311. )
  11312. {
  11313. PADAPTER pAdapter = pDM_Odm->Adapter;
  11314. pSWAT_T pDM_SWAT_Table = &pDM_Odm->DM_SWAT_Table;
  11315. u4Byte CurrentChannel,RfLoopReg;
  11316. u1Byte n;
  11317. u4Byte Reg88c, Regc08, Reg874, Regc50;
  11318. u1Byte initial_gain = 0x5a;
  11319. u4Byte PSD_report_tmp;
  11320. u4Byte AntA_report = 0x0, AntB_report = 0x0,AntO_report=0x0;
  11321. BOOLEAN bResult = TRUE;
  11322. BOOLEAN bAntDetection = FALSE;
  11323. u4Byte AFE_Backup[16];
  11324. u4Byte AFE_REG_8723A[16] = {
  11325. rRx_Wait_CCA, rTx_CCK_RFON,
  11326. rTx_CCK_BBON, rTx_OFDM_RFON,
  11327. rTx_OFDM_BBON, rTx_To_Rx,
  11328. rTx_To_Tx, rRx_CCK,
  11329. rRx_OFDM, rRx_Wait_RIFS,
  11330. rRx_TO_Rx, rStandby,
  11331. rSleep, rPMPD_ANAEN,
  11332. rFPGA0_XCD_SwitchControl, rBlue_Tooth};
  11333. // Retrieve antenna detection registry info, added by Roger, 2012.11.27.
  11334. pAdapter->HalFunc.GetHalDefVarHandler(pAdapter, HAL_DEF_ANT_DETECT, &bAntDetection);
  11335. if(!(pDM_Odm->SupportICType & (ODM_RTL8723A|ODM_RTL8192C)))
  11336. return bResult;
  11337. if(!(pDM_Odm->SupportAbility&ODM_BB_ANT_DIV) && !bAntDetection)
  11338. return bResult;
  11339. if(pDM_Odm->SupportICType == ODM_RTL8192C)
  11340. {
  11341. //Which path in ADC/DAC is turnned on for PSD: both I/Q
  11342. ODM_SetBBReg(pDM_Odm, 0x808, BIT10|BIT11, 0x3);
  11343. //Ageraged number: 8
  11344. ODM_SetBBReg(pDM_Odm, 0x808, BIT12|BIT13, 0x1);
  11345. //pts = 128;
  11346. ODM_SetBBReg(pDM_Odm, 0x808, BIT14|BIT15, 0x0);
  11347. }
  11348. //1 Backup Current RF/BB Settings
  11349. CurrentChannel = ODM_GetRFReg(pDM_Odm, ODM_RF_PATH_A, ODM_CHANNEL, bRFRegOffsetMask);
  11350. RfLoopReg = ODM_GetRFReg(pDM_Odm, ODM_RF_PATH_A, 0x00, bRFRegOffsetMask);
  11351. ODM_SetBBReg(pDM_Odm, rFPGA0_XA_RFInterfaceOE, ODM_DPDT, Antenna_A); // change to Antenna A
  11352. // Step 1: USE IQK to transmitter single tone
  11353. ODM_StallExecution(10);
  11354. //Store A Path Register 88c, c08, 874, c50
  11355. Reg88c = ODM_GetBBReg(pDM_Odm, rFPGA0_AnalogParameter4, bMaskDWord);
  11356. Regc08 = ODM_GetBBReg(pDM_Odm, rOFDM0_TRMuxPar, bMaskDWord);
  11357. Reg874 = ODM_GetBBReg(pDM_Odm, rFPGA0_XCD_RFInterfaceSW, bMaskDWord);
  11358. Regc50 = ODM_GetBBReg(pDM_Odm, rOFDM0_XAAGCCore1, bMaskDWord);
  11359. // Store AFE Registers
  11360. odm_PHY_SaveAFERegisters(pDM_Odm, AFE_REG_8723A, AFE_Backup, 16);
  11361. //Set PSD 128 pts
  11362. ODM_SetBBReg(pDM_Odm, rFPGA0_PSDFunction, BIT14|BIT15, 0x0); //128 pts
  11363. // To SET CH1 to do
  11364. ODM_SetRFReg(pDM_Odm, ODM_RF_PATH_A, ODM_CHANNEL, bRFRegOffsetMask, 0x7401); //Channel 1
  11365. // AFE all on step
  11366. ODM_SetBBReg(pDM_Odm, rRx_Wait_CCA, bMaskDWord, 0x6FDB25A4);
  11367. ODM_SetBBReg(pDM_Odm, rTx_CCK_RFON, bMaskDWord, 0x6FDB25A4);
  11368. ODM_SetBBReg(pDM_Odm, rTx_CCK_BBON, bMaskDWord, 0x6FDB25A4);
  11369. ODM_SetBBReg(pDM_Odm, rTx_OFDM_RFON, bMaskDWord, 0x6FDB25A4);
  11370. ODM_SetBBReg(pDM_Odm, rTx_OFDM_BBON, bMaskDWord, 0x6FDB25A4);
  11371. ODM_SetBBReg(pDM_Odm, rTx_To_Rx, bMaskDWord, 0x6FDB25A4);
  11372. ODM_SetBBReg(pDM_Odm, rTx_To_Tx, bMaskDWord, 0x6FDB25A4);
  11373. ODM_SetBBReg(pDM_Odm, rRx_CCK, bMaskDWord, 0x6FDB25A4);
  11374. ODM_SetBBReg(pDM_Odm, rRx_OFDM, bMaskDWord, 0x6FDB25A4);
  11375. ODM_SetBBReg(pDM_Odm, rRx_Wait_RIFS, bMaskDWord, 0x6FDB25A4);
  11376. ODM_SetBBReg(pDM_Odm, rRx_TO_Rx, bMaskDWord, 0x6FDB25A4);
  11377. ODM_SetBBReg(pDM_Odm, rStandby, bMaskDWord, 0x6FDB25A4);
  11378. ODM_SetBBReg(pDM_Odm, rSleep, bMaskDWord, 0x6FDB25A4);
  11379. ODM_SetBBReg(pDM_Odm, rPMPD_ANAEN, bMaskDWord, 0x6FDB25A4);
  11380. ODM_SetBBReg(pDM_Odm, rFPGA0_XCD_SwitchControl, bMaskDWord, 0x6FDB25A4);
  11381. ODM_SetBBReg(pDM_Odm, rBlue_Tooth, bMaskDWord, 0x6FDB25A4);
  11382. // 3 wire Disable
  11383. ODM_SetBBReg(pDM_Odm, rFPGA0_AnalogParameter4, bMaskDWord, 0xCCF000C0);
  11384. //BB IQK Setting
  11385. ODM_SetBBReg(pDM_Odm, rOFDM0_TRMuxPar, bMaskDWord, 0x000800E4);
  11386. ODM_SetBBReg(pDM_Odm, rFPGA0_XCD_RFInterfaceSW, bMaskDWord, 0x22208000);
  11387. //IQK setting tone@ 4.34Mhz
  11388. ODM_SetBBReg(pDM_Odm, rTx_IQK_Tone_A, bMaskDWord, 0x10008C1C);
  11389. ODM_SetBBReg(pDM_Odm, rTx_IQK, bMaskDWord, 0x01007c00);
  11390. //Page B init
  11391. ODM_SetBBReg(pDM_Odm, rConfig_AntA, bMaskDWord, 0x00080000);
  11392. ODM_SetBBReg(pDM_Odm, rConfig_AntA, bMaskDWord, 0x0f600000);
  11393. ODM_SetBBReg(pDM_Odm, rRx_IQK, bMaskDWord, 0x01004800);
  11394. ODM_SetBBReg(pDM_Odm, rRx_IQK_Tone_A, bMaskDWord, 0x10008c1f);
  11395. ODM_SetBBReg(pDM_Odm, rTx_IQK_PI_A, bMaskDWord, 0x82150008);
  11396. ODM_SetBBReg(pDM_Odm, rRx_IQK_PI_A, bMaskDWord, 0x28150008);
  11397. ODM_SetBBReg(pDM_Odm, rIQK_AGC_Rsp, bMaskDWord, 0x001028d0);
  11398. //RF loop Setting
  11399. ODM_SetRFReg(pDM_Odm, ODM_RF_PATH_A, 0x0, 0xFFFFF, 0x50008);
  11400. //IQK Single tone start
  11401. ODM_SetBBReg(pDM_Odm, rFPGA0_IQK, bMaskDWord, 0x80800000);
  11402. ODM_SetBBReg(pDM_Odm, rIQK_AGC_Pts, bMaskDWord, 0xf8000000);
  11403. ODM_StallExecution(10000);
  11404. PSD_report_tmp=0x0;
  11405. for (n=0;n<2;n++)
  11406. {
  11407. PSD_report_tmp = GetPSDData(pDM_Odm, 14, initial_gain);
  11408. if(PSD_report_tmp >AntA_report)
  11409. AntA_report=PSD_report_tmp;
  11410. }
  11411. PSD_report_tmp=0x0;
  11412. ODM_SetBBReg(pDM_Odm, rFPGA0_XA_RFInterfaceOE, 0x300, Antenna_B); // change to Antenna B
  11413. ODM_StallExecution(10);
  11414. for (n=0;n<2;n++)
  11415. {
  11416. PSD_report_tmp = GetPSDData(pDM_Odm, 14, initial_gain);
  11417. if(PSD_report_tmp > AntB_report)
  11418. AntB_report=PSD_report_tmp;
  11419. }
  11420. // change to open case
  11421. ODM_SetBBReg(pDM_Odm, rFPGA0_XA_RFInterfaceOE, 0x300, 0); // change to Ant A and B all open case
  11422. ODM_StallExecution(10);
  11423. for (n=0;n<2;n++)
  11424. {
  11425. PSD_report_tmp = GetPSDData(pDM_Odm, 14, initial_gain);
  11426. if(PSD_report_tmp > AntO_report)
  11427. AntO_report=PSD_report_tmp;
  11428. }
  11429. //Close IQK Single Tone function
  11430. ODM_SetBBReg(pDM_Odm, rFPGA0_IQK, bMaskDWord, 0x00000000);
  11431. PSD_report_tmp = 0x0;
  11432. //1 Return to antanna A
  11433. ODM_SetBBReg(pDM_Odm, rFPGA0_XA_RFInterfaceOE, 0x300, Antenna_A);
  11434. ODM_SetBBReg(pDM_Odm, rFPGA0_AnalogParameter4, bMaskDWord, Reg88c);
  11435. ODM_SetBBReg(pDM_Odm, rOFDM0_TRMuxPar, bMaskDWord, Regc08);
  11436. ODM_SetBBReg(pDM_Odm, rFPGA0_XCD_RFInterfaceSW, bMaskDWord, Reg874);
  11437. ODM_SetBBReg(pDM_Odm, rOFDM0_XAAGCCore1, 0x7F, 0x40);
  11438. ODM_SetBBReg(pDM_Odm, rOFDM0_XAAGCCore1, bMaskDWord, Regc50);
  11439. ODM_SetRFReg(pDM_Odm, ODM_RF_PATH_A, RF_CHNLBW, bRFRegOffsetMask,CurrentChannel);
  11440. ODM_SetRFReg(pDM_Odm, ODM_RF_PATH_A, 0x00, bRFRegOffsetMask,RfLoopReg);
  11441. //Reload AFE Registers
  11442. odm_PHY_ReloadAFERegisters(pDM_Odm, AFE_REG_8723A, AFE_Backup, 16);
  11443. //ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("psd_report_A[%d]= %d \n", 2416, AntA_report));
  11444. //ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("psd_report_B[%d]= %d \n", 2416, AntB_report));
  11445. //ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("psd_report_O[%d]= %d \n", 2416, AntO_report));
  11446. if(pDM_Odm->SupportICType == ODM_RTL8723A)
  11447. {
  11448. //2 Test Ant B based on Ant A is ON
  11449. if(mode==ANTTESTB)
  11450. {
  11451. if(AntA_report >= 100)
  11452. {
  11453. if(AntB_report > (AntA_report+1))
  11454. {
  11455. pDM_SWAT_Table->ANTB_ON=FALSE;
  11456. ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("ODM_SingleDualAntennaDetection(): Single Antenna A\n"));
  11457. }
  11458. else
  11459. {
  11460. pDM_SWAT_Table->ANTB_ON=TRUE;
  11461. ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("ODM_SingleDualAntennaDetection(): Dual Antenna is A and B\n"));
  11462. }
  11463. }
  11464. else
  11465. {
  11466. ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("ODM_SingleDualAntennaDetection(): Need to check again\n"));
  11467. pDM_SWAT_Table->ANTB_ON=FALSE; // Set Antenna B off as default
  11468. bResult = FALSE;
  11469. }
  11470. }
  11471. //2 Test Ant A and B based on DPDT Open
  11472. else if(mode==ANTTESTALL)
  11473. {
  11474. if((AntO_report >=100) && (AntO_report <=118))
  11475. {
  11476. if(AntA_report > (AntO_report+1))
  11477. {
  11478. pDM_SWAT_Table->ANTA_ON=FALSE;
  11479. ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD,("Ant A is OFF\n"));
  11480. }
  11481. else
  11482. {
  11483. pDM_SWAT_Table->ANTA_ON=TRUE;
  11484. ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD,("Ant A is ON\n"));
  11485. }
  11486. if(AntB_report > (AntO_report+2))
  11487. {
  11488. pDM_SWAT_Table->ANTB_ON=FALSE;
  11489. ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD,("Ant B is OFF\n"));
  11490. }
  11491. else
  11492. {
  11493. pDM_SWAT_Table->ANTB_ON=TRUE;
  11494. ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD,("Ant B is ON\n"));
  11495. }
  11496. ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("psd_report_A[%d]= %d \n", 2416, AntA_report));
  11497. ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("psd_report_B[%d]= %d \n", 2416, AntB_report));
  11498. ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("psd_report_O[%d]= %d \n", 2416, AntO_report));
  11499. pDM_Odm->AntDetectedInfo.bAntDetected= TRUE;
  11500. pDM_Odm->AntDetectedInfo.dBForAntA = AntA_report;
  11501. pDM_Odm->AntDetectedInfo.dBForAntB = AntB_report;
  11502. pDM_Odm->AntDetectedInfo.dBForAntO = AntO_report;
  11503. }
  11504. else
  11505. {
  11506. ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD,("return FALSE!!\n"));
  11507. bResult = FALSE;
  11508. }
  11509. }
  11510. }
  11511. else if(pDM_Odm->SupportICType == ODM_RTL8192C)
  11512. {
  11513. if(AntA_report >= 100)
  11514. {
  11515. if(AntB_report > (AntA_report+2))
  11516. {
  11517. pDM_SWAT_Table->ANTA_ON=FALSE;
  11518. pDM_SWAT_Table->ANTB_ON=TRUE;
  11519. ODM_SetBBReg(pDM_Odm, rFPGA0_XA_RFInterfaceOE, 0x300, Antenna_B);
  11520. ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("ODM_SingleDualAntennaDetection(): Single Antenna B\n"));
  11521. }
  11522. else if(AntA_report > (AntB_report+2))
  11523. {
  11524. pDM_SWAT_Table->ANTA_ON=TRUE;
  11525. pDM_SWAT_Table->ANTB_ON=FALSE;
  11526. ODM_SetBBReg(pDM_Odm, rFPGA0_XA_RFInterfaceOE, 0x300, Antenna_A);
  11527. ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("ODM_SingleDualAntennaDetection(): Single Antenna A\n"));
  11528. }
  11529. else
  11530. {
  11531. pDM_SWAT_Table->ANTA_ON=TRUE;
  11532. pDM_SWAT_Table->ANTB_ON=TRUE;
  11533. RT_TRACE(COMP_ANTENNA, DBG_LOUD, ("ODM_SingleDualAntennaDetection(): Dual Antenna \n"));
  11534. }
  11535. }
  11536. else
  11537. {
  11538. ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("ODM_SingleDualAntennaDetection(): Need to check again\n"));
  11539. pDM_SWAT_Table->ANTA_ON=TRUE; // Set Antenna A on as default
  11540. pDM_SWAT_Table->ANTB_ON=FALSE; // Set Antenna B off as default
  11541. bResult = FALSE;
  11542. }
  11543. }
  11544. return bResult;
  11545. }
  11546. #endif // end odm_CE
  11547. #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
  11548. VOID
  11549. ODM_UpdateInitRate(
  11550. IN PDM_ODM_T pDM_Odm,
  11551. IN u1Byte Rate
  11552. )
  11553. {
  11554. u1Byte p = 0;
  11555. ODM_RT_TRACE(pDM_Odm,ODM_COMP_TX_PWR_TRACK, ODM_DBG_LOUD,("Get C2H Command! Rate=0x%x\n", Rate));
  11556. if(pDM_Odm->SupportICType == ODM_RTL8821 || pDM_Odm->SupportICType == ODM_RTL8812)
  11557. {
  11558. pDM_Odm->TxRate = Rate;
  11559. #if DEV_BUS_TYPE==RT_PCI_INTERFACE
  11560. #if USE_WORKITEM
  11561. PlatformScheduleWorkItem(&pDM_Odm->RaRptWorkitem);
  11562. #else
  11563. if(pDM_Odm->SupportICType == ODM_RTL8821)
  11564. {
  11565. ODM_TxPwrTrackSetPwr8821A(pDM_Odm, MIX_MODE, ODM_RF_PATH_A, 0);
  11566. }
  11567. else
  11568. {
  11569. for (p = ODM_RF_PATH_A; p < 2; p++)
  11570. {
  11571. ODM_TxPwrTrackSetPwr8812A(pDM_Odm, BBSWING, p, 0);
  11572. }
  11573. }
  11574. #endif
  11575. #else
  11576. PlatformScheduleWorkItem(&pDM_Odm->RaRptWorkitem);
  11577. #endif
  11578. }
  11579. else
  11580. return;
  11581. }
  11582. VOID
  11583. ODM_UpdateInitRateWorkItemCallback(
  11584. IN PVOID pContext
  11585. )
  11586. {
  11587. PADAPTER Adapter = (PADAPTER)pContext;
  11588. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  11589. PDM_ODM_T pDM_Odm = &pHalData->DM_OutSrc;
  11590. u1Byte p = 0;
  11591. if(pDM_Odm->SupportICType == ODM_RTL8821)
  11592. {
  11593. ODM_TxPwrTrackSetPwr8821A(pDM_Odm, MIX_MODE, ODM_RF_PATH_A, 0);
  11594. }
  11595. else if(pDM_Odm->SupportICType == ODM_RTL8812)
  11596. {
  11597. for (p = ODM_RF_PATH_A; p < 2; p++) //DOn't know how to include &c
  11598. {
  11599. ODM_TxPwrTrackSetPwr8812A(pDM_Odm, BBSWING, p, 0);
  11600. }
  11601. }
  11602. }
  11603. #endif
  11604. #if (DM_ODM_SUPPORT_TYPE == ODM_CE)
  11605. /* Justin: According to the current RRSI to adjust Response Frame TX power, 2012/11/05 */
  11606. void odm_dtc(PDM_ODM_T pDM_Odm)
  11607. {
  11608. #ifdef CONFIG_DM_RESP_TXAGC
  11609. #define DTC_BASE 35 /* RSSI higher than this value, start to decade TX power */
  11610. #define DTC_DWN_BASE (DTC_BASE-5) /* RSSI lower than this value, start to increase TX power */
  11611. /* RSSI vs TX power step mapping: decade TX power */
  11612. static const u8 dtc_table_down[]={
  11613. DTC_BASE,
  11614. (DTC_BASE+5),
  11615. (DTC_BASE+10),
  11616. (DTC_BASE+15),
  11617. (DTC_BASE+20),
  11618. (DTC_BASE+25)
  11619. };
  11620. /* RSSI vs TX power step mapping: increase TX power */
  11621. static const u8 dtc_table_up[]={
  11622. DTC_DWN_BASE,
  11623. (DTC_DWN_BASE-5),
  11624. (DTC_DWN_BASE-10),
  11625. (DTC_DWN_BASE-15),
  11626. (DTC_DWN_BASE-15),
  11627. (DTC_DWN_BASE-20),
  11628. (DTC_DWN_BASE-20),
  11629. (DTC_DWN_BASE-25),
  11630. (DTC_DWN_BASE-25),
  11631. (DTC_DWN_BASE-30),
  11632. (DTC_DWN_BASE-35)
  11633. };
  11634. u8 i;
  11635. u8 dtc_steps=0;
  11636. u8 sign;
  11637. u8 resp_txagc=0;
  11638. #if 0
  11639. /* As DIG is disabled, DTC is also disable */
  11640. if(!(pDM_Odm->SupportAbility & ODM_XXXXXX))
  11641. return;
  11642. #endif
  11643. if (DTC_BASE < pDM_Odm->RSSI_Min) {
  11644. /* need to decade the CTS TX power */
  11645. sign = 1;
  11646. for (i=0;i<ARRAY_SIZE(dtc_table_down);i++)
  11647. {
  11648. if ((dtc_table_down[i] >= pDM_Odm->RSSI_Min) || (dtc_steps >= 6))
  11649. break;
  11650. else
  11651. dtc_steps++;
  11652. }
  11653. }
  11654. #if 0
  11655. else if (DTC_DWN_BASE > pDM_Odm->RSSI_Min)
  11656. {
  11657. /* needs to increase the CTS TX power */
  11658. sign = 0;
  11659. dtc_steps = 1;
  11660. for (i=0;i<ARRAY_SIZE(dtc_table_up);i++)
  11661. {
  11662. if ((dtc_table_up[i] <= pDM_Odm->RSSI_Min) || (dtc_steps>=10))
  11663. break;
  11664. else
  11665. dtc_steps++;
  11666. }
  11667. }
  11668. #endif
  11669. else
  11670. {
  11671. sign = 0;
  11672. dtc_steps = 0;
  11673. }
  11674. resp_txagc = dtc_steps | (sign << 4);
  11675. resp_txagc = resp_txagc | (resp_txagc << 5);
  11676. ODM_Write1Byte(pDM_Odm, 0x06d9, resp_txagc);
  11677. DBG_871X("%s RSSI_Min:%u, set RESP_TXAGC to %s %u\n",
  11678. __func__, pDM_Odm->RSSI_Min, sign?"minus":"plus", dtc_steps);
  11679. #endif /* CONFIG_RESP_TXAGC_ADJUST */
  11680. }
  11681. #endif /* #if (DM_ODM_SUPPORT_TYPE == ODM_CE) */